diff --git a/typescript/Frontend/src/App.tsx b/typescript/Frontend/src/App.tsx index 711216363..5a482cdda 100644 --- a/typescript/Frontend/src/App.tsx +++ b/typescript/Frontend/src/App.tsx @@ -1,12 +1,7 @@ import useToken from "./hooks/useToken"; import Login from "./Login"; import { BrowserRouter, Route, Routes } from "react-router-dom"; -import { Box, Grid, Divider } from "@mui/material"; -import BasicTable from "./components/Table"; -import InstallationTabs from "./components/InstallationTabs"; -import Alarms from "./routes/Alarms"; -import InstallationDetail from "./routes/Installation"; -import Log from "./routes/Log"; +import { Grid } from "@mui/material"; import routes from "./routes.json"; import { IntlProvider } from "react-intl"; import { useState } from "react"; @@ -14,14 +9,13 @@ import en from "./lang/en.json"; import de from "./lang/de.json"; import LanguageSelect from "./components/LanguageSelect"; import LogoutButton from "./components/LogoutButton"; -import NavigationButtons from "./components/NavigationButtons"; -import UserList from "./components/UserTree"; -import Sidebar from "./components/Sidebar"; +import Installations from "./routes/Installations"; + +import Users from "./routes/Users"; const App = () => { const { token, setToken, removeToken } = useToken(); const [language, setLanguage] = useState("en"); - const [currentView, setCurrentView] = useState("installations"); const getTranslations = () => { if (language === "de") { @@ -45,43 +39,13 @@ const App = () => { - - - - - {currentView === "installations" ? : } - - - - - - {currentView === "installations" && ( - <> - - - } - /> - } /> - } /> - } /> - - - )} - - - + + } + /> + } /> + ); diff --git a/typescript/Frontend/src/components/InstallationList.tsx b/typescript/Frontend/src/components/InstallationList.tsx index c151fd9aa..07ff648fe 100644 --- a/typescript/Frontend/src/components/InstallationList.tsx +++ b/typescript/Frontend/src/components/InstallationList.tsx @@ -41,10 +41,10 @@ const InstallationList = (props: InstallationListProps) => { const filteredData = filterData(props.searchQuery, data); const routeMatch = useRouteMatch([ - routes.installationWithId, - routes.alarmsWithId, - routes.usersWithId, - routes.logWithId, + routes.installations + routes.installation + ":id", + routes.installations + routes.alarms + ":id", + routes.installations + routes.users + ":id", + routes.installations + routes.log + ":id", ]); useEffect(() => { @@ -76,25 +76,31 @@ const InstallationList = (props: InstallationListProps) => { component="nav" aria-labelledby="nested-list-subheader" > - {filteredData?.map((installation) => ( - - - { + console.log(routeMatch); + return ( + + - - - - - - ))} + + + + + + + ); + })} )} diff --git a/typescript/Frontend/src/components/InstallationTabs.tsx b/typescript/Frontend/src/components/InstallationTabs.tsx index 8291357ac..86987e375 100644 --- a/typescript/Frontend/src/components/InstallationTabs.tsx +++ b/typescript/Frontend/src/components/InstallationTabs.tsx @@ -9,10 +9,10 @@ import { useIntl } from "react-intl"; const InstallationTabs = () => { const routeMatch = useRouteMatch([ - routes.installationWithId, - routes.alarmsWithId, - routes.usersWithId, - routes.logWithId, + routes.installations + routes.installation + ":id", + routes.installations + routes.alarms + ":id", + routes.installations + routes.users + ":id", + routes.installations + routes.log + ":id", ]); const id = routeMatch?.params?.id; @@ -23,7 +23,7 @@ const InstallationTabs = () => { { id: "installation", defaultMessage: "Installation", })} - value={routes.installationWithId} + value={ + routes.installations + routes.installation + ":id" + } component={Link} to={routes.installation + id} /> @@ -40,7 +42,7 @@ const InstallationTabs = () => { id: "alarms", defaultMessage: "Alarms", })} - value={routes.alarmsWithId} + value={routes.installations + routes.alarms + ":id"} component={Link} to={routes.alarms + id} /> @@ -49,7 +51,7 @@ const InstallationTabs = () => { id: "users", defaultMessage: "Users", })} - value={routes.usersWithId} + value={routes.installations + routes.users + ":id"} component={Link} to={routes.users + id} /> @@ -58,7 +60,7 @@ const InstallationTabs = () => { id: "log", defaultMessage: "Log", })} - value={routes.logWithId} + value={routes.installations + routes.log + ":id"} component={Link} to={routes.log + id} /> diff --git a/typescript/Frontend/src/components/NavigationButtons.tsx b/typescript/Frontend/src/components/NavigationButtons.tsx index 21ccbde9a..096061cb0 100644 --- a/typescript/Frontend/src/components/NavigationButtons.tsx +++ b/typescript/Frontend/src/components/NavigationButtons.tsx @@ -1,33 +1,33 @@ import { ToggleButton, ToggleButtonGroup } from "@mui/material"; import { FormattedMessage } from "react-intl"; +import { Link } from "react-router-dom"; +import useRouteMatch from "../hooks/useRouteMatch"; +import routes from "../routes.json"; -interface NavigationButtonsProps { - currentView: string; - setCurrentView: (value: string) => void; -} -const NavigationButtons = (props: NavigationButtonsProps) => { - const handleChange = ( - event: React.MouseEvent, - newAlignment: string - ) => { - props.setCurrentView(newAlignment); - }; +const NavigationButtons = () => { + const routeMatch = useRouteMatch([ + routes.installations + "*", + routes.tree + "*", + ]); return ( - + - + diff --git a/typescript/Frontend/src/components/UserTree.tsx b/typescript/Frontend/src/components/UserTree.tsx index 219b2e8ca..0e9a7694a 100644 --- a/typescript/Frontend/src/components/UserTree.tsx +++ b/typescript/Frontend/src/components/UserTree.tsx @@ -1,102 +1,23 @@ import TreeView from "@mui/lab/TreeView"; import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; import ChevronRightIcon from "@mui/icons-material/ChevronRight"; -import { ReactNode } from "react"; +import { ReactNode, useEffect, useState } from "react"; import { TreeItem } from "@mui/lab"; import { I_Folder, I_Installation } from "../util/types"; +import axiosConfig from "../config/axiosConfig"; const UserList = () => { - const data: I_Folder[] = [ - { - id: 107, - name: "Bruen-Tromp", - information: "05 Burrows Terrace", - parentId: 75, - type: "Folder", - children: [ - { - id: 100, - name: "Sporer and Sons", - information: "820 Helena Terrace", - parentId: 107, - type: "Folder", - }, - { - id: 101, - name: "Hahn-Heaney", - information: "144 Di Loreto Center", - parentId: 107, - type: "Folder", - }, - ], - }, - { - id: 125, - name: "Sporer and Sons", - information: "820 Helena Terrace", - parentId: 107, - type: "Folder", - children: [ - { - location: "Säffle", - region: "SG", - country: "SE", - orderNumbers: "1LWDGmdXCLmCRFJHTKwcmpoP7bcNeaWJuj", - lat: 0, - long: 0, - s3Bucket: "", - id: 632, - name: "Nikolas Scholz", - information: "", - parentId: 125, - type: "Installation", - }, - { - location: "Krasnoye", - region: "ZH", - country: "RU", - orderNumbers: "1M4Rw8toMSJn3d8ULouDd1gYKzANFXeMWh", - lat: 0, - long: 0, - s3Bucket: "", - id: 248, - name: "Judye Goldson", - information: "", - parentId: 125, - type: "Installation", - }, - { - id: 103, - name: "Bruen-Tromp", - information: "05 Burrows Terrace", - parentId: 75, - type: "Folder", - children: [ - { - id: 100, - name: "Sporer and Sons", - information: "820 Helena Terrace", - parentId: 107, - type: "Folder", - }, - { - id: 101, - name: "Hahn-Heaney", - information: "144 Di Loreto Center", - parentId: 107, - type: "Folder", - }, - ], - }, - ], - }, - { - id: 135, - name: "Hahn-Heaney", - information: "144 Di Loreto Center", - parentId: 107, - type: "Folder", - }, - ]; + const [data, setData] = useState(); + + useEffect(() => { + axiosConfig.get("/GetTree").then((res) => { + setData(res.data); + }); + }, []); + + const handleClick = (e: any, nodes: any) => { + console.log(e); + console.log(nodes); + }; const instanceOfFolder = (object: any): object is I_Folder => { return "children" in object; @@ -122,14 +43,15 @@ const UserList = () => { ); }); }; + return ( } defaultExpandIcon={} sx={{ height: 300, flexGrow: 1, maxWidth: 400 }} + onNodeToggle={handleClick} > - {renderTree(data)} + {data && renderTree(data)} ); }; diff --git a/typescript/Frontend/src/routes.json b/typescript/Frontend/src/routes.json index 311ef8a1c..c65eb635d 100644 --- a/typescript/Frontend/src/routes.json +++ b/typescript/Frontend/src/routes.json @@ -1,11 +1,8 @@ { - "installationWithId": "/installation/:id", - "installation": "/installation/", - "alarmsWithId": "/alarms/:id", - "alarms": "/alarms/", - "usersWithId": "/users/:id", - "users": "/users/", - "logWithId": "/log/:id", - "log": "/log/", - "installations": "/installations" + "installation": "installation/", + "alarms": "alarms/", + "users": "users/", + "log": "log/", + "installations": "/installations/", + "tree": "/users/*" } diff --git a/typescript/Frontend/src/routes/Installation.tsx b/typescript/Frontend/src/routes/Installation.tsx index 675d65ca7..fe6c60dac 100644 --- a/typescript/Frontend/src/routes/Installation.tsx +++ b/typescript/Frontend/src/routes/Installation.tsx @@ -28,7 +28,7 @@ const InstallationDetail = () => { if (values && values.id && values.id.toString() === id) { return ( - + ); diff --git a/typescript/Frontend/src/routes/Installations.tsx b/typescript/Frontend/src/routes/Installations.tsx new file mode 100644 index 000000000..f412a2934 --- /dev/null +++ b/typescript/Frontend/src/routes/Installations.tsx @@ -0,0 +1,49 @@ +import { Grid, Divider } from "@mui/material"; +import { Container } from "@mui/system"; +import { Routes, Route } from "react-router"; +import InstallationTabs from "../components/InstallationTabs"; +import NavigationButtons from "../components/NavigationButtons"; +import BasicTable from "../components/Table"; +import Alarms from "./Alarms"; +import InstallationDetail from "./Installation"; +import Log from "./Log"; +import routes from "../routes.json"; +import Sidebar from "../components/Sidebar"; + +const Installations = () => { + return ( + + + + + + + + + + + + + } + index + /> + } /> + } /> + } /> + + + + + ); +}; + +export default Installations; diff --git a/typescript/Frontend/src/routes/Users.tsx b/typescript/Frontend/src/routes/Users.tsx new file mode 100644 index 000000000..472c949e8 --- /dev/null +++ b/typescript/Frontend/src/routes/Users.tsx @@ -0,0 +1,30 @@ +import { Grid, Divider } from "@mui/material"; +import { Container } from "@mui/system"; +import NavigationButtons from "../components/NavigationButtons"; +import UserTree from "../components/UserTree"; + +const Users = () => { + return ( + + + + + + + + + + + + + ); +}; + +export default Users;