From ee40a4d5442a6b48527991e4a2449934c220e5f5 Mon Sep 17 00:00:00 2001 From: Sina Blattmann Date: Tue, 6 Jun 2023 10:06:22 +0200 Subject: [PATCH] fix some bugs --- typescript/Frontend/lang/en.json | 136 ++++++++++++++++ .../UsersWithDirectAccess.tsx | 13 +- .../UsersWithInheritedAccess.tsx | 6 +- .../src/components/Groups/AddNewDialog.tsx | 13 +- .../src/components/Groups/GroupTabs.tsx | 5 +- .../src/components/Groups/Tree/GroupTree.tsx | 7 +- .../src/components/Groups/Tree/MoveDialog.tsx | 6 +- .../src/components/Groups/Tree/MoveTree.tsx | 7 +- .../src/components/InnovenergySnackbar.tsx | 1 + .../src/components/Installations/Alarms.tsx | 8 +- .../Installations/InstallationTabs.tsx | 5 +- .../Installations/Log/DateRangePicker.tsx | 145 +++++++++++------- .../Installations/Log/ScalarGraph.tsx | 32 ++-- .../components/Layout/NavigationButtons.tsx | 8 +- .../Frontend/src/components/Layout/Table.tsx | 65 -------- .../src/components/Users/UserTabs.tsx | 1 - typescript/Frontend/src/lang/en.json | 30 +++- 17 files changed, 326 insertions(+), 162 deletions(-) create mode 100644 typescript/Frontend/lang/en.json delete mode 100644 typescript/Frontend/src/components/Layout/Table.tsx diff --git a/typescript/Frontend/lang/en.json b/typescript/Frontend/lang/en.json new file mode 100644 index 000000000..ea3953e38 --- /dev/null +++ b/typescript/Frontend/lang/en.json @@ -0,0 +1,136 @@ +{ + "Information": { + "defaultMessage": "Information" + }, + "addNewChild": { + "defaultMessage": "Add new child" + }, + "addNewDialogButton": { + "defaultMessage": "Add new dialog button" + }, + "addUser": { + "defaultMessage": "Create user" + }, + "alarms": { + "defaultMessage": "Alarms" + }, + "applyChanges": { + "defaultMessage": "Apply changes" + }, + "country": { + "defaultMessage": "Country" + }, + "createNewFolder": { + "defaultMessage": "Create new folder" + }, + "createNewUser": { + "defaultMessage": "Create new user" + }, + "customerName": { + "defaultMessage": "Customer name" + }, + "email": { + "defaultMessage": "Email" + }, + "english": { + "defaultMessage": "English" + }, + "error": { + }, + "folder": { + "defaultMessage": "Folder" + }, + "german": { + "defaultMessage": "German" + }, + "groupTabs": { + "defaultMessage": "Group tabs" + }, + "groupTree": { + "defaultMessage": "Group tree" + }, + "information": { + "defaultMessage": "Information" + }, + "inheritedAccess": { + "defaultMessage": "Inherited access from" + }, + "installation": { + "defaultMessage": "Installation" + }, + "installationTabs": { + "defaultMessage": "Installation tabs" + }, + "installations": { + "defaultMessage": "Installations" + }, + "lastWeek": { + "defaultMessage": "Last week" + }, + "location": { + "defaultMessage": "Location" + }, + "log": { + "defaultMessage": "Log" + }, + "logout": { + "defaultMessage": "Logout" + }, + "makeASelection": { + "defaultMessage": "Please make a selection on the left" + }, + "manageAccess": { + "defaultMessage": "Manage access" + }, + "move": { + "defaultMessage": "Move" + }, + "moveTo": { + "defaultMessage": "Move to" + }, + "moveTree": { + "defaultMessage": "Move tree" + }, + "name": { + "defaultMessage": "Name" + }, + "navigationTabs": { + "defaultMessage": "Navigation tabs" + }, + "orderNumbers": { + "defaultMessage": "Order number" + }, + "region": { + "defaultMessage": "Region" + }, + "requiredLocation": { + "defaultMessage": "Location is required" + }, + "requiredName": { + "defaultMessage": "Name is required" + }, + "requiredRegion": { + "defaultMessage": "Region is required" + }, + "search": { + "defaultMessage": "Search" + }, + "submit": { + "defaultMessage": "Submit" + }, + "updateFolderErrorMessage": { + "defaultMessage": "Couldn't update folder, an error occured" + }, + "updatedSuccessfully": { + "defaultMessage": "Updated successfully" + }, + "user": { + "defaultMessage": "User" + }, + "userTabs": { + "defaultMessage": "user tabs" + }, + "users": { + "defaultMessage": "Users" + } +} diff --git a/typescript/Frontend/src/components/Groups/AccessManagement/UsersWithDirectAccess.tsx b/typescript/Frontend/src/components/Groups/AccessManagement/UsersWithDirectAccess.tsx index aba3365f5..3e2e4285c 100644 --- a/typescript/Frontend/src/components/Groups/AccessManagement/UsersWithDirectAccess.tsx +++ b/typescript/Frontend/src/components/Groups/AccessManagement/UsersWithDirectAccess.tsx @@ -5,8 +5,9 @@ import { IconButton, Avatar, ListItemAvatar, + Alert, } from "@mui/material"; -import { Fragment, useContext, useEffect } from "react"; +import { Fragment, useContext, useEffect, useState } from "react"; import axiosConfig from "../../../config/axiosConfig"; import PersonRemoveIcon from "@mui/icons-material/PersonRemove"; import PersonIcon from "@mui/icons-material/Person"; @@ -14,10 +15,12 @@ import { UsersContext } from "../../Context/UsersContextProvider"; import { useParams } from "react-router-dom"; import { GroupContext } from "../../Context/GroupContextProvider"; import { UserContext } from "../../Context/UserContextProvider"; +import { FormattedMessage } from "react-intl"; const UsersWithDirectAccess = () => { const { fetchUsersWithDirectAccessForResource, directAccessUsers } = useContext(UsersContext); + const [error, setError] = useState(); const { currentType } = useContext(GroupContext); const { id } = useParams(); const { getCurrentUser } = useContext(UserContext); @@ -35,12 +38,20 @@ const UsersWithDirectAccess = () => { }) .then((res) => { fetchUsersWithDirectAccessForResource(); + }) + .catch((err) => { + setError(err); }); }; if (directAccessUsers && directAccessUsers.length) { return ( <> + {error && ( + + + + )} {directAccessUsers.map((user) => { return ( diff --git a/typescript/Frontend/src/components/Groups/AccessManagement/UsersWithInheritedAccess.tsx b/typescript/Frontend/src/components/Groups/AccessManagement/UsersWithInheritedAccess.tsx index bfa8caaea..d6ea6e4d8 100644 --- a/typescript/Frontend/src/components/Groups/AccessManagement/UsersWithInheritedAccess.tsx +++ b/typescript/Frontend/src/components/Groups/AccessManagement/UsersWithInheritedAccess.tsx @@ -14,6 +14,7 @@ import { import routes from "../../../routes.json"; import PersonIcon from "@mui/icons-material/Person"; import { UsersContext } from "../../Context/UsersContextProvider"; +import { FormattedMessage } from "react-intl"; const UsersWithInheritedAccess = () => { const { fetchUsersWithInheritedAccessForResource, inheritedAccessUsers } = @@ -45,7 +46,10 @@ const UsersWithInheritedAccess = () => { primary={user.name} secondary={ <> - Inherited access from{" "} + { const [open, setOpen] = useState(false); + const intl = useIntl(); const handleSubmit = (data: I_Folder, childData: Partial) => { return axiosConfig @@ -49,13 +50,19 @@ const AddNewDialog = (props: AddNewDialogProps) => { maxWidth="sm" > - Create new folder + setOpen(false)} - aria-label="close" + aria-label={intl.formatMessage({ + id: "addNewDialogButton", + defaultMessage: "Add new dialog button", + })} sx={{ position: "absolute", right: 8, diff --git a/typescript/Frontend/src/components/Groups/GroupTabs.tsx b/typescript/Frontend/src/components/Groups/GroupTabs.tsx index 9e1fb4d08..573a36594 100644 --- a/typescript/Frontend/src/components/Groups/GroupTabs.tsx +++ b/typescript/Frontend/src/components/Groups/GroupTabs.tsx @@ -24,7 +24,10 @@ const GroupTabs = () => { {currentType === "Folder" ? ( { const { setCurrentType, fetchData, data, loading } = useContext(GroupContext); const [openNodes, setOpenNodes] = useState([]); const [selected, setSelected] = useState(""); + const intl = useIntl(); useEffect(() => { fetchData(); @@ -69,7 +71,10 @@ const GroupTree = () => { if (data) { return ( } defaultExpandIcon={} sx={{ diff --git a/typescript/Frontend/src/components/Groups/Tree/MoveDialog.tsx b/typescript/Frontend/src/components/Groups/Tree/MoveDialog.tsx index bfe47093c..b6b00467a 100644 --- a/typescript/Frontend/src/components/Groups/Tree/MoveDialog.tsx +++ b/typescript/Frontend/src/components/Groups/Tree/MoveDialog.tsx @@ -56,7 +56,9 @@ const MoveDialog = (props: MoveDialogProps) => { }} scroll="paper" > - Move to + + + { id={"move-dialog-move-button-" + id} onClick={handleMove} > - Move + diff --git a/typescript/Frontend/src/components/Groups/Tree/MoveTree.tsx b/typescript/Frontend/src/components/Groups/Tree/MoveTree.tsx index db1c3d871..db39df7c5 100644 --- a/typescript/Frontend/src/components/Groups/Tree/MoveTree.tsx +++ b/typescript/Frontend/src/components/Groups/Tree/MoveTree.tsx @@ -6,6 +6,7 @@ import { TreeItem } from "@mui/lab"; import { I_Folder, I_Installation } from "../../../util/types"; import { GroupContext } from "../../Context/GroupContextProvider"; import { instanceOfFolder } from "../../../util/group.util"; +import { useIntl } from "react-intl"; interface MoveTreeProps { setSelectedParentId: (value: number) => void; @@ -14,6 +15,7 @@ interface MoveTreeProps { const MoveTree = (props: MoveTreeProps) => { const { data } = useContext(GroupContext); + const intl = useIntl(); const getNodes = (element: I_Folder | I_Installation): null | ReactNode => { if (instanceOfFolder(element)) { @@ -42,7 +44,10 @@ const MoveTree = (props: MoveTreeProps) => { if (data) { return ( } defaultExpandIcon={} sx={{ diff --git a/typescript/Frontend/src/components/InnovenergySnackbar.tsx b/typescript/Frontend/src/components/InnovenergySnackbar.tsx index 5223131b9..b78eae667 100644 --- a/typescript/Frontend/src/components/InnovenergySnackbar.tsx +++ b/typescript/Frontend/src/components/InnovenergySnackbar.tsx @@ -12,6 +12,7 @@ const InnovenergySnackbar = (props: InnovenergySnackbarProps) => { const handleClose = () => { setOpen(false); }; + return ( { - return
alarms
; + return ( +
+ +
+ ); }; export default Alarms; diff --git a/typescript/Frontend/src/components/Installations/InstallationTabs.tsx b/typescript/Frontend/src/components/Installations/InstallationTabs.tsx index 1f20b0bd0..ea7db5818 100644 --- a/typescript/Frontend/src/components/Installations/InstallationTabs.tsx +++ b/typescript/Frontend/src/components/Installations/InstallationTabs.tsx @@ -22,7 +22,10 @@ const InstallationTabs = () => { void; @@ -15,64 +19,87 @@ interface DateRangePickerProps { } const DateRangePicker = (props: DateRangePickerProps) => { const { setRange, range, getCacheSeries } = props; - const [open, setOpen] = useState(false); + const [fromDateError, setFromDateError] = + useState(null); + const [toDateError, setToDateError] = + useState(null); + + const handleChange = (fromDate: Date, toDate: Date) => { + setRange([fromDate, toDate]); + getCacheSeries(fromDate.getMilliseconds(), toDate.getMilliseconds()); + }; return ( <> - setOpen(true)}> - Set range - - setOpen(false)}> - Set range - -
- -
- - { - if (newValue) { - const fromDate = newValue.toDate(); - const toDate = range[1]; - setRange([fromDate, toDate]); - getCacheSeries(+fromDate, +toDate); - } - }} - /> - { - if (newValue) { - const fromDate = newValue.toDate(); - const toDate = range[1]; - setRange([fromDate, toDate]); - getCacheSeries(+fromDate, +toDate); - } - }} - /> - -
-
+
+ +
+ + { + if (newValue) { + handleChange(newValue.toDate(), range[1]); + } + }} + onError={(err) => setFromDateError(err)} + slotProps={{ + textField: { + variant: "outlined", + error: !!fromDateError, + helperText: fromDateError + ? "From date needs to be before to date" + : "", + }, + }} + /> + setToDateError(err)} + onChange={(newValue) => { + if (newValue) { + handleChange(range[0], newValue.toDate()); + } + }} + slotProps={{ + textField: { + variant: "outlined", + error: !!toDateError, + helperText: toDateError + ? "To date needs to be after from date" + : "", + }, + }} + /> + ); }; diff --git a/typescript/Frontend/src/components/Installations/Log/ScalarGraph.tsx b/typescript/Frontend/src/components/Installations/Log/ScalarGraph.tsx index 72693b258..eabbfcaa8 100644 --- a/typescript/Frontend/src/components/Installations/Log/ScalarGraph.tsx +++ b/typescript/Frontend/src/components/Installations/Log/ScalarGraph.tsx @@ -4,7 +4,7 @@ import { GraphData, createTimes, flattenToggles, - insertTreeElements, + getTreeElements, isNumeric, parseCsv, stringToColor, @@ -16,20 +16,20 @@ import { BehaviorSubject, startWith, throttleTime, withLatestFrom } from "rxjs"; import { S3Access } from "../../../dataCache/S3/S3Access"; import DataCache, { FetchResult } from "../../../dataCache/dataCache"; import { LogContext } from "../../Context/LogContextProvider"; -import { TreeElement } from "./CheckboxTree"; import { isDefined } from "../../../dataCache/utils/maybe"; import { Data, Layout } from "plotly.js"; -import { Alert, Button, ToggleButton, ToggleButtonGroup } from "@mui/material"; +import { Alert } from "@mui/material"; import DateRangePicker from "./DateRangePicker"; import { LocalizationProvider } from "@mui/x-date-pickers"; import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs"; +import { FormattedMessage } from "react-intl"; const NUMBER_OF_NODES = 100; const ScalarGraph = () => { const timeRange = createTimes( UnixTime.now() /* .fromTicks(1682085650) */ - .earlier(TimeSpan.fromDays(7)) + .earlier(TimeSpan.fromDays(14)) .rangeBefore(TimeSpan.fromDays(4)), NUMBER_OF_NODES ); @@ -38,6 +38,7 @@ const ScalarGraph = () => { timeRange[0].toDate(), timeRange[timeRange.length - 1].toDate(), ]); + const [uiRevision, setUiRevision] = useState(Math.random()); const [plotTitles, setPlotTitles] = useState([]); @@ -67,22 +68,11 @@ const ScalarGraph = () => { setTimeSeries(timeSeries); const toggleValues = timeSeries.find((timeStamp) => timeStamp.value); if (toggles === null && toggleValues && toggleValues.value) { - const treeElements = Object.keys(toggleValues.value) - .map((path) => - path - .split("/") - .map((_, i, arr) => `/${arr.slice(1, i + 1).join("/")}`) - .slice(1) - ) - .reduce( - (children, path) => insertTreeElements(children, path), - [] as TreeElement[] - ); + const treeElements = getTreeElements(toggleValues.value); setToggles(treeElements); setCheckedToggles(flattenToggles(treeElements)); } }); - return () => subscription.unsubscribe(); }, [toggles]); @@ -199,7 +189,6 @@ const ScalarGraph = () => { barnorm: "percent", } : {}; - return ( { ], }} onRelayout={(params) => { - console.log("relayout"); const xaxisRange0 = params["xaxis.range[0]"]; const xaxisRange1 = params["xaxis.range[1]"]; if (xaxisRange0 && xaxisRange1) { setRange([new Date(xaxisRange0), new Date(xaxisRange1)]); setUiRevision(Math.random()); - console.log("ranges", xaxisRange0); getCacheSeries(xaxisRange0, xaxisRange1); } }} - onRestyle={() => "event restyle"} - onRedraw={() => "event restyle"} /> ); })} @@ -249,7 +234,10 @@ const ScalarGraph = () => { } return ( - Please make a selection on the left + ); } diff --git a/typescript/Frontend/src/components/Layout/NavigationButtons.tsx b/typescript/Frontend/src/components/Layout/NavigationButtons.tsx index 2e2ed032c..814ebf9ae 100644 --- a/typescript/Frontend/src/components/Layout/NavigationButtons.tsx +++ b/typescript/Frontend/src/components/Layout/NavigationButtons.tsx @@ -1,4 +1,4 @@ -import { FormattedMessage } from "react-intl"; +import { FormattedMessage, useIntl } from "react-intl"; import { Link } from "react-router-dom"; import useRouteMatch from "../../hooks/useRouteMatch"; import routes from "../../routes.json"; @@ -9,6 +9,7 @@ const NavigationButtons = () => { routes.installations + "*", routes.users + "*", ]); + const intl = useIntl(); return ( <> @@ -37,7 +38,10 @@ const NavigationButtons = () => { { - return ( - - {/* - - - Device - Code - Message - Severity - - - - {rows.map((row, i) => ( - - {row.device} - {row.code} - {row.message} - {row.severity} - - ))} - -
*/} -
- ); -}; - -export default BasicTable; diff --git a/typescript/Frontend/src/components/Users/UserTabs.tsx b/typescript/Frontend/src/components/Users/UserTabs.tsx index 23de0b79d..d3d6f6ff1 100644 --- a/typescript/Frontend/src/components/Users/UserTabs.tsx +++ b/typescript/Frontend/src/components/Users/UserTabs.tsx @@ -1,5 +1,4 @@ import * as React from "react"; -import Box from "@mui/material/Box"; import { Link } from "react-router-dom"; import routes from "../../routes.json"; import useRouteMatch from "../../hooks/useRouteMatch"; diff --git a/typescript/Frontend/src/lang/en.json b/typescript/Frontend/src/lang/en.json index 35a821433..aabb7b8fe 100644 --- a/typescript/Frontend/src/lang/en.json +++ b/typescript/Frontend/src/lang/en.json @@ -18,5 +18,33 @@ "groups": "Groups", "group": "Group", "folder": "Folder", - "updateFolderErrorMessage": "Couldn't update folder, an error occured" + "updateFolderErrorMessage": "Couldn't update folder, an error occured", + "Information": "Information", + "addNewChild": "Add new child", + "addNewDialogButton": "Add new dialog button", + "addUser": "Create user", + "createNewFolder": "Create new folder", + "createNewUser": "Create new user", + "email": "Email", + "error": "", + "groupTabs": "Group tabs", + "groupTree": "Group tree", + "information": "Information", + "inheritedAccess": "Inherited access from", + "installationTabs": "Installation tabs", + "installations": "Installations", + "lastWeek": "Last week", + "makeASelection": "Please make a selection on the left", + "manageAccess": "Manage access", + "move": "Move", + "moveTo": "Move to", + "moveTree": "Move tree", + "name": "Name", + "navigationTabs": "Navigation tabs", + "requiredLocation": "Location is required", + "requiredName": "Name is required", + "requiredRegion": "Region is required", + "submit": "Submit", + "user": "User", + "userTabs": "user tabs" }