From 4daf171b1e5e008f73beb99e472580f70402c179 Mon Sep 17 00:00:00 2001 From: John Wu <76966357+jwu-fisker@users.noreply.github.com> Date: Mon, 21 Mar 2022 17:21:59 -0700 Subject: [PATCH] CEC-1216 Remove unused components (#129) * CEC-1216 Remove unused components * Remove import --- .../App/__snapshots__/App.test.js.snap | 18 +- src/components/Cars/CarECUs/index.jsx | 159 ------------------ src/components/Cars/CarUpdates/index.jsx | 159 ------------------ src/components/Cars/StatusModal/index.jsx | 91 ---------- .../Controls/FlashModesList/index.jsx | 34 ---- src/components/Manifest/List/index.jsx | 15 +- src/components/ModalProgressBar/index.jsx | 57 ------- 7 files changed, 6 insertions(+), 527 deletions(-) delete mode 100644 src/components/Cars/CarECUs/index.jsx delete mode 100644 src/components/Cars/CarUpdates/index.jsx delete mode 100644 src/components/Cars/StatusModal/index.jsx delete mode 100644 src/components/Controls/FlashModesList/index.jsx delete mode 100644 src/components/ModalProgressBar/index.jsx diff --git a/src/components/App/__snapshots__/App.test.js.snap b/src/components/App/__snapshots__/App.test.js.snap index d890adc..058e79f 100644 --- a/src/components/App/__snapshots__/App.test.js.snap +++ b/src/components/App/__snapshots__/App.test.js.snap @@ -5374,23 +5374,7 @@ exports[`App Route /packages authenticated 1`] = ` >
- - - -
+ />
diff --git a/src/components/Cars/CarECUs/index.jsx b/src/components/Cars/CarECUs/index.jsx deleted file mode 100644 index 0b6d3b6..0000000 --- a/src/components/Cars/CarECUs/index.jsx +++ /dev/null @@ -1,159 +0,0 @@ -import React, { useEffect, useState } from "react"; -import { - Table, - TableBody, - TableCell, - TableFooter, - TablePagination, - TableRow, -} from "@material-ui/core"; -import clsx from "clsx"; - -import { LocalDateTimeString } from "../../../utils/dates"; -import TableHeaderSortable from "../../Table/HeaderSortable"; -import { useVehicleContext } from "../../Contexts/VehicleContext"; -import { useStatusContext } from "../../Contexts/StatusContext"; -import useStyles from "../../useStyles"; -import { logger } from "../../../services/monitoring"; - -const tableColumns = [ - { - id: "ecu", - label: "ECU", - }, - { - id: "version", - label: "SW Version", - }, - { - id: "hw_version", - label: "HW Version", - }, - { - id: "mode", - label: "Flash Mode", - }, - { - id: "self_download", - label: "Flash Mode", - }, - { - id: "created_at", - label: "Created", - }, - { - id: "updated_at", - label: "Updated", - }, -]; - -const CarECUs = ({ vin, token }) => { - const [ecus, setECUs] = useState([]); - const [total, setTotal] = useState(0); - const classes = useStyles(); - const [pageSize, setPageSize] = useState(10); - const [pageIndex, setPageIndex] = useState(0); - const [orderBy, setOrderBy] = useState("ecu"); - const [order, setOrder] = useState("desc"); - const { getECUs } = useVehicleContext(); - const { setMessage } = useStatusContext(); - - useEffect(() => { - (async () => { - try { - if (!vin || !token) return; - const result = await getECUs( - { - vin, - limit: pageSize, - offset: pageSize * pageIndex, - order: `${orderBy} ${order}`, - }, - token - ); - setECUs(result.data); - if (result.total > -1) setTotal(result.total); - } catch (e) { - setMessage(e.message); - logger.warn(e.stack); - } - })(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [vin, token, pageIndex, pageSize, orderBy, order]); - - 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 ( -
- - - - {ecus.map((row) => ( - - {row.ecu} - {row.version} - {row.hw_version} - {row.mode} - {row.self_download} - - {LocalDateTimeString(row.created)} - - - {LocalDateTimeString(row.updated)} - - - ))} - - - - - - -
-
- ); -}; - -export default CarECUs; diff --git a/src/components/Cars/CarUpdates/index.jsx b/src/components/Cars/CarUpdates/index.jsx deleted file mode 100644 index bc29566..0000000 --- a/src/components/Cars/CarUpdates/index.jsx +++ /dev/null @@ -1,159 +0,0 @@ -import React, { useEffect, useState } from "react"; -import { - Table, - TableBody, - TableCell, - TableFooter, - TablePagination, - TableRow, -} from "@material-ui/core"; - -import { LocalDateTimeString } from "../../../utils/dates"; -import TableHeaderSortable from "../../Table/HeaderSortable"; -import { - UpdatesProvider, - useUpdatesContext, -} from "../../Contexts/UpdatesContext"; -import { useStatusContext } from "../../Contexts/StatusContext"; -import useStyles from "../../useStyles"; -import { logger } from "../../../services/monitoring"; - -const tableColumns = [ - { - id: "id", - label: "ID", - }, - { - id: "update_package_id", - label: "Name", - }, - { - id: "status", - label: "Status", - }, - { - id: "created_at", - label: "Created", - }, - { - id: "updated_at", - label: "Updated", - }, -]; - -const MainForm = ({ vin, token }) => { - const classes = useStyles(); - const [pageSize, setPageSize] = useState(10); - const [pageIndex, setPageIndex] = useState(0); - const [orderBy, setOrderBy] = useState("id"); - const [order, setOrder] = useState("desc"); - const { getCarUpdates, carUpdates, totalCarUpdates } = useUpdatesContext(); - const { setMessage } = useStatusContext(); - - useEffect(() => { - (async () => { - try { - if (!vin || !token) return; - await getCarUpdates( - { - vin, - limit: pageSize, - offset: pageSize * pageIndex, - order: `${orderBy} ${order}`, - }, - token - ); - } catch (e) { - setMessage(e.message); - logger.warn(e.stack); - } - })(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [vin, token, pageIndex, pageSize, orderBy, order]); - - 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); - } - }; - - const updateName = (row) => { - if (row.updatepackage) - return `${row.updatepackage.package_name} ${row.updatepackage.version}`; - if (row.updatemanifest) - return `${row.updatemanifest.name} ${row.updatemanifest.version}`; - return "None"; - }; - - return ( - - - - {carUpdates.map((row) => ( - - {row.id} - {updateName(row)} - {row.status} - - {LocalDateTimeString(row.created)} - - - {LocalDateTimeString(row.updated)} - - - ))} - - - - - - -
- ); -}; - -const CarUpdates = (props) => ( - - - -); - -export default CarUpdates; diff --git a/src/components/Cars/StatusModal/index.jsx b/src/components/Cars/StatusModal/index.jsx deleted file mode 100644 index 43b315f..0000000 --- a/src/components/Cars/StatusModal/index.jsx +++ /dev/null @@ -1,91 +0,0 @@ -import React, { useEffect, useState } from "react"; -import { - Backdrop, - Modal, - Fade, - Table, - TableHead, - TableRow, - TableCell, - TableBody, -} from "@material-ui/core"; - -import useStyles from "../../useStyles"; -import { useUpdatesContext } from "../../Contexts/UpdatesContext"; -import { useUserContext } from "../../Contexts/UserContext"; -import { useStatusContext } from "../../Contexts/StatusContext"; -import { LocalDateTimeString } from "../../../utils/dates"; - -export default function CarStatusModal(props) { - const classes = useStyles(); - const [updates, setUpdates] = useState([]); - const { setMessage } = useStatusContext(); - const { getVINUpdates } = useUpdatesContext(); - const { - token: { - idToken: { jwtToken: token }, - }, - } = useUserContext(); - - useEffect(() => { - (async () => { - try { - if (!props.vin) return; - const result = await getVINUpdates(props.vin, token); - if (result.error) { - throw new Error(`Get VIN updates error. ${result.message}`); - } else { - setUpdates(result.data); - } - } catch (e) { - setMessage(e.message); - } - })(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [props.vin]); - return ( -
- - -
-

{props.vin} Updates

- - - - Date - Update - Status - Updated - - - - {updates.map((update) => ( - - - {LocalDateTimeString(update.created)} - - {`${update.updatepackage.package_name} ${update.updatepackage.version}`} - {update.status} - - {LocalDateTimeString(update.updated)} - - - ))} - -
-
-
-
-
- ); -} diff --git a/src/components/Controls/FlashModesList/index.jsx b/src/components/Controls/FlashModesList/index.jsx deleted file mode 100644 index 1ce3d05..0000000 --- a/src/components/Controls/FlashModesList/index.jsx +++ /dev/null @@ -1,34 +0,0 @@ -import React from "react"; - -import { Select } from "@material-ui/core"; - -const ManifestECUFlashModes = (props) => { - const changeHandler = (e) => { - if (!props.changeHandler) return; - props.changeHandler(e); - }; - - return ( - - ); -}; - -export default ManifestECUFlashModes; - -const FlashModeTypes = [ - ["A", "Mode A"], - ["D", "Mode D"], - ["SELF", "Self"], -]; diff --git a/src/components/Manifest/List/index.jsx b/src/components/Manifest/List/index.jsx index 4e18822..ae69831 100644 --- a/src/components/Manifest/List/index.jsx +++ b/src/components/Manifest/List/index.jsx @@ -10,7 +10,6 @@ import { TableRow, Tooltip, } from "@material-ui/core"; -import AddCircleIcon from "@material-ui/icons/AddCircle"; import SendIcon from "@material-ui/icons/Send"; import VisibilityIcon from "@material-ui/icons/Visibility"; import DeleteIcon from "@material-ui/icons/Delete"; @@ -150,15 +149,15 @@ const MainForm = () => { actions.push({ tip: `Deploy "${row.name} ${row.version}"`, link: `/package-deploy/${row.id}`, - icon: - }) + icon: , + }); } if (hasRole([Roles.DELETE], groups)) { actions.push({ tip: `Delete "${row.name} ${row.version}"`, id: row.id, - icon: - }) + icon: , + }); } if (actions.length === 0) return ["No actions"]; @@ -186,11 +185,7 @@ const MainForm = () => { return (
- - - - - + diff --git a/src/components/ModalProgressBar/index.jsx b/src/components/ModalProgressBar/index.jsx deleted file mode 100644 index 73c2528..0000000 --- a/src/components/ModalProgressBar/index.jsx +++ /dev/null @@ -1,57 +0,0 @@ -import React from "react"; -import Modal from "@material-ui/core/Modal"; - -import { Button, LinearProgress } from "@material-ui/core"; -import { useFileUploadContext } from "../Contexts/FileUploadContext"; - -const getModalStyle = () => { - const top = 30; - const left = 50; - - return { - width: `350px`, - top: `${top}%`, - left: `${left}%`, - transform: `translate(-${left}%, -${top}%)`, - backgroundColor: `white`, - border: `none`, - position: `absolute`, - margin: `1em`, - padding: `1em`, - textAlign: `center`, - }; -}; - -const ModalProgressBar = () => { - const { - uploading, - progress, - status, - linkURL, - cancel, - } = useFileUploadContext(); - - const modalStyle = getModalStyle(); - const onClickCancel = cancel; - - return ( - -
- {status &&

{status}

} - {linkURL && ( -

- - View - -

- )} - - -
-
- ); -}; - -export default ModalProgressBar;