From 05c02dc1aa41134e734b320f73c1d277a74a0658 Mon Sep 17 00:00:00 2001 From: Tristan Timblin Date: Tue, 30 Apr 2024 10:06:55 -0700 Subject: [PATCH] CEC-6016: add trim to fleet (#523) * CEC-6016: add trim to fleet * update snapshot --- .../Controls/CarSelectionTable/index.jsx | 12 +-- .../Controls/ConnectedIcon/index.jsx | 88 +++++++++++---- .../Table/__snapshots__/index.test.jsx.snap | 2 +- .../Fleets/Status/Vehicles/Table/index.jsx | 100 +++++++++--------- .../__snapshots__/VehiclesTab.test.jsx.snap | 2 +- src/components/VehicleTeaser/index.jsx | 72 +++++++++++++ src/hooks/index.js | 2 + src/hooks/useIntersectObserver.js | 21 ++++ 8 files changed, 217 insertions(+), 82 deletions(-) create mode 100644 src/components/VehicleTeaser/index.jsx create mode 100644 src/hooks/useIntersectObserver.js diff --git a/src/components/Controls/CarSelectionTable/index.jsx b/src/components/Controls/CarSelectionTable/index.jsx index 3bc04ce..5104136 100644 --- a/src/components/Controls/CarSelectionTable/index.jsx +++ b/src/components/Controls/CarSelectionTable/index.jsx @@ -1,5 +1,4 @@ import React, { useEffect, useState } from "react"; -import { Link } from "react-router-dom"; import PropTypes from "prop-types"; import { Checkbox, @@ -17,9 +16,9 @@ import { useStatusContext } from "../../Contexts/StatusContext"; import { LocalDateTimeString } from "../../../utils/dates"; import TableHeaderSortable from "../../Table/HeaderSortable"; import { logger } from "../../../services/monitoring"; -import ConnectedIcon from "../../Controls/ConnectedIcon"; import ECUList from "../../Controls/ECUList"; import { useLocalStorage } from "../../useLocalStorage"; +import { VehicleTeaser } from "../../VehicleTeaser"; const tableColumns = [ { @@ -164,12 +163,11 @@ const CarSelectionTable = (props) => { )} - - {row.vin} {row.ecu_list && ( <>
diff --git a/src/components/Controls/ConnectedIcon/index.jsx b/src/components/Controls/ConnectedIcon/index.jsx index 650ee83..dd36383 100644 --- a/src/components/Controls/ConnectedIcon/index.jsx +++ b/src/components/Controls/ConnectedIcon/index.jsx @@ -1,36 +1,78 @@ import React from "react"; import PropTypes from "prop-types"; -import CheckCircleIcon from "@material-ui/icons/CheckCircle"; -import CheckBoxIcon from "@material-ui/icons/CheckBox"; +import DoneAllIcon from "@material-ui/icons/DoneAll"; +import ClearIcon from "@material-ui/icons/Clear"; +import DoneIcon from "@material-ui/icons/Done"; import { Tooltip } from "@material-ui/core"; const ConnectedIcon = (props) => { - if (props.connected || props.connectedHMI) { - return ( - - {props.connected && ( - - - - )} - {props.connectedHMI && ( - - - - )} - - ); - } + let title = tooltip(props.connected, props.connectedHMI); - return null; + const content = () => { + if (props.connected && props.connectedHMI) { + return ( + + + + ); + } + + if (props.connected || props.connectedHMI) { + let color = "blue"; + if (props.connected) { + color = "green" + } + + return ( + + + + ); + } + + return ( + + + + ); + }; + + return ( + + {content()} + + ) }; ConnectedIcon.propTypes = { connected: PropTypes.bool.isRequired, }; +function tooltip(trex, icc) { + const status = []; + + if (trex) { + status.push("TREX"); + } + + if (icc) { + status.push("ICC"); + } + + if (!status.length) { + return "OFFLINE"; + } + + return status.join(" & "); +} + export default ConnectedIcon; diff --git a/src/components/Fleets/Status/Vehicles/Table/__snapshots__/index.test.jsx.snap b/src/components/Fleets/Status/Vehicles/Table/__snapshots__/index.test.jsx.snap index 3dbb472..97ce278 100644 --- a/src/components/Fleets/Status/Vehicles/Table/__snapshots__/index.test.jsx.snap +++ b/src/components/Fleets/Status/Vehicles/Table/__snapshots__/index.test.jsx.snap @@ -191,7 +191,7 @@ exports[`FleetVehiclesTable Render 1`] = ` role="button" tabindex="0" > - VIN + Vehicle
+ Missing VIN +
+ ); + } + + return ( +
+ +
+ ); +} + +export function VehicleTeaser(props) { + const classes = useStyles(); + + return ( +
+ + + {props.vin} + + + {props.trim && } + +
+ ) +} diff --git a/src/hooks/index.js b/src/hooks/index.js index 5fc34e4..d4f0272 100644 --- a/src/hooks/index.js +++ b/src/hooks/index.js @@ -1,2 +1,4 @@ export { useTimeoutState } from "./useTimeoutState"; export { useUpdateManifest } from "./useUpdateManifest"; +export { useIntersectObserver } from "./useIntersectObserver"; + diff --git a/src/hooks/useIntersectObserver.js b/src/hooks/useIntersectObserver.js new file mode 100644 index 0000000..b51972c --- /dev/null +++ b/src/hooks/useIntersectObserver.js @@ -0,0 +1,21 @@ +import { useEffect, useState } from "react"; + +export function useIntersectObserver(element, offset, once) { + const [isInViewport, setIsInViewport] = useState(false); + + useEffect(() => { + const current = element?.current; + const observer = new IntersectionObserver(([entry]) => { + setIsInViewport(entry.isIntersecting); + if (entry.isIntersecting && once) { + observer.unobserve(current); + } + }, { rootMargin: offset }); + + current && observer.observe(current); + + return () => current && observer.unobserve(current); + }, [element, offset, once]); + + return isInViewport; +} \ No newline at end of file