From 8c6d11795cdab00ba321333459a4636a25ad0cd6 Mon Sep 17 00:00:00 2001 From: Yinyin Liu Date: Tue, 21 Jan 2025 11:51:54 +0100 Subject: [PATCH] test implementing flat installation view of Sodiohome --- typescript/frontend-marios2/src/App.tsx | 4 +- .../FlatInstallationView.tsx | 338 ++++++++++++++++++ .../InstallationSearch.tsx | 44 +-- 3 files changed, 363 insertions(+), 23 deletions(-) create mode 100644 typescript/frontend-marios2/src/content/dashboards/SodiohomeInstallations/FlatInstallationView.tsx diff --git a/typescript/frontend-marios2/src/App.tsx b/typescript/frontend-marios2/src/App.tsx index 1b51d2995..ecb77c3d8 100644 --- a/typescript/frontend-marios2/src/App.tsx +++ b/typescript/frontend-marios2/src/App.tsx @@ -19,7 +19,7 @@ import { axiosConfigWithoutToken } from './Resources/axiosConfig'; import InstallationsContextProvider from './contexts/InstallationsContextProvider'; import AccessContextProvider from './contexts/AccessContextProvider'; import SalidomoInstallationTabs from './content/dashboards/SalidomoInstallations'; -// import SodiohomeInstallationTabs from './content/dashboards/SodiohomeInstallations'; +import SodioHomeInstallationTabs from './content/dashboards/SodiohomeInstallations'; import { ProductIdContext } from './contexts/ProductIdContextProvider'; function App() { @@ -170,7 +170,7 @@ function App() { path={routes.sodiohome_installations + '*'} element={ - {/**/} + } /> diff --git a/typescript/frontend-marios2/src/content/dashboards/SodiohomeInstallations/FlatInstallationView.tsx b/typescript/frontend-marios2/src/content/dashboards/SodiohomeInstallations/FlatInstallationView.tsx new file mode 100644 index 000000000..7b9af3266 --- /dev/null +++ b/typescript/frontend-marios2/src/content/dashboards/SodiohomeInstallations/FlatInstallationView.tsx @@ -0,0 +1,338 @@ +import React, { useState } from 'react'; +import { + Card, + CircularProgress, + Grid, + styled, + Table, + TableBody, + TableCell, + TableContainer, + TableHead, + TableRow, + Typography, + useTheme +} from '@mui/material'; +import { I_Installation } from 'src/interfaces/InstallationTypes'; +import { FormattedMessage } from 'react-intl'; +import { useLocation, useNavigate } from 'react-router-dom'; +import routes from '../../../Resources/routes.json'; +import CancelIcon from '@mui/icons-material/Cancel'; +import BuildIcon from '@mui/icons-material/Build'; + +interface FlatInstallationViewProps { + installations: I_Installation[]; +} + +const FlatInstallationView = (props: FlatInstallationViewProps) => { + // const webSocketContext = useContext(WebSocketContext); + // const { getSortedInstallations } = webSocketContext; + const navigate = useNavigate(); + const [selectedInstallation, setSelectedInstallation] = useState(-1); + const currentLocation = useLocation(); + // + const sortedInstallations = [...props.installations].sort((a, b) => { + // Compare the status field of each installation and sort them based on the status. + //Installations with alarms go first + let a_status = a.status; + let b_status = b.status; + + if (a_status > b_status) { + return -1; + } + if (a_status < b_status) { + return 1; + } + return 0; + }); + + const handleSelectOneInstallation = (installationID: number): void => { + if (selectedInstallation != installationID) { + setSelectedInstallation(installationID); + setSelectedInstallation(-1); + + navigate( + routes.sodiohome_installations + + routes.list + + routes.installation + + `${installationID}` + + '/' + + routes.batteryview, + { + replace: true + } + ); + } else { + setSelectedInstallation(-1); + } + }; + + const theme = useTheme(); + + const HoverableTableRow = styled(TableRow)(({ theme }) => ({ + cursor: 'pointer', + '&:hover': { + backgroundColor: theme.palette.action.hover // Or any other color + } + })); + + return ( + + + + + + + + + + + + + + + + + + + + {/**/} + {/* */} + {/**/} + {/**/} + {/* */} + {/**/} + + + + {sortedInstallations + // .filter( + // (installation) => + // installation.status === -1 && + // installation.testingMode == false + // ) + .map((installation) => { + const isInstallationSelected = + installation.s3BucketId === selectedInstallation; + + const status = installation.status; + + return ( + + handleSelectOneInstallation(installation.s3BucketId) + } + > + + + {installation.name} + + + + + + {installation.location} + + + + + + {installation.region} + + + + + + {installation.country} + + + + + + e.stopPropagation()} // Prevent the click event from bubbling up to the table row + > + VRM link + + + + + +
+ {installation.device === 1 ? ( + + Cerbo + + ) : installation.device === 2 ? ( + + Venus + + ) : ( + + Device not specified + + )} +
+
+ + +
+ {status === -1 ? ( + + ) : ( + '' + )} + + {status === -2 ? ( + + ) : ( + '' + )} + +
+ {installation.testingMode && ( + + )} +
+ + + ); + })} + +
+
+
+
+
+ ); +}; + +export default FlatInstallationView; diff --git a/typescript/frontend-marios2/src/content/dashboards/SodiohomeInstallations/InstallationSearch.tsx b/typescript/frontend-marios2/src/content/dashboards/SodiohomeInstallations/InstallationSearch.tsx index 62ca20dc5..0c4f8bf41 100644 --- a/typescript/frontend-marios2/src/content/dashboards/SodiohomeInstallations/InstallationSearch.tsx +++ b/typescript/frontend-marios2/src/content/dashboards/SodiohomeInstallations/InstallationSearch.tsx @@ -2,8 +2,10 @@ import React, { useMemo, useState } from 'react'; import { FormControl, Grid, InputAdornment, TextField } from '@mui/material'; import SearchTwoToneIcon from '@mui/icons-material/SearchTwoTone'; import { I_Installation } from '../../../interfaces/InstallationTypes'; -import { useLocation } from 'react-router-dom'; +import { Route, Routes,useLocation } from 'react-router-dom'; import routes from '../../../Resources/routes.json'; +import FlatInstallationView from './FlatInstallationView'; +import SodioHomeInstallation from './Installation'; interface installationSearchProps { installations: I_Installation[]; @@ -42,9 +44,9 @@ function InstallationSearch(props: installationSearchProps) { sx={{ display: currentLocation.pathname === - routes.salidomo_installations + 'list' || + routes.sodiohome_installations + 'list' || currentLocation.pathname === - routes.salidomo_installations + routes.list + routes.sodiohome_installations + routes.list ? 'block' : 'none' }} @@ -75,24 +77,24 @@ function InstallationSearch(props: installationSearchProps) { - {/**/} - {/**/} - {/* {filteredData.map((installation) => {*/} - {/* return (*/} - {/* */} - {/* }*/} - {/* />*/} - {/* );*/} - {/* })}*/} - {/**/} + + + {filteredData.map((installation) => { + return ( + + } + /> + ); + })} + ); }