Merge branch 'main' into CEC-6008
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { Link } from "react-router-dom";
|
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import {
|
import {
|
||||||
Checkbox,
|
Checkbox,
|
||||||
@@ -17,9 +16,9 @@ import { useStatusContext } from "../../Contexts/StatusContext";
|
|||||||
import { LocalDateTimeString } from "../../../utils/dates";
|
import { LocalDateTimeString } from "../../../utils/dates";
|
||||||
import TableHeaderSortable from "../../Table/HeaderSortable";
|
import TableHeaderSortable from "../../Table/HeaderSortable";
|
||||||
import { logger } from "../../../services/monitoring";
|
import { logger } from "../../../services/monitoring";
|
||||||
import ConnectedIcon from "../../Controls/ConnectedIcon";
|
|
||||||
import ECUList from "../../Controls/ECUList";
|
import ECUList from "../../Controls/ECUList";
|
||||||
import { useLocalStorage } from "../../useLocalStorage";
|
import { useLocalStorage } from "../../useLocalStorage";
|
||||||
|
import { VehicleTeaser } from "../../VehicleTeaser";
|
||||||
|
|
||||||
const tableColumns = [
|
const tableColumns = [
|
||||||
{
|
{
|
||||||
@@ -164,12 +163,11 @@ const CarSelectionTable = (props) => {
|
|||||||
</TableCell>
|
</TableCell>
|
||||||
)}
|
)}
|
||||||
<TableCell align="center">
|
<TableCell align="center">
|
||||||
<ConnectedIcon
|
<VehicleTeaser
|
||||||
connected={row.connected}
|
vin={row.vin}
|
||||||
connectedHMI={row.connectedHMI}
|
trex={row.connected}
|
||||||
style={{ marginRight: 3 }}
|
icc={row.connectedHMI}
|
||||||
/>
|
/>
|
||||||
<Link to={`/vehicle-status/${row.vin}`}>{row.vin}</Link>
|
|
||||||
{row.ecu_list && (
|
{row.ecu_list && (
|
||||||
<>
|
<>
|
||||||
<br />
|
<br />
|
||||||
|
|||||||
@@ -1,36 +1,78 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import CheckCircleIcon from "@material-ui/icons/CheckCircle";
|
import DoneAllIcon from "@material-ui/icons/DoneAll";
|
||||||
import CheckBoxIcon from "@material-ui/icons/CheckBox";
|
import ClearIcon from "@material-ui/icons/Clear";
|
||||||
|
import DoneIcon from "@material-ui/icons/Done";
|
||||||
import { Tooltip } from "@material-ui/core";
|
import { Tooltip } from "@material-ui/core";
|
||||||
|
|
||||||
const ConnectedIcon = (props) => {
|
const ConnectedIcon = (props) => {
|
||||||
if (props.connected || props.connectedHMI) {
|
let title = tooltip(props.connected, props.connectedHMI);
|
||||||
|
|
||||||
|
const content = () => {
|
||||||
|
if (props.connected && props.connectedHMI) {
|
||||||
return (
|
return (
|
||||||
<span style={props.style}>
|
<Tooltip title={title}>
|
||||||
{props.connected && (
|
<DoneAllIcon
|
||||||
<Tooltip title="TBOX">
|
fontSize="small"
|
||||||
<CheckCircleIcon
|
style={{ color: "green" }}
|
||||||
style={{ color: "Green", fontSize: 12, marginRight: 3 }}
|
|
||||||
/>
|
/>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
|
||||||
{props.connectedHMI && (
|
|
||||||
<Tooltip title="ICC">
|
|
||||||
<CheckBoxIcon
|
|
||||||
style={{ color: "Blue", fontSize: 12, marginRight: 3 }}
|
|
||||||
/>
|
|
||||||
</Tooltip>
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
if (props.connected || props.connectedHMI) {
|
||||||
|
let color = "blue";
|
||||||
|
if (props.connected) {
|
||||||
|
color = "green"
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tooltip title={title}>
|
||||||
|
<DoneIcon
|
||||||
|
fontSize="small"
|
||||||
|
style={{ color }}
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tooltip title={title}>
|
||||||
|
<ClearIcon
|
||||||
|
fontSize="small"
|
||||||
|
style={{ color: "red" }}
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<span style={props.style}>
|
||||||
|
{content()}
|
||||||
|
</span>
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
ConnectedIcon.propTypes = {
|
ConnectedIcon.propTypes = {
|
||||||
connected: PropTypes.bool.isRequired,
|
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;
|
export default ConnectedIcon;
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ exports[`FleetVehiclesTable Render 1`] = `
|
|||||||
role="button"
|
role="button"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
>
|
>
|
||||||
VIN
|
Vehicle
|
||||||
<svg
|
<svg
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
class="MuiSvgIcon-root MuiTableSortLabel-icon MuiTableSortLabel-iconDirectionAsc"
|
class="MuiSvgIcon-root MuiTableSortLabel-icon MuiTableSortLabel-iconDirectionAsc"
|
||||||
|
|||||||
@@ -23,18 +23,19 @@ import {
|
|||||||
} from "../../../../Contexts/FleetContext";
|
} from "../../../../Contexts/FleetContext";
|
||||||
import { useStatusContext } from "../../../../Contexts/StatusContext";
|
import { useStatusContext } from "../../../../Contexts/StatusContext";
|
||||||
import { useUserContext } from "../../../../Contexts/UserContext";
|
import { useUserContext } from "../../../../Contexts/UserContext";
|
||||||
|
import { VehicleProvider } from "../../../../Contexts/VehicleContext";
|
||||||
import SearchField from "../../../../Controls/SearchField";
|
import SearchField from "../../../../Controls/SearchField";
|
||||||
import TableHeaderSortable from "../../../../Table/HeaderSortable";
|
import TableHeaderSortable from "../../../../Table/HeaderSortable";
|
||||||
import { useLocalStorage } from "../../../../useLocalStorage";
|
import { useLocalStorage } from "../../../../useLocalStorage";
|
||||||
import ConnectedIcon from "../../../../Controls/ConnectedIcon";
|
|
||||||
import BulkActions from "../../../../BulkActions";
|
import BulkActions from "../../../../BulkActions";
|
||||||
import Battery from "../../../../Battery";
|
import Battery from "../../../../Battery";
|
||||||
|
import { VehicleTeaserController as VehicleTeaser } from "../../../../VehicleTeaser";
|
||||||
import useStyles from "../../../../useStyles";
|
import useStyles from "../../../../useStyles";
|
||||||
|
|
||||||
const tableColumns = [
|
const tableColumns = [
|
||||||
{
|
{
|
||||||
id: "vin",
|
id: "vehicle",
|
||||||
label: "VIN",
|
label: "Vehicle",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "trex_version",
|
id: "trex_version",
|
||||||
@@ -213,6 +214,7 @@ const MainForm = ({ name }) => {
|
|||||||
selectCount={selected.length}
|
selectCount={selected.length}
|
||||||
rowCount={fleetVehicles.length}
|
rowCount={fleetVehicles.length}
|
||||||
/>
|
/>
|
||||||
|
<VehicleProvider>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{fleetVehicles && fleetVehicles.map((car) => {
|
{fleetVehicles && fleetVehicles.map((car) => {
|
||||||
const isSelected = selected.includes(car.vin);
|
const isSelected = selected.includes(car.vin);
|
||||||
@@ -224,15 +226,12 @@ const MainForm = ({ name }) => {
|
|||||||
/>
|
/>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell key={"cell" + car.vin} align="center">
|
<TableCell key={"cell" + car.vin} align="center">
|
||||||
{(car.connected || car.connectedHMI) &&
|
<VehicleTeaser
|
||||||
<ConnectedIcon
|
vin={car.vin}
|
||||||
key={"icon" + car.vin}
|
icc={car.connectedHMI}
|
||||||
connected={car.connected}
|
trex={car.connected}
|
||||||
connectedHMI={car.connectedHMI}
|
token={token}
|
||||||
style={{ marginRight: 3 }}
|
|
||||||
/>
|
/>
|
||||||
}
|
|
||||||
<Link key={"link" + car.vin} to={`/vehicle-status/${car.vin}`}>{car.vin}</Link>
|
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell key={"cell2" + car.vin} align="center">{car.trex_version}</TableCell>
|
<TableCell key={"cell2" + car.vin} align="center">{car.trex_version}</TableCell>
|
||||||
<TableCell key={"cell3" + car.car_update_name}>
|
<TableCell key={"cell3" + car.car_update_name}>
|
||||||
@@ -261,6 +260,7 @@ const MainForm = ({ name }) => {
|
|||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
|
</VehicleProvider>
|
||||||
<TableFooter>
|
<TableFooter>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TablePagination
|
<TablePagination
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ exports[`VehiclesTab Render 1`] = `
|
|||||||
role="button"
|
role="button"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
>
|
>
|
||||||
VIN
|
Vehicle
|
||||||
<svg
|
<svg
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
class="MuiSvgIcon-root MuiTableSortLabel-icon MuiTableSortLabel-iconDirectionAsc"
|
class="MuiSvgIcon-root MuiTableSortLabel-icon MuiTableSortLabel-iconDirectionAsc"
|
||||||
|
|||||||
72
src/components/VehicleTeaser/index.jsx
Normal file
72
src/components/VehicleTeaser/index.jsx
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
import { useRef, useState, useEffect } from "react";
|
||||||
|
import { Link } from "react-router-dom";
|
||||||
|
import Chip from '@mui/material/Chip';
|
||||||
|
import Stack from '@mui/material/Stack';
|
||||||
|
import ConnectedIcon from "../Controls/ConnectedIcon";
|
||||||
|
import { useVehicleContext } from "../Contexts/VehicleContext";
|
||||||
|
import useStyles from "../useStyles";
|
||||||
|
import { useIntersectObserver } from "../../hooks";
|
||||||
|
|
||||||
|
// Prevent fetching missing data by not including `token` prop
|
||||||
|
|
||||||
|
export function VehicleTeaserController(props) {
|
||||||
|
const el = useRef(null);
|
||||||
|
const isVisible = useIntersectObserver(el, "0px", true);
|
||||||
|
const [isMissingData, setIsMissingData] = useState(false);
|
||||||
|
|
||||||
|
const { getVehicle, vehicle } = useVehicleContext();
|
||||||
|
|
||||||
|
const classes = useStyles();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (props.trim === undefined) {
|
||||||
|
setIsMissingData(true);
|
||||||
|
}
|
||||||
|
}, [isVisible, props.trim]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isVisible && props.token) {
|
||||||
|
getVehicle(props.vin, props.token)
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [isMissingData, isVisible, props.vin, props.token]);
|
||||||
|
|
||||||
|
if (!props.vin) {
|
||||||
|
return (
|
||||||
|
<div className={classes.alignBaseline}>
|
||||||
|
Missing VIN
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div ref={el}>
|
||||||
|
<VehicleTeaser
|
||||||
|
vin={props.vin}
|
||||||
|
trex={props.trex}
|
||||||
|
icc={props.icc}
|
||||||
|
trim={props.trim || vehicle.trim}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function VehicleTeaser(props) {
|
||||||
|
const classes = useStyles();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={classes.alignBaseline}>
|
||||||
|
<ConnectedIcon
|
||||||
|
connected={props.trex}
|
||||||
|
connectedHMI={props.icc}
|
||||||
|
style={{ display: "flex", marginRight: 3 }}
|
||||||
|
/>
|
||||||
|
<Link to={`/vehicle-status/${props.vin}`}>
|
||||||
|
{props.vin}
|
||||||
|
</Link>
|
||||||
|
<Stack direction="row" spacing={1} style={{ marginLeft: 3 }}>
|
||||||
|
{props.trim && <Chip label={props.trim} size="small" />}
|
||||||
|
</Stack>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,2 +1,4 @@
|
|||||||
export { useTimeoutState } from "./useTimeoutState";
|
export { useTimeoutState } from "./useTimeoutState";
|
||||||
export { useUpdateManifest } from "./useUpdateManifest";
|
export { useUpdateManifest } from "./useUpdateManifest";
|
||||||
|
export { useIntersectObserver } from "./useIntersectObserver";
|
||||||
|
|
||||||
|
|||||||
21
src/hooks/useIntersectObserver.js
Normal file
21
src/hooks/useIntersectObserver.js
Normal file
@@ -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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user