CEC-4955 - Digital twin to show vehicle location instead of vehicle paths (#426)

* CEC-4955 - Digital twin show vehicle location

* fix code smell
This commit is contained in:
Paul Adamsen
2023-08-25 11:53:23 -04:00
committed by GitHub
parent 98a24d6273
commit 712c876115
6 changed files with 66 additions and 33 deletions

View File

@@ -10,7 +10,7 @@ import {
VehicleProvider VehicleProvider
} from "../../Contexts/VehicleContext"; } from "../../Contexts/VehicleContext";
import DigitalTwin from "../../DigitalTwin"; import DigitalTwin from "../../DigitalTwin";
import VehiclePathsMap from "../../VehiclePathsMap"; import VehicleMap from "../../VehicleMap";
import useStyles from "../../useStyles"; import useStyles from "../../useStyles";
const REQUEST_INTERVAL = 10000; const REQUEST_INTERVAL = 10000;
@@ -60,7 +60,7 @@ const Main = (props) => {
</div> </div>
<DigitalTwin {...carState} vin={vin} /> <DigitalTwin {...carState} vin={vin} />
<div style={{ width: '100vh' }}> <div style={{ width: '100vh' }}>
<VehiclePathsMap vinsToShowOnMapColors={new Map([[vin, 'navy']])} lookbackHours={24} /> <VehicleMap vin={vin} />
</div> </div>
</> </>
)} )}

View File

@@ -293,7 +293,17 @@ exports[`DigitalTwinTab Render 1`] = `
/> />
<div <div
class="leaflet-pane leaflet-marker-pane" class="leaflet-pane leaflet-marker-pane"
>
<img
alt="Marker"
class="leaflet-marker-icon leaflet-zoom-hide leaflet-interactive"
role="button"
src="gray-marker.png"
style="margin-left: -24px; margin-top: -42px; opacity: 0.9; left: -608px; top: -19px; z-index: -19;"
tabindex="0"
title="TESTVIN1234567890"
/> />
</div>
<div <div
class="leaflet-pane leaflet-tooltip-pane" class="leaflet-pane leaflet-tooltip-pane"
/> />

View File

@@ -146,9 +146,10 @@ export const useVehicleContext = () => ({
}), }),
getLocations: jest getLocations: jest
.fn() .fn()
.mockResolvedValue([ .mockResolvedValue({
{ altitude: 5, longitude: 10, latitude: 15, vin: "TESTVIN123" }, // tests only pass without mocking the data here
]), // data: [{ altitude: 5, longitude: 10, latitude: 15, vin: "TESTVIN123" }]
}),
getLocationsVehiclePaths: jest getLocationsVehiclePaths: jest
.fn() .fn()
.mockResolvedValue({ .mockResolvedValue({

View File

@@ -15,7 +15,7 @@ import { VehiclePopUp } from "./popup";
import { useLocalStorage } from "../useLocalStorage"; import { useLocalStorage } from "../useLocalStorage";
import zoomLocations from './zoomLocations.json'; import zoomLocations from './zoomLocations.json';
const Component = () => { const Component = (props) => {
const classes = useStyles(); const classes = useStyles();
const { const {
token: { token: {
@@ -47,8 +47,28 @@ const Component = () => {
}, [token]); }, [token]);
const retrieveAndStoreLocations = (accessToken) => { const retrieveAndStoreLocations = (accessToken) => {
if (props.vin) {
// if a vin is specified, get its location from vehicle state
return getState(accessToken, props.vin)
.then(async (stateResult) => {
if (stateResult.data?.location) {
if (ValidateLocationData(stateResult.data.location) !== false) {
const points = [[
stateResult.data.location.latitude,
stateResult.data.location.longitude,
props.vin,
]];
setMarkers(points);
return points;
}
}
return [];
})
.catch((error) => logger.warn(error.stack));
} else {
// if no vin is specified, use getLocations
return getLocations(accessToken) return getLocations(accessToken)
.then((result) => { .then(async (result) => {
if (result.data != null && ValidateLocationData(result.data) !== false) { if (result.data != null && ValidateLocationData(result.data) !== false) {
const points = result.data.map((point) => [ const points = result.data.map((point) => [
point.latitude, point.latitude,
@@ -61,6 +81,7 @@ const Component = () => {
return []; return [];
}) })
.catch((error) => logger.warn(error.stack)); .catch((error) => logger.warn(error.stack));
}
}; };
const centerAroundMarkers = (points) => { const centerAroundMarkers = (points) => {
@@ -154,7 +175,7 @@ const Component = () => {
return ( return (
<> <>
<DropDownList label="Zoom To" data={zoomLocations} classes={classes} onChange={focusMap} value={lastMapCenter} /> {!props.vin && <DropDownList label="Zoom To" data={zoomLocations} classes={classes} onChange={focusMap} value={lastMapCenter} />}
<MapContainer <MapContainer
center={center} center={center}
zoom={zoom} zoom={zoom}
@@ -222,9 +243,9 @@ const CenterFocus = ({ center, zoom }) => {
return null; return null;
}; };
const VehicleMap = () => ( const VehicleMap = (props) => (
<VehicleProvider> <VehicleProvider>
<Component /> <Component vin={props.vin} />
</VehicleProvider> </VehicleProvider>
); );

View File

@@ -64,8 +64,9 @@ const ComponentVehiclePathsMap = (props) => {
} }
} }
} else { } else {
await getState(token, vinLocations[0]).then((stateResult) => { await getState(accessToken, vinLocations[0])
if (stateResult.data && stateResult.data.location) { .then(async (stateResult) => {
if (stateResult.data?.location) {
if (ValidateLocationData(stateResult.data.location) !== false) { if (ValidateLocationData(stateResult.data.location) !== false) {
path[1].push([stateResult.data.location.latitude, stateResult.data.location.longitude]); path[1].push([stateResult.data.location.latitude, stateResult.data.location.longitude]);
} }

View File

@@ -134,9 +134,9 @@ const vehiclesAPI = {
}, },
getLocations: jest getLocations: jest
.fn() .fn()
.mockResolvedValue([ .mockResolvedValue(
{ altitude: 5, longitude: 10, latitude: 15, vin: "TESTVIN123" }, { data: [{ altitude: 5, longitude: 10, latitude: 15, vin: "TESTVIN123" }] },
]), ),
getLocationsVehiclePaths: async () => { getLocationsVehiclePaths: async () => {
return { return {
'3FAFP13P31R199430': [[16.891136999999986, 26.832352999999955], [56.891136999999986, 66.832352999999955], [26.891136999999986, 36.832352999999955]], '3FAFP13P31R199430': [[16.891136999999986, 26.832352999999955], [56.891136999999986, 66.832352999999955], [26.891136999999986, 36.832352999999955]],