diff --git a/package.json b/package.json index 9cd719f..7376a9e 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "react-github-btn": "1.2.1", "react-images-viewer": "1.7.1", "react-quill": "1.3.5", + "react-router": "6.3.0", "react-router-dom": "6.2.1", "react-scripts": "5.0.0", "react-table": "7.7.0", @@ -102,5 +103,11 @@ "types": "dist/index.d.ts", "files": [ "dist/**/*" + ], + "react/no-unstable-nested-components": [ + "off", + { + "allowAsProps": true + } ] } diff --git a/src/App.tsx b/src/App.tsx index 38a3a49..c6ee4a5 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -13,7 +13,14 @@ Coded by www.creative-tim.com * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. */ -import { useState, useEffect, useMemo, JSXElementConstructor, Key, ReactElement } from "react"; +import React, { + useState, + useEffect, + useMemo, + JSXElementConstructor, + Key, + ReactElement, +} from "react"; // react-router components import { Routes, Route, Navigate, useLocation } from "react-router-dom"; @@ -53,6 +60,8 @@ import { useMaterialUIController, setMiniSidenav, setOpenConfigurator } from "co import brandWhite from "assets/images/logo-ct.png"; import brandDark from "assets/images/logo-ct-dark.png"; import EntityCreate from "./qqq/pages/entity-create"; +import EntityView from "./qqq/pages/entity-view"; +import EntityEdit from "./qqq/pages/entity-edit"; export default function App() { const [controller, dispatch] = useMaterialUIController(); @@ -156,6 +165,8 @@ export default function App() { ); const entityCreateElement = ; + const entityViewElement = ; + const entityEditElement = ; return direction === "rtl" ? ( @@ -177,9 +188,10 @@ export default function App() { )} {layout === "vr" && } - {getRoutes(routes)} } /> ; + ; + {getRoutes(routes)} @@ -202,9 +214,11 @@ export default function App() { )} {layout === "vr" && } - {getRoutes(routes)} } /> ; + ; + ; + {getRoutes(routes)} ); diff --git a/src/qqq/pages/entity-create/components/CreateForm/data/selectData.ts b/src/qqq/pages/components/EntityForm/data/selectData.ts similarity index 100% rename from src/qqq/pages/entity-create/components/CreateForm/data/selectData.ts rename to src/qqq/pages/components/EntityForm/data/selectData.ts diff --git a/src/qqq/pages/components/EntityForm/index.tsx b/src/qqq/pages/components/EntityForm/index.tsx new file mode 100644 index 0000000..f18b420 --- /dev/null +++ b/src/qqq/pages/components/EntityForm/index.tsx @@ -0,0 +1,184 @@ +/** + ========================================================= + * Material Dashboard 2 PRO React TS - v1.0.0 + ========================================================= + + * Product Page: https://www.creative-tim.com/product/material-dashboard-2-pro-react-ts + * Copyright 2022 Creative Tim (https://www.creative-tim.com) + + Coded by www.creative-tim.com + + ========================================================= + + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + */ + +/* eslint-disable no-unused-vars */ +/* eslint-disable spaced-comment */ + +import { useParams } from "react-router-dom"; + +// @material-ui core components +import Card from "@mui/material/Card"; +import Grid from "@mui/material/Grid"; + +// Material Dashboard 2 PRO React TS components +import MDBox from "components/MDBox"; +import MDTypography from "components/MDTypography"; + +// Settings page components +import FormField from "layouts/pages/account/components/FormField"; + +// qqq imports +import { QTableMetaData } from "qqq-frontend-core/lib/model/metaData/QTableMetaData"; +import { QController } from "qqq-frontend-core/lib/controllers/QController"; +import React, { useState } from "react"; +import { QTableRecord } from "qqq-frontend-core/lib/model/metaData/QTableRecord"; +import MDButton from "../../../../components/MDButton"; + +const qController = new QController("http://localhost:8000"); + +// Declaring props types for EntityForm +interface Props { + id?: string; +} + +function EntityForm({ id }: Props): JSX.Element { + const { tableName } = useParams(); + const [formFields, setFormFields] = useState([] as JSX.Element[]); + const defaultValues: { [key: string]: string } = {}; + const [formValues, setFormValues] = useState(defaultValues); + const [loadCounter, setLoadCounter] = useState(0); + + const handleInputChange = (e: { target: { name: any; value: any } }) => { + console.log("A"); + const { name, value } = e.target; + console.log(name); + console.log(value); + formValues[name] = value; + setFormValues(formValues); + }; + + const tableMetaData = new QTableMetaData(tableName); + if (loadCounter === 0) { + setLoadCounter(1); + + (async () => { + await qController.loadTableMetaData(tableName).then((tableMetaData) => { + const formFields = [] as JSX.Element[]; + + // make a call to query (just get all for now, and iterate and filter like a caveman) + if (id !== null) { + (async () => { + await qController.query(tableName, 250).then((results) => { + let foundRecord: QTableRecord; + results.forEach((record) => { + const values = new Map(Object.entries(record.values)); + values.forEach((value, key) => { + if (key === tableMetaData.primaryKeyField && value.toString() === id) { + foundRecord = record; + } + }); + }); + + if (id != null) { + const values = new Map(Object.entries(foundRecord.values)); + values.forEach((value, key) => { + formValues[key] = value; + console.log(`key:${key},value:${value}`); + }); + } + + const fields = new Map(Object.entries(tableMetaData.fields)); + const sortedEntries = new Map([...fields.entries()].sort()); + sortedEntries.forEach((fieldMetaData) => { + if (fieldMetaData.name !== tableMetaData.primaryKeyField) { + if (formValues[fieldMetaData.name] == null) { + formValues[fieldMetaData.name] = ""; + } + + formFields.push( + + + + ); + } + }); + + setLoadCounter(2); + setFormValues(formValues); + }); + })(); + } else { + const fields = new Map(Object.entries(tableMetaData.fields)); + const sortedEntries = new Map([...fields.entries()].sort()); + sortedEntries.forEach((fieldMetaData) => { + if (fieldMetaData.name !== tableMetaData.primaryKeyField) { + formFields.push( + + + + ); + } + }); + } + + setFormFields(formFields); + }); + })(); + } + + const handleSubmit = (event: { preventDefault: () => void }) => { + event.preventDefault(); + + (async () => { + await qController.create(tableName, formValues).then((recordList) => { + const values = new Map(Object.entries(recordList[0].values)); + window.location.href = `/${tableName}/view/${values.get("id")}`; + }); + })(); + }; + + const pageTitle = id != null ? `Edit ${tableMetaData.label}` : `Create ${tableMetaData.label}`; + + return ( + + + {pageTitle} + + + + {formFields} + + + + + save {tableMetaData.label} + + + + + + ); +} + +// Declaring default props for DefaultCell +EntityForm.defaultProps = { + id: null, +}; + +export default EntityForm; diff --git a/src/qqq/pages/entity-create/components/Accounts/index.tsx b/src/qqq/pages/entity-create/components/Accounts/index.tsx deleted file mode 100644 index 6d5a48e..0000000 --- a/src/qqq/pages/entity-create/components/Accounts/index.tsx +++ /dev/null @@ -1,273 +0,0 @@ -/** -========================================================= -* Material Dashboard 2 PRO React TS - v1.0.0 -========================================================= - -* Product Page: https://www.creative-tim.com/product/material-dashboard-2-pro-react-ts -* Copyright 2022 Creative Tim (https://www.creative-tim.com) - -Coded by www.creative-tim.com - - ========================================================= - -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -*/ - -import { useState } from "react"; - -// @mui material components -import Card from "@mui/material/Card"; -import Icon from "@mui/material/Icon"; -import Switch from "@mui/material/Switch"; -import Tooltip from "@mui/material/Tooltip"; -import Divider from "@mui/material/Divider"; - -// Material Dashboard 2 PRO React TS components -import MDBox from "components/MDBox"; -import MDTypography from "components/MDTypography"; -import MDAvatar from "components/MDAvatar"; -import MDInput from "components/MDInput"; -import MDButton from "components/MDButton"; - -// Images -import logoSlack from "assets/images/small-logos/logo-slack.svg"; -import logoSpotify from "assets/images/small-logos/logo-spotify.svg"; -import logoAtlassian from "assets/images/small-logos/logo-atlassian.svg"; -import logoAsana from "assets/images/small-logos/logo-asana.svg"; - -// Material Dashboard 2 PRO React TS components -import { useMaterialUIController } from "context"; - -function Accounts(): JSX.Element { - const [controller] = useMaterialUIController(); - const { darkMode } = controller; - - const [slack2FA, setSlack2FA] = useState(true); - const [spotify2FA, setSpotify2FA] = useState(true); - const [atlassian2FA, setAtlassian2FA] = useState(true); - const [asana2FA, setAsana2FA] = useState(false); - - const handleSetSlack2FA = () => setSlack2FA(!slack2FA); - const handleSetSpotify2FA = () => setSpotify2FA(!spotify2FA); - const handleSetAtlassian2FA = () => setAtlassian2FA(!atlassian2FA); - const handleSetAsana2FA = () => setAsana2FA(!asana2FA); - - return ( - - - - Accounts - - - Here you can setup and manage your integration settings. - - - - - - - - - Slack - - - - Show less - - - expand_less - - - - - - - - {slack2FA ? "Enabled" : "Disabled"} - - - - - - - - - - You haven't added your Slack yet or you aren't authorized. Please add our - Slack Bot to your account by clicking on here. When you've added the bot, send your - verification code that you have received. - - - - Verification Code - - - - - - - - - - Connected account - - - - - hello@creative-tim.com - - - - delete - - - - - - - - - - - Spotify - - - Music - - - - - - - {spotify2FA ? "Enabled" : "Disabled"} - - - - - - - - - - - - - - Atlassian - - - Payment vendor - - - - - - - {atlassian2FA ? "Enabled" : "Disabled"} - - - - - - - - - - - - - - Asana - - - Organize your team - - - - - - - {asana2FA ? "Enabled" : "Disabled"} - - - - - - - - - - ); -} - -export default Accounts; diff --git a/src/qqq/pages/entity-create/components/Authentication/index.tsx b/src/qqq/pages/entity-create/components/Authentication/index.tsx deleted file mode 100644 index 04bc22e..0000000 --- a/src/qqq/pages/entity-create/components/Authentication/index.tsx +++ /dev/null @@ -1,113 +0,0 @@ -/** -========================================================= -* Material Dashboard 2 PRO React TS - v1.0.0 -========================================================= - -* Product Page: https://www.creative-tim.com/product/material-dashboard-2-pro-react-ts -* Copyright 2022 Creative Tim (https://www.creative-tim.com) - -Coded by www.creative-tim.com - - ========================================================= - -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -*/ - -// @mui material components -import Card from "@mui/material/Card"; -import Divider from "@mui/material/Divider"; - -// Material Dashboard 2 PRO React TS components -import MDBox from "components/MDBox"; -import MDTypography from "components/MDTypography"; -import MDButton from "components/MDButton"; -import MDBadge from "components/MDBadge"; - -function Authentication(): JSX.Element { - return ( - - - Two-factor authentication - - - - - - Security keys - - - - - No Security keys - - - - add - - - - - - - SMS number - - - - - +3012374423 - - - - edit - - - - - - - Authenticator app - - - - - Not Configured - - - - set up - - - - - - ); -} - -export default Authentication; diff --git a/src/qqq/pages/entity-create/components/ChangePassword/index.tsx b/src/qqq/pages/entity-create/components/ChangePassword/index.tsx deleted file mode 100644 index 75c0896..0000000 --- a/src/qqq/pages/entity-create/components/ChangePassword/index.tsx +++ /dev/null @@ -1,98 +0,0 @@ -/** -========================================================= -* Material Dashboard 2 PRO React TS - v1.0.0 -========================================================= - -* Product Page: https://www.creative-tim.com/product/material-dashboard-2-pro-react-ts -* Copyright 2022 Creative Tim (https://www.creative-tim.com) - -Coded by www.creative-tim.com - - ========================================================= - -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -*/ - -// @mui material components -import Card from "@mui/material/Card"; -import Grid from "@mui/material/Grid"; - -// Material Dashboard 2 PRO React TS components -import MDBox from "components/MDBox"; -import MDTypography from "components/MDTypography"; -import MDButton from "components/MDButton"; -import MDInput from "components/MDInput"; - -function ChangePassword(): JSX.Element { - const passwordRequirements = [ - "One special characters", - "Min 6 characters", - "One number (2 are recommended)", - "Change it often", - ]; - - const renderPasswordRequirements = passwordRequirements.map((item, key) => { - const itemKey = `element-${key}`; - - return ( - - - {item} - - - ); - }); - - return ( - - - Change Password - - - - - - - - - - - - - - - Password requirements - - - - Please follow this guide for a strong password - - - - - {renderPasswordRequirements} - - - - update password - - - - - - ); -} - -export default ChangePassword; diff --git a/src/qqq/pages/entity-create/components/CreateForm/index.tsx b/src/qqq/pages/entity-create/components/CreateForm/index.tsx deleted file mode 100644 index 19e1bc4..0000000 --- a/src/qqq/pages/entity-create/components/CreateForm/index.tsx +++ /dev/null @@ -1,106 +0,0 @@ -/** - ========================================================= - * Material Dashboard 2 PRO React TS - v1.0.0 - ========================================================= - - * Product Page: https://www.creative-tim.com/product/material-dashboard-2-pro-react-ts - * Copyright 2022 Creative Tim (https://www.creative-tim.com) - - Coded by www.creative-tim.com - - ========================================================= - - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - */ - -/* eslint-disable no-unused-vars */ -/* eslint-disable spaced-comment */ - -import { useParams } from "react-router-dom"; - -// @material-ui core components -import Card from "@mui/material/Card"; -import Grid from "@mui/material/Grid"; - -// Material Dashboard 2 PRO React TS components -import MDBox from "components/MDBox"; -import MDTypography from "components/MDTypography"; - -// Settings page components -import FormField from "layouts/pages/account/components/FormField"; - -// qqq imports -import { QTableMetaData } from "qqq-frontend-core/lib/model/metaData/QTableMetaData"; -import { QController } from "qqq-frontend-core/lib/controllers/QController"; -import { useState } from "react"; -import MDButton from "../../../../../components/MDButton"; -// import React, { useState } from "react"; - -const qController = new QController("http://localhost:8000"); -console.log(qController); - -function CreateForm(): JSX.Element { - const { tableName } = useParams(); - const [formFields, setFormFields] = useState([] as JSX.Element[]); - const defaultValues: { [key: string]: string } = {}; - const [formValues, setFormValues] = useState(defaultValues); - - const handleInputChange = (e: { target: { name: any; value: any } }) => { - const { name, value } = e.target; - formValues[name] = value; - }; - - const handleSubmit = (event: { preventDefault: () => void }) => { - event.preventDefault(); - qController.create(tableName, formValues); - }; - - const tableMetaData = new QTableMetaData(tableName); - if (formFields.length === 0) { - (async () => { - await qController.loadTableMetaData(tableName).then((tableMetaData) => { - const formFields = [] as JSX.Element[]; - const fields = new Map(Object.entries(tableMetaData.fields)); - fields.forEach((fieldMetaData) => { - //formValues[fieldMetaData.name] = ""; - formFields.push( - - - - ); - }); - - setFormFields(formFields); - }); - })(); - } - - return ( - - - Create {tableMetaData.label} - - - - {formFields} - - - - - create {tableMetaData.label} - - - - - - ); -} - -export default CreateForm; diff --git a/src/qqq/pages/entity-create/components/DeleteAccount/index.tsx b/src/qqq/pages/entity-create/components/DeleteAccount/index.tsx deleted file mode 100644 index e5796be..0000000 --- a/src/qqq/pages/entity-create/components/DeleteAccount/index.tsx +++ /dev/null @@ -1,57 +0,0 @@ -/** -========================================================= -* Material Dashboard 2 PRO React TS - v1.0.0 -========================================================= - -* Product Page: https://www.creative-tim.com/product/material-dashboard-2-pro-react-ts -* Copyright 2022 Creative Tim (https://www.creative-tim.com) - -Coded by www.creative-tim.com - - ========================================================= - -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -*/ - -// @mui material components -import Card from "@mui/material/Card"; - -// Material Dashboard 2 PRO React TS components -import MDBox from "components/MDBox"; -import MDTypography from "components/MDTypography"; -import MDButton from "components/MDButton"; - -function DeleteAccount(): JSX.Element { - return ( - - - - - Delete Account - - - Once you delete your account, there is no going back. Please be certain. - - - - - deactivate - - - - delete account - - - - - - ); -} - -export default DeleteAccount; diff --git a/src/qqq/pages/entity-create/components/Header/index.tsx b/src/qqq/pages/entity-create/components/Header/index.tsx deleted file mode 100644 index 120ba26..0000000 --- a/src/qqq/pages/entity-create/components/Header/index.tsx +++ /dev/null @@ -1,74 +0,0 @@ -/** -========================================================= -* Material Dashboard 2 PRO React TS - v1.0.0 -========================================================= - -* Product Page: https://www.creative-tim.com/product/material-dashboard-2-pro-react-ts -* Copyright 2022 Creative Tim (https://www.creative-tim.com) - -Coded by www.creative-tim.com - - ========================================================= - -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -*/ - -import { useState } from "react"; - -// @mui material components -import Card from "@mui/material/Card"; -import Grid from "@mui/material/Grid"; -import Switch from "@mui/material/Switch"; - -// Material Dashboard 2 PRO React TS components -import MDBox from "components/MDBox"; -import MDTypography from "components/MDTypography"; -import MDAvatar from "components/MDAvatar"; - -// Images -import burceMars from "assets/images/bruce-mars.jpg"; - -function Header(): JSX.Element { - const [visible, setVisible] = useState(true); - - const handleSetVisible = () => setVisible(!visible); - - return ( - - - - - - - - - - Alex Thompson - - - CEO / Co-Founder - - - - - - - Switch to {visible ? "invisible" : "visible"} - - - - - - - - - - ); -} - -export default Header; diff --git a/src/qqq/pages/entity-create/components/Notifications/index.tsx b/src/qqq/pages/entity-create/components/Notifications/index.tsx deleted file mode 100644 index cf37879..0000000 --- a/src/qqq/pages/entity-create/components/Notifications/index.tsx +++ /dev/null @@ -1,149 +0,0 @@ -/** -========================================================= -* Material Dashboard 2 PRO React TS - v1.0.0 -========================================================= - -* Product Page: https://www.creative-tim.com/product/material-dashboard-2-pro-react-ts -* Copyright 2022 Creative Tim (https://www.creative-tim.com) - -Coded by www.creative-tim.com - - ========================================================= - -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -*/ - -// @mui material components -import Card from "@mui/material/Card"; -import Table from "@mui/material/Table"; -import TableRow from "@mui/material/TableRow"; -import TableBody from "@mui/material/TableBody"; -import Switch from "@mui/material/Switch"; - -// Material Dashboard 2 PRO React TS components -import MDBox from "components/MDBox"; -import MDTypography from "components/MDTypography"; - -// Setting pages components -import TableCell from "layouts/pages/account/settings/components/TableCell"; - -function Notifications(): JSX.Element { - return ( - - - - Notifications - - - Choose how you receive notifications. These notification settings apply to the things - you’re watching. - - - - - - - - - Activity - - - Email - - - Push - - - SMS - - - - - - - - - Mentions - - - Notify when another user mentions you in a comment - - - - - - - - - - - - - - - - - - Comments - - - Notify when another user comments your item. - - - - - - - - - - - - - - - - - - Follows - - - Notify when another user follows you. - - - - - - - - - - - - - - - - - Log in from a new device - - - - - - - - - - - - - -
-
-
-
- ); -} - -export default Notifications; diff --git a/src/qqq/pages/entity-create/components/Sessions/index.tsx b/src/qqq/pages/entity-create/components/Sessions/index.tsx deleted file mode 100644 index 45f1d95..0000000 --- a/src/qqq/pages/entity-create/components/Sessions/index.tsx +++ /dev/null @@ -1,172 +0,0 @@ -/** -========================================================= -* Material Dashboard 2 PRO React TS - v1.0.0 -========================================================= - -* Product Page: https://www.creative-tim.com/product/material-dashboard-2-pro-react-ts -* Copyright 2022 Creative Tim (https://www.creative-tim.com) - -Coded by www.creative-tim.com - - ========================================================= - -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -*/ - -// @mui material components -import Card from "@mui/material/Card"; -import Icon from "@mui/material/Icon"; -import Divider from "@mui/material/Divider"; - -// Material Dashboard 2 PRO React TS components -import MDBox from "components/MDBox"; -import MDTypography from "components/MDTypography"; -import MDBadge from "components/MDBadge"; - -function Sessions(): JSX.Element { - const actionButtonStyles = { - "& .material-icons-round": { - transform: `translateX(0)`, - transition: "all 200ms cubic-bezier(0.34,1.61,0.7,1.3)", - }, - - "&:hover .material-icons-round, &:focus .material-icons-round": { - transform: `translateX(4px)`, - }, - }; - - return ( - - - - Sessions - - - This is a list of devices that have logged into your account. Remove those that you do not - recognize. - - - - - - - desktop_windows - - - - Bucharest 68.133.163.201 - - - Your current session - - - - - - - - EU - - - - See more  - arrow_forward - - - - - - - - desktop_windows - - - - Chrome on macOS - - - - - - - US - - - - See more  - arrow_forward - - - - - - - - phone_iphone - - - - Safari on iPhone - - - - - - - US - - - - See more  - arrow_forward - - - - - - ); -} - -export default Sessions; diff --git a/src/qqq/pages/entity-create/components/Sidenav/index.tsx b/src/qqq/pages/entity-create/components/Sidenav/index.tsx deleted file mode 100644 index 4ab704e..0000000 --- a/src/qqq/pages/entity-create/components/Sidenav/index.tsx +++ /dev/null @@ -1,105 +0,0 @@ -/** -========================================================= -* Material Dashboard 2 PRO React TS - v1.0.0 -========================================================= - -* Product Page: https://www.creative-tim.com/product/material-dashboard-2-pro-react-ts -* Copyright 2022 Creative Tim (https://www.creative-tim.com) - -Coded by www.creative-tim.com - - ========================================================= - -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -*/ - -// @mui material components -import Card from "@mui/material/Card"; -import Icon from "@mui/material/Icon"; -import { Theme } from "@mui/material/styles"; - -// Material Dashboard 2 PRO React TS components -import MDBox from "components/MDBox"; -import MDTypography from "components/MDTypography"; - -// Material Dashboard 2 PRO React context -import { useMaterialUIController } from "context"; - -function Sidenav(): JSX.Element { - const [controller] = useMaterialUIController(); - const { darkMode } = controller; - - const sidenavItems = [ - { icon: "person", label: "profile", href: "profile" }, - { icon: "receipt_long", label: "basic info", href: "basic-info" }, - { icon: "lock", label: "change password", href: "change-password" }, - { icon: "security", label: "2FA", href: "2fa" }, - { icon: "badge", label: "accounts", href: "accounts" }, - { icon: "campaign", label: "notifications", href: "notifications" }, - { icon: "settings_applications", label: "sessions", href: "sessions" }, - { icon: "delete", label: "delete account", href: "delete-account" }, - ]; - - const renderSidenavItems = sidenavItems.map(({ icon, label, href }, key) => { - const itemKey = `item-${key}`; - - return ( - - ({ - display: "flex", - alignItems: "center", - borderRadius: borderRadius.md, - padding: `${pxToRem(10)} ${pxToRem(16)}`, - transition: transitions.create("background-color", { - easing: transitions.easing.easeInOut, - duration: transitions.duration.shorter, - }), - - "&:hover": { - backgroundColor: light.main, - }, - })} - > - - {icon} - - {label} - - - ); - }); - - return ( - borderRadius.lg, - position: "sticky", - top: "1%", - }} - > - - {renderSidenavItems} - - - ); -} - -export default Sidenav; diff --git a/src/qqq/pages/entity-create/components/TableCell/index.tsx b/src/qqq/pages/entity-create/components/TableCell/index.tsx deleted file mode 100644 index 1d0de7a..0000000 --- a/src/qqq/pages/entity-create/components/TableCell/index.tsx +++ /dev/null @@ -1,61 +0,0 @@ -/** -========================================================= -* Material Dashboard 2 PRO React TS - v1.0.0 -========================================================= - -* Product Page: https://www.creative-tim.com/product/material-dashboard-2-pro-react-ts -* Copyright 2022 Creative Tim (https://www.creative-tim.com) - -Coded by www.creative-tim.com - - ========================================================= - -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -*/ - -import { ReactNode } from "react"; - -// Material Dashboard 2 PRO React TS components -import MDBox from "components/MDBox"; -import MDTypography from "components/MDTypography"; - -// Declaring props types for TableCell -interface Props { - width?: string; - children: ReactNode; - align?: string | any; - padding?: number[]; - noBorder?: boolean; -} - -function TableCell({ width, align, padding, noBorder, children }: Props): JSX.Element { - return ( - - noBorder ? 0 : `${borderWidth[1]} solid ${light.main}`, - }} - > - - {children} - - - ); -} - -// Declaring default props for TableCell -TableCell.defaultProps = { - width: "auto", - align: "left", - padding: [], - noBorder: false, -}; - -export default TableCell; diff --git a/src/qqq/pages/entity-create/index.tsx b/src/qqq/pages/entity-create/index.tsx index effdd33..e1954cf 100644 --- a/src/qqq/pages/entity-create/index.tsx +++ b/src/qqq/pages/entity-create/index.tsx @@ -20,7 +20,7 @@ import Grid from "@mui/material/Grid"; import MDBox from "components/MDBox"; // Settings page components -import CreateForm from "qqq/pages/entity-create/components/CreateForm"; +import CreateForm from "qqq/pages/components/EntityForm"; import BaseLayout from "qqq/pages/components/BaseLayout"; function EntityCreate(): JSX.Element { diff --git a/src/qqq/pages/entity-edit/index.tsx b/src/qqq/pages/entity-edit/index.tsx new file mode 100644 index 0000000..4db3893 --- /dev/null +++ b/src/qqq/pages/entity-edit/index.tsx @@ -0,0 +1,49 @@ +/** + ========================================================= + * Material Dashboard 2 PRO React TS - v1.0.0 + ========================================================= + + * Product Page: https://www.creative-tim.com/product/material-dashboard-2-pro-react-ts + * Copyright 2022 Creative Tim (https://www.creative-tim.com) + + Coded by www.creative-tim.com + + ========================================================= + + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + */ + +// @mui material components +import Grid from "@mui/material/Grid"; + +// Material Dashboard 2 PRO React TS components +import MDBox from "components/MDBox"; + +// Settings page components +import BaseLayout from "qqq/pages/components/BaseLayout"; +import { useParams } from "react-router-dom"; +import EntityForm from "qqq/pages/components/EntityForm"; + +function EntityEdit(): JSX.Element { + const { id } = useParams(); + + return ( + + + + + + + + + + + + + + + + ); +} + +export default EntityEdit; diff --git a/src/qqq/pages/entity-list/components/IdCell/index.tsx b/src/qqq/pages/entity-list/components/IdCell/index.tsx index f7ee9e1..c696047 100644 --- a/src/qqq/pages/entity-list/components/IdCell/index.tsx +++ b/src/qqq/pages/entity-list/components/IdCell/index.tsx @@ -1,17 +1,17 @@ /** -========================================================= -* Material Dashboard 2 PRO React TS - v1.0.0 -========================================================= + ========================================================= + * Material Dashboard 2 PRO React TS - v1.0.0 + ========================================================= -* Product Page: https://www.creative-tim.com/product/material-dashboard-2-pro-react-ts -* Copyright 2022 Creative Tim (https://www.creative-tim.com) + * Product Page: https://www.creative-tim.com/product/material-dashboard-2-pro-react-ts + * Copyright 2022 Creative Tim (https://www.creative-tim.com) -Coded by www.creative-tim.com + Coded by www.creative-tim.com ========================================================= -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -*/ + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + */ // @mui material components import Checkbox from "@mui/material/Checkbox"; @@ -19,6 +19,7 @@ import Checkbox from "@mui/material/Checkbox"; // Material Dashboard 2 PRO React TS components import MDBox from "components/MDBox"; import MDTypography from "components/MDTypography"; +import Link from "@mui/material/Link"; // Declaring props types for IdCell interface Props { @@ -27,12 +28,17 @@ interface Props { } function IdCell({ id, checked }: Props): JSX.Element { + const pathParts = window.location.pathname.split("/"); + const tableName = pathParts[1]; + const href = `/${tableName}/view/${id}/`; + const link = {id}; + return ( - {id} + {link} diff --git a/src/qqq/pages/entity-list/data/dataTableData.tsx b/src/qqq/pages/entity-list/data/dataTableData.tsx deleted file mode 100644 index e5550a5..0000000 --- a/src/qqq/pages/entity-list/data/dataTableData.tsx +++ /dev/null @@ -1,184 +0,0 @@ -/** -========================================================= -* Material Dashboard 2 PRO React TS - v1.0.0 -========================================================= - -* Product Page: https://www.creative-tim.com/product/material-dashboard-2-pro-react-ts -* Copyright 2022 Creative Tim (https://www.creative-tim.com) - -Coded by www.creative-tim.com - - ========================================================= - -* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -*/ - -/* eslint-disable react/prop-types */ -// ProductsList page components -import IdCell from "layouts/ecommerce/orders/order-list/components/IdCell"; -import DefaultCell from "layouts/ecommerce/orders/order-list/components/DefaultCell"; -import StatusCell from "layouts/ecommerce/orders/order-list/components/StatusCell"; -import CustomerCell from "layouts/ecommerce/orders/order-list/components/CustomerCell"; - -// Images -import team1 from "assets/images/team-1.jpg"; -import team2 from "assets/images/team-2.jpg"; -import team3 from "assets/images/team-3.jpg"; -import team4 from "assets/images/team-4.jpg"; -import team5 from "assets/images/team-5.jpg"; -import ivana from "assets/images/ivana-squares.jpg"; - -const dataTableData = { - columns: [ - { Header: "id", accessor: "id", Cell: ({ value }: any) => }, - { - Header: "date", - accessor: "date", - Cell: ({ value }: any) => , - }, - { - Header: "status", - accessor: "status", - Cell: ({ value }: any) => { - let status; - - if (value === "paid") { - status = ; - } else if (value === "refunded") { - status = ; - } else { - status = ; - } - - return status; - }, - }, - { - Header: "customer", - accessor: "customer", - Cell: ({ value: [name, data] }: any) => ( - - ), - }, - { - Header: "product", - accessor: "product", - Cell: ({ value }: any) => { - const [name, data] = value; - - return ( - - ); - }, - }, - { - Header: "revenue", - accessor: "revenue", - Cell: ({ value }: any) => , - }, - ], - - rows: [ - { - id: "#10421", - date: "1 Nov, 10:20 AM", - status: "paid", - customer: ["Orlando Imieto", { image: team2 }], - product: "Nike Sport V2", - revenue: "$140,20", - }, - { - id: "#10422", - date: "1 Nov, 10:53 AM", - status: "paid", - customer: ["Alice Murinho", { image: team1 }], - product: "Valvet T-shirt", - revenue: "$42,00", - }, - { - id: "#10423", - date: "1 Nov, 11:13 AM", - status: "refunded", - customer: ["Michael Mirra", { image: "M" }], - product: ["Leather Wallet", { suffix: "+1 more" }], - revenue: "$25,50", - }, - { - id: "#10424", - date: "1 Nov, 12:20 PM", - status: "paid", - customer: ["Andrew Nichel", { image: team3 }], - product: "Bracelet Onu-Lino", - revenue: "$19,40", - }, - { - id: "#10425", - date: "1 Nov, 1:40 PM", - status: "canceled", - customer: ["Sebastian Koga", { image: team4 }], - product: ["Phone Case Pink", { suffix: "x 2" }], - revenue: "$44,90", - }, - { - id: "#10426", - date: "1 Nov, 2:19 PM", - status: "paid", - customer: ["Laur Gilbert", { image: "L" }], - product: "Backpack Niver", - revenue: "$112,50", - }, - { - id: "#10427", - date: "1 Nov, 3:42 AM", - status: "paid", - customer: ["Iryna Innda", { image: "I" }], - product: "Adidas Vio", - revenue: "$200,00", - }, - { - id: "#10428", - date: "2 Nov, 9:32 AM", - status: "paid", - customer: ["Arrias Liunda", { image: "A" }], - product: "Airpods 2 Gen", - revenue: "$350,00", - }, - { - id: "#10429", - date: "2 Nov, 10:14 AM", - status: "paid", - customer: ["Rugna Ilpio", { image: team5 }], - product: "Bracelet Warret", - revenue: "$15,00", - }, - { - id: "#10430", - date: "2 Nov, 10:14 AM", - status: "refunded", - customer: ["Anna Landa", { image: ivana }], - product: ["Watter Bottle India", { suffix: "x 3" }], - revenue: "$25,00", - }, - { - id: "#10431", - date: "2 Nov, 3:12 PM", - status: "paid", - customer: ["Karl Innas", { image: "K" }], - product: "Kitchen Gadgets", - revenue: "$164,90", - }, - { - id: "#10432", - date: "2 Nov, 5:12 PM", - status: "paid", - customer: ["Oana Kilas", { image: "O", color: "info" }], - product: "Office Papers", - revenue: "$23,90", - }, - ], -}; - -export default dataTableData; diff --git a/src/qqq/pages/entity-list/index.tsx b/src/qqq/pages/entity-list/index.tsx index 7f5283a..b531ae6 100644 --- a/src/qqq/pages/entity-list/index.tsx +++ b/src/qqq/pages/entity-list/index.tsx @@ -12,8 +12,9 @@ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. */ +/* eslint-disable react/no-unstable-nested-components */ -import { useState } from "react"; +import React, { useState } from "react"; // @mui material components import Card from "@mui/material/Card"; @@ -30,14 +31,14 @@ import MDButton from "components/MDButton"; // Material Dashboard 2 PRO React TS examples components import DashboardLayout from "examples/LayoutContainers/DashboardLayout"; import DashboardNavbar from "examples/Navbars/DashboardNavbar"; -import Footer from "examples/Footer"; import DataTable from "examples/Tables/DataTable"; -// import dataTableData from "layouts/ecommerce/orders/order-list/data/dataTableData"; // Data -import { QTableMetaData } from "qqq-frontend-core/lib/model/metaData/QTableMetaData"; import { QController } from "qqq-frontend-core/lib/controllers/QController"; import Link from "@mui/material/Link"; +import { QTableMetaData } from "qqq-frontend-core/lib/model/metaData/QTableMetaData"; +import IdCell from "./components/IdCell"; +import Footer from "../components/Footer"; const qController = new QController("http://localhost:8000"); console.log(qController); @@ -54,8 +55,8 @@ let dataTableData = { function EntityList({ table }: Props): JSX.Element { const [menu, setMenu] = useState(null); - const [thing, thing1] = useState(1); - console.log(thing); + const [tableState, setTableState] = useState(""); + console.log(tableState); const newEntity = (event: any) => setMenu(event.currentTarget); const openMenu = (event: any) => setMenu(event.currentTarget); @@ -66,33 +67,39 @@ function EntityList({ table }: Props): JSX.Element { (async () => { await qController.loadTableMetaData(table.name).then((tableMetaData) => { (async () => { - await qController.query(table.name).then((results) => { + await qController.query(table.name, 250).then((results) => { dataTableData = { columns: [], rows: [], }; - Object.keys(tableMetaData.fields).forEach((key) => { - dataTableData.columns.push({ - Header: key, - accessor: key, - }); + const fields = new Map(Object.entries(tableMetaData.fields)); + const sortedEntries = new Map([...fields.entries()].sort()); + sortedEntries.forEach((value, key) => { + if (key === tableMetaData.primaryKeyField) { + dataTableData.columns.splice(0, 0, { + Header: key, + accessor: key, + Cell: ({ value }: any) => , + }); + } else { + dataTableData.columns.push({ + Header: key, + accessor: key, + }); + } }); results.forEach((record) => { const row = new Map(); const values = new Map(Object.entries(record.values)); values.forEach((value, key) => { - if (key === tableMetaData.primaryKeyField) { - row.set(key, `${value}`); - } else { - row.set(key, value); - } + row.set(key, value); }); dataTableData.rows.push(Object.fromEntries(row)); }); - thing1(table.name === "carrier" ? 2 : 3); + setTableState(table.name); }); })(); }); diff --git a/src/qqq/pages/entity-view/components/ViewContents/index.tsx b/src/qqq/pages/entity-view/components/ViewContents/index.tsx new file mode 100644 index 0000000..299e3b1 --- /dev/null +++ b/src/qqq/pages/entity-view/components/ViewContents/index.tsx @@ -0,0 +1,188 @@ +/** + ========================================================= + * Material Dashboard 2 PRO React TS - v1.0.0 + ========================================================= + + * Product Page: https://www.creative-tim.com/product/material-dashboard-2-pro-react-ts + * Copyright 2022 Creative Tim (https://www.creative-tim.com) + + Coded by www.creative-tim.com + + ========================================================= + + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + */ + +/* eslint-disable no-unused-vars */ +/* eslint-disable spaced-comment */ +/* eslint-disable react/no-array-index-key */ + +import { useParams } from "react-router-dom"; + +// @material-ui core components +import Card from "@mui/material/Card"; +import Grid from "@mui/material/Grid"; + +// Material Dashboard 2 PRO React TS components +import MDBox from "components/MDBox"; +import MDTypography from "components/MDTypography"; + +// Settings page components + +// qqq imports +import { QTableMetaData } from "qqq-frontend-core/lib/model/metaData/QTableMetaData"; +import { QController } from "qqq-frontend-core/lib/controllers/QController"; +import { QTableRecord } from "qqq-frontend-core/lib/model/metaData/QTableRecord"; +import React, { useState } from "react"; + +import Link from "@mui/material/Link"; +import Dialog from "@mui/material/Dialog"; +import DialogTitle from "@mui/material/DialogTitle"; +import DialogContent from "@mui/material/DialogContent"; +import DialogContentText from "@mui/material/DialogContentText"; +import DialogActions from "@mui/material/DialogActions"; +import Button from "@mui/material/Button"; + +import MDButton from "../../../../../components/MDButton"; +import { setLayout } from "../../../../../context"; + +const qController = new QController("http://localhost:8000"); +console.log(qController); + +// Declaring props types for ViewForm +interface Props { + id: string; +} + +function ViewContents({ id }: Props): JSX.Element { + const { tableName } = useParams(); + const [nameValues, setNameValues] = useState([] as JSX.Element[]); + const [loadCounter, setLoadCounter] = useState(0); + const [open, setOpen] = useState(false); + + const handleConfirmDelete = (event: { preventDefault: () => void }) => { + event.preventDefault(); + + (async () => { + await qController.delete(tableName, id).then((results) => { + window.location.href = `/${tableName}/list/`; + }); + })(); + }; + + const tableMetaData = new QTableMetaData(tableName); + if (loadCounter === 0) { + setLoadCounter(1); + (async () => { + await qController.loadTableMetaData(tableName).then((tableMetaData) => { + const formFields = [] as JSX.Element[]; + const fields = new Map(Object.entries(tableMetaData.fields)); + + // make a call to query (just get all for now, and iterate and filter like a caveman) + (async () => { + await qController.query(tableName, 250).then((results) => { + let foundRecord: QTableRecord; + results.forEach((record) => { + const values = new Map(Object.entries(record.values)); + values.forEach((value, key) => { + if (key === tableMetaData.primaryKeyField && value.toString() === id) { + foundRecord = record; + } + }); + }); + + nameValues.push( + + + {tableMetaData.primaryKeyField}:   + + +  {id} + + + ); + + const values = new Map(Object.entries(foundRecord.values)); + const sortedEntries = new Map([...values.entries()].sort()); + sortedEntries.forEach((value, key) => { + if (key !== tableMetaData.primaryKeyField) { + nameValues.push( + + + {key}:   + + +  {value} + + + ); + } + }); + + setLoadCounter(2); + }); + })(); + }); + })(); + } + + const handleConfirmDeleteOpen = () => { + // setOpen(true); + }; + + const handleConfirmDeleteClose = () => { + // setOpen(false); + }; + + const editPath = `/${tableName}/edit/${id}`; + + return ( + + + + Viewing {tableMetaData.label} ({id}) + + + {nameValues} + + + + + delete {tableMetaData.label} + + + Confirm Deletion + + + Are you sure you want to delete this record? + + + + + + + + + edit {tableMetaData.label} + + + + + + ); +} + +export default ViewContents; diff --git a/src/qqq/pages/entity-view/index.tsx b/src/qqq/pages/entity-view/index.tsx new file mode 100644 index 0000000..e48ec87 --- /dev/null +++ b/src/qqq/pages/entity-view/index.tsx @@ -0,0 +1,51 @@ +/** + ========================================================= + * Material Dashboard 2 PRO React TS - v1.0.0 + ========================================================= + + * Product Page: https://www.creative-tim.com/product/material-dashboard-2-pro-react-ts + * Copyright 2022 Creative Tim (https://www.creative-tim.com) + + Coded by www.creative-tim.com + + ========================================================= + + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + */ + +import { useParams } from "react-router-dom"; + +// @mui material components +import Grid from "@mui/material/Grid"; + +// Material Dashboard 2 PRO React TS components +import MDBox from "components/MDBox"; + +// Settings page components +// import CreateForm from "qqq/pages/entity-create/components/CreateForm"; +import BaseLayout from "qqq/pages/components/BaseLayout"; +import ViewContents from "./components/ViewContents"; + +function EntityView(): JSX.Element { + const { id } = useParams(); + + return ( + + + + + + + + + + + + + + + + ); +} + +export default EntityView; diff --git a/src/qqq/qqqRoutes.tsx b/src/qqq/qqqRoutes.tsx index 5c8e7fd..61e61d6 100644 --- a/src/qqq/qqqRoutes.tsx +++ b/src/qqq/qqqRoutes.tsx @@ -393,8 +393,11 @@ console.log(qController); await qController.loadMetaData().then((metaData) => { console.log(`metaData: ${metaData}`); + // get the keys sorted + const keys = new Map([...metaData.entries()].sort()); + const tableList = [] as any[]; - metaData.forEach((value, key) => { + keys.forEach((value, key) => { const table = metaData.get(key); tableList.push({ name: table.label, diff --git a/tsconfig.json b/tsconfig.json index 54f563d..c520734 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,7 +20,8 @@ "noImplicitThis": true, "strictNullChecks": false, "downlevelIteration": true, - "baseUrl": "src" + "baseUrl": "src", + "allowAsProps": true }, "include": ["src"] }