From 754c5eb746e4878fce338e1a38aa27df2df99699 Mon Sep 17 00:00:00 2001 From: padamsen_fisker Date: Fri, 8 Dec 2023 12:27:54 -0500 Subject: [PATCH] further improvements --- src/components/Contexts/VehicleContext.jsx | 22 ++- src/components/Flashpack/Details/index.jsx | 159 +++++++++++++++++++++ src/components/Flashpack/index.jsx | 2 +- src/components/Routes/SiteRoutes.jsx | 7 +- 4 files changed, 185 insertions(+), 5 deletions(-) create mode 100644 src/components/Flashpack/Details/index.jsx diff --git a/src/components/Contexts/VehicleContext.jsx b/src/components/Contexts/VehicleContext.jsx index f2f74a9..8b25310 100644 --- a/src/components/Contexts/VehicleContext.jsx +++ b/src/components/Contexts/VehicleContext.jsx @@ -309,6 +309,26 @@ export const VehicleProvider = ({ children }) => { return result; }; + const getFlashpackECUMappings = async (flashpack, model, year, options, token) => { + let result; + try { + setBusy(true); + + result = await api.getAllFlashpacks(options, token); + if (result.error) + throw new Error(`Get all flashpacks error. ${result.message}`); + + setFlashpacks(result.data); + if (options && options.offset === 0 && result.total) { + setTotalFlashpacks(result.total); + } + } finally { + setBusy(false); + } + + return result; + }; + return ( { flashpacks, totalFlashpacks, getAllFlashpacks, - // getFlashpackECUMappings, + getFlashpackECUMappings, // addFlashpackECUMapping, // deleteFlashpackECUMapping, }} diff --git a/src/components/Flashpack/Details/index.jsx b/src/components/Flashpack/Details/index.jsx new file mode 100644 index 0000000..7bf6ba5 --- /dev/null +++ b/src/components/Flashpack/Details/index.jsx @@ -0,0 +1,159 @@ +import { + Table, + TableBody, + TableCell, + TableFooter, + TablePagination, + TableRow, +} from "@material-ui/core"; +import { logger } from "../../../services/monitoring"; +import React, { useEffect, useState } from "react"; +import { useVehicleContext, VehicleProvider } from "../../Contexts/VehicleContext"; +import { useStatusContext } from "../../Contexts/StatusContext"; +import { useUserContext } from "../../Contexts/UserContext"; +import TableHeaderSortable from "../../Table/HeaderSortable"; +import { useLocalStorage } from "../../useLocalStorage"; +import useStyles from "../../useStyles"; + +const tableColumns = [ + { + id: "ecu_name", + label: "ECU Name", + }, + { + id: "ecu_version", + label: "ECU Version", + }, +]; + +const PAGE_SIZE = "FLASHPACK_MAPPINGS_TABLE_PAGE_SIZE"; + +const MainForm = () => { + const classes = useStyles(); + const { setMessage, setTitle, setSitePath } = useStatusContext(); + const [pageSize, setPageSize] = useLocalStorage(PAGE_SIZE, 10); + const [pageIndex, setPageIndex] = useState(0); + const [orderBy, setOrderBy] = useState("flashpack"); + const [order, setOrder] = useState("desc"); + const { + getAllFlashpacks, + flashpacks, + totalFlashpacks, + } = useVehicleContext(); + const { + token: { + idToken: { jwtToken: token }, + }, + } = useUserContext(); + const { flashpack } = useParams(); + + useEffect(() => { + setTitle(`Flashpack ${flashpack}`); + setSitePath([ + { + label: `Flashpack ${flashpack}`, + link: `/tools/flashpack/${flashpack}`, + }, + ]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + + useEffect(() => { + loadFlashpacks(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [token, token, pageIndex, pageSize, orderBy, order]); + + const loadFlashpacks = async () => { + try { + if (!token) return; + await getAllFlashpacks( + { + limit: pageSize, + offset: pageSize * pageIndex, + order: `${orderBy} ${order}`, + }, + token + ); + } catch (e) { + setMessage(e.message); + logger.warn(e.stack); + } + }; + + const handleChangePageIndex = (event, newIndex) => { + setPageIndex(newIndex); + }; + + const handleChangePageSize = (event) => { + setPageSize(parseInt(event.target.value, 10)); + setPageIndex(0); + }; + + const handleSort = (event, property) => { + try { + if (property === orderBy) { + if (order === "asc") { + setOrder("desc"); + } else { + setOrder("asc"); + } + } else { + setOrderBy(property); + setOrder("asc"); + } + } catch (e) { + logger.warn(e.stack); + } + }; + + return ( +
+ + + + {flashpacks && flashpacks.map((row, index) => ( + + + {row} + + + ))} + + + + {!flashpacks || flashpacks.length === 0 ? ( + No Flashpack Numbers + ) : ( + )} + + +
+
+ ); +}; + +const FlashpackDetails = () => ( + + + +); + +export default FlashpackDetails; \ No newline at end of file diff --git a/src/components/Flashpack/index.jsx b/src/components/Flashpack/index.jsx index 6c3981e..8a84e66 100644 --- a/src/components/Flashpack/index.jsx +++ b/src/components/Flashpack/index.jsx @@ -46,7 +46,7 @@ const MainForm = () => { setTitle("Flashpacks"); setSitePath([ { - label: "Tools", + label: "Flashpacks", link: "/tools/flashpacks", }, ]); diff --git a/src/components/Routes/SiteRoutes.jsx b/src/components/Routes/SiteRoutes.jsx index f3118ac..a56a54e 100644 --- a/src/components/Routes/SiteRoutes.jsx +++ b/src/components/Routes/SiteRoutes.jsx @@ -41,6 +41,7 @@ const SMSSend = React.lazy(() => import("../SMS/Send")); const SuppliersList = React.lazy(() => import("../Suppliers/List")); const SupplierDetails = React.lazy(() => import("../Suppliers/Details")); const Flashpacks = React.lazy(() => import("../Flashpack")); +const FlashpackDetails = React.lazy(() => import("../Flashpack/Details")); const Datascope = React.lazy(() => import("../Dashboard")); const SumsRxSwin = React.lazy(() => import("../SUMS")); const SumsRxSwinAdd = React.lazy(() => import("../SUMS/Add")); @@ -290,15 +291,15 @@ const SiteRoutes = () => { rolesPerGroup={Permissions.FiskerRead} providers={providers} /> - {/* } + render={() => } type={TYPES.PROTECTED} token={token} groups={groups} rolesPerGroup={Permissions.FiskerCreate} providers={providers} - /> */} + /> }