Merge branch 'release/0.9.0'

This commit is contained in:
jwu-fisker
2023-05-25 16:50:16 -07:00
18 changed files with 667 additions and 1701 deletions

2096
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -6,13 +6,14 @@
"@datadog/browser-logs": "^3.11.0", "@datadog/browser-logs": "^3.11.0",
"@date-io/date-fns": "1.x", "@date-io/date-fns": "1.x",
"@date-io/moment": "1.x", "@date-io/moment": "1.x",
"@emotion/react": "^11.9.0", "@emotion/react": "^11.11.0",
"@emotion/styled": "^11.8.1", "@emotion/styled": "^11.11.0",
"@material-ui/core": "^4.12.4", "@material-ui/core": "^4.12.4",
"@material-ui/icons": "^4.11.3", "@material-ui/icons": "^4.11.3",
"@material-ui/lab": "^4.0.0-alpha.61", "@material-ui/lab": "^4.0.0-alpha.61",
"@material-ui/pickers": "^3.3.10", "@material-ui/pickers": "^3.3.10",
"@mui/material": "^5.10.14", "@mui/icons-material": "^5.11.16",
"@mui/material": "^5.13.1",
"@superset-ui/embedded-sdk": "^0.1.0-alpha.8", "@superset-ui/embedded-sdk": "^0.1.0-alpha.8",
"@testing-library/jest-dom": "^5.16.4", "@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^12.1.4", "@testing-library/react": "^12.1.4",
@@ -83,7 +84,7 @@
"coverageThreshold": { "coverageThreshold": {
"global": { "global": {
"branches": 39, "branches": 39,
"functions": 47, "functions": 46,
"lines": 55, "lines": 55,
"statements": 55 "statements": 55
} }

View File

@@ -11428,9 +11428,28 @@ exports[`App Route /vehicle-status authenticated 1`] = `
/> />
</svg> </svg>
</a> </a>
<a
class=""
href="/vehicle-status/FISKER123"
title="Push Config \\"FISKER123\\""
>
<svg
aria-hidden="true"
aria-label="Push Config \\"FISKER123\\""
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-i4bv87-MuiSvgIcon-root"
data-testid="UploadIcon"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M5 20h14v-2H5v2zm0-10h4v6h6v-6h4l-7-7-7 7z"
/>
</svg>
</a>
</div> </div>
</div> </div>
<div /> <div />
<div />
</div> </div>
</div> </div>
</div> </div>

View File

@@ -16,7 +16,7 @@ const MainForm = ({ id }) => {
const [selectedStartDate, setSelectedStartDate] = useState(new Date(Date.now() - 24 * 60 * 60 * 1000)); const [selectedStartDate, setSelectedStartDate] = useState(new Date(Date.now() - 24 * 60 * 60 * 1000));
const [selectedEndDate, setSelectedEndDate] = useState(new Date()); const [selectedEndDate, setSelectedEndDate] = useState(new Date());
const [selectedCanSignals, setSelectedCanSignals] = useState([]); const [selectedCanSignals, setSelectedCanSignals] = useState([]);
const [selectAllCanSignals, setSelectAllCanSignals] = useState(false);
const { const {
token: { token: {
@@ -29,8 +29,8 @@ const MainForm = ({ id }) => {
let timestamp_start = Date.parse(selectedStartDate.toUTCString()) / 1000 let timestamp_start = Date.parse(selectedStartDate.toUTCString()) / 1000
let timestamp_end = Date.parse(selectedEndDate.toUTCString()) / 1000 let timestamp_end = Date.parse(selectedEndDate.toUTCString()) / 1000
try { try {
await getDynamicColumnCANSignals(id, timestamp_start, timestamp_end, selectedCanSignals, token) await getDynamicColumnCANSignals(id, timestamp_start, timestamp_end, selectedCanSignals, selectAllCanSignals, token)
} catch(e){ } catch (e) {
setMessage(e.message); setMessage(e.message);
logger.error(e.stack) logger.error(e.stack)
} }
@@ -74,12 +74,14 @@ const MainForm = ({ id }) => {
const handleSelectedItemsChange = (event) => { const handleSelectedItemsChange = (event) => {
const { value } = event.target; const { value } = event.target;
if (value.some(item => item === "Select All")) { if (value.some(item => item === "Select All")) {
setSelectAllCanSignals(true);
if (selectedCanSignals.length === canSignals.length) { if (selectedCanSignals.length === canSignals.length) {
setSelectedCanSignals([]); setSelectedCanSignals([]);
} else { } else {
setSelectedCanSignals(canSignals.map(signal => signal.signal_name)); setSelectedCanSignals(canSignals.map(signal => signal.signal_name));
} }
} else { } else {
setSelectAllCanSignals(false);
setSelectedCanSignals(value); setSelectedCanSignals(value);
} }
}; };

View File

@@ -168,9 +168,28 @@ exports[`VehicleDetailsTab Render 1`] = `
/> />
</svg> </svg>
</a> </a>
<a
class=""
href="/"
title="Push Config \\"TESTVIN1234567890\\""
>
<svg
aria-hidden="true"
aria-label="Push Config \\"TESTVIN1234567890\\""
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-i4bv87-MuiSvgIcon-root"
data-testid="UploadIcon"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M5 20h14v-2H5v2zm0-10h4v6h6v-6h4l-7-7-7 7z"
/>
</svg>
</a>
</div> </div>
</div> </div>
<div /> <div />
<div />
</div> </div>
</div> </div>
</div> </div>

View File

@@ -1,6 +1,7 @@
import { Grid, Tooltip } from "@material-ui/core"; import { Grid, Tooltip } from "@material-ui/core";
import DeleteIcon from "@material-ui/icons/Delete"; import DeleteIcon from "@material-ui/icons/Delete";
import EditIcon from "@material-ui/icons/Edit"; import EditIcon from "@material-ui/icons/Edit";
import UploadIcon from '@mui/icons-material/Upload';
import clsx from "clsx"; import clsx from "clsx";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { Redirect } from "react-router"; import { Redirect } from "react-router";
@@ -16,14 +17,16 @@ import {
} from "../../../Contexts/VehicleContext"; } from "../../../Contexts/VehicleContext";
import { RoleWrap } from "../../../Controls/RoleWrap"; import { RoleWrap } from "../../../Controls/RoleWrap";
import DeleteConfirmation from "../../../DeleteConfirmation"; import DeleteConfirmation from "../../../DeleteConfirmation";
import GeneralConfirmation from "../../../GeneralConfirmation";
import useStyles from "../../../useStyles"; import useStyles from "../../../useStyles";
const MainForm = ({ vin }) => { const MainForm = ({ vin }) => {
const classes = useStyles(); const classes = useStyles();
const { setMessage } = useStatusContext(); const { setMessage } = useStatusContext();
const { vehicle, getVehicle, deleteVehicle } = useVehicleContext(); const { vehicle, getVehicle, deleteVehicle, uploadConfig } = useVehicleContext();
const [redirect, setRedirect] = useState(null); const [redirect, setRedirect] = useState(null);
const [showDeleteModal, setShowDeleteModal] = useState(false); const [showDeleteModal, setShowDeleteModal] = useState(false);
const [showUploadConfigModal, setShowUploadConfigModal] = useState(false);
const { const {
token: { token: {
idToken: { jwtToken: token }, idToken: { jwtToken: token },
@@ -59,6 +62,16 @@ const MainForm = ({ vin }) => {
} }
}; };
const onUploadConfig = async () => {
try {
await uploadConfig(vin, token);
setMessage(`Config Uploaded ${vin}`);
} catch (e) {
setMessage(e.message);
logger.warn(e.stack);
}
}
if (redirect && redirect.length > 0) { if (redirect && redirect.length > 0) {
return <Redirect to={redirect} />; return <Redirect to={redirect} />;
} }
@@ -142,6 +155,18 @@ const MainForm = ({ vin }) => {
</Link> </Link>
</Tooltip> </Tooltip>
</RoleWrap> </RoleWrap>
<RoleWrap
groups={groups}
providers={providers}
rolesPerProvider={Permissions.FiskerCreate}
>
<Tooltip key={`push-config-${vin}`} title={`Push Config "${vin}"`}>
<Link to="#" onClick={() => setShowUploadConfigModal(true)}>
<UploadIcon aria-label={`Push Config "${vin}"`} />
</Link>
</Tooltip>
</RoleWrap>
<RoleWrap <RoleWrap
groups={groups} groups={groups}
providers={providers} providers={providers}
@@ -161,6 +186,13 @@ const MainForm = ({ vin }) => {
close={() => setShowDeleteModal(false)} close={() => setShowDeleteModal(false)}
deleteFunction={onDelete} deleteFunction={onDelete}
/> />
<GeneralConfirmation
message={"push config update to:" + vin}
open={showUploadConfigModal}
close={() => setShowUploadConfigModal(false)}
actionFunction={onUploadConfig}
title="Send Update"
/>
</div> </div>
); );
}; };

View File

@@ -176,9 +176,28 @@ exports[`DetailsTab Render 1`] = `
/> />
</svg> </svg>
</a> </a>
<a
class=""
href="/testroute/TESTVIN1234567890"
title="Push Config \\"TESTVIN1234567890\\""
>
<svg
aria-hidden="true"
aria-label="Push Config \\"TESTVIN1234567890\\""
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-i4bv87-MuiSvgIcon-root"
data-testid="UploadIcon"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M5 20h14v-2H5v2zm0-10h4v6h6v-6h4l-7-7-7 7z"
/>
</svg>
</a>
</div> </div>
</div> </div>
<div /> <div />
<div />
</div> </div>
</div> </div>
</div> </div>

View File

@@ -357,9 +357,28 @@ exports[`CarStatus Render 1`] = `
/> />
</svg> </svg>
</a> </a>
<a
class=""
href="/"
title="Push Config \\"TESTVIN1234567890\\""
>
<svg
aria-hidden="true"
aria-label="Push Config \\"TESTVIN1234567890\\""
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-i4bv87-MuiSvgIcon-root"
data-testid="UploadIcon"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M5 20h14v-2H5v2zm0-10h4v6h6v-6h4l-7-7-7 7z"
/>
</svg>
</a>
</div> </div>
</div> </div>
<div /> <div />
<div />
</div> </div>
</div> </div>
</div> </div>

View File

@@ -23,14 +23,20 @@ export const CANSignalsExportProvider = ({ children }) => {
} }
}; };
const getDynamicColumnCANSignals = async (vin, timestart, timeend, cansingals, token) => { const getDynamicColumnCANSignals = async (vin, timestart, timeend, cansignals, selectall, token) => {
try { try {
setBusy(true) setBusy(true)
if (!vin) return; if (!vin) return;
validateVIN(vin); validateVIN(vin);
if (timestart > timeend) throw new Error("Start time cannot be after end time"); if (timestart > timeend) throw new Error("Start time cannot be after end time");
const result = await api.getCanSignalsVin(vin, timestart, timeend, cansingals, token);
let result
if (selectall === true) {
result = await api.getCanSignalsVin(vin, timestart, timeend, [], selectall, token);
} else {
result = await api.getCanSignalsVin(vin, timestart, timeend, cansignals, false, token);
}
if (result.error || !result.ok) if (result.error || !result.ok)
throw new Error(`Get CAN signals error. ${result.message}`); throw new Error(`Get CAN signals error. ${result.message}`);

View File

@@ -200,6 +200,20 @@ export const VehicleProvider = ({ children }) => {
} }
}; };
const uploadConfig = async (vin, token) => {
try {
setBusy(true);
validateVIN(vin);
const result = await api.updateConfig(vin, token);
if (result.error)
throw new Error(`Update vehicle error. ${result.message}`);
return result;
} finally {
setBusy(false);
}
}
const deleteVehicle = async (vin, token) => { const deleteVehicle = async (vin, token) => {
try { try {
setBusy(true); setBusy(true);
@@ -285,6 +299,7 @@ export const VehicleProvider = ({ children }) => {
updateVehicle, updateVehicle,
getFleets, getFleets,
getVersionLog, getVersionLog,
uploadConfig
}} }}
> >
{children} {children}

View File

@@ -30,6 +30,7 @@ const Statuses = {
ManifestRollback: "manifest_rollback", ManifestRollback: "manifest_rollback",
ManifestSucceeded: "manifest_succeeded", ManifestSucceeded: "manifest_succeeded",
ManifesCanceled: "manifest_canceled", ManifesCanceled: "manifest_canceled",
ManifestCancelPending: "manifest_cancel_pending",
PackageDownloadStarted: "package_download_start", PackageDownloadStarted: "package_download_start",
PackageDownloadCompleted: "package_download_complete", PackageDownloadCompleted: "package_download_complete",
PackageInstallStarted: "package_install_start", PackageInstallStarted: "package_install_start",

View File

@@ -18,9 +18,9 @@ const PHASES = [
}, },
{ {
label: "Received", label: "Received",
events: [s.ManifestAccepted, s.ManifestReceived, s.ManifestRejected], events: [s.ManifestAccepted, s.ManifestReceived, s.ManifestRejected, s.ManifestError],
progress: (msg) => { progress: (msg) => {
if (msg === s.ManifestRejected) return ErrorStatus; if (msg === s.ManifestRejected || msg === s.ManifestError) return ErrorStatus;
return CompleteStatus; return CompleteStatus;
}, },
}, },
@@ -67,8 +67,11 @@ const PHASES = [
}, },
{ {
label: "Updated", label: "Updated",
events: [s.ManifestSucceeded], events: [s.ManifestSucceeded, s.CleanupFailed, s.CleanupSucceeded, s.RollbackSucceeded, s.RollbackFailed],
progress: (_msg, _progress) => CompleteStatus, progress: (msg, _progress) => {
if (msg === s.ManifestSucceeded) return CompleteStatus;
return ErrorStatus;
}
}, },
]; ];

View File

@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`General Confirmation Modal Should render 1`] = `
<div
aria-hidden="true"
>
<div />
</div>
`;

View File

@@ -0,0 +1,37 @@
import React from "react";
import PropTypes from "prop-types";
import {Dialog, DialogTitle, DialogContentText, Button, DialogActions, DialogContent} from '@material-ui/core';
const GeneralConfirmation = (props) => {
return (
<div>
<Dialog open={props.open}
onClose={props.close}>
<DialogTitle id="alert-dialog-title">
{props.title}
</DialogTitle>
<DialogContent>
<DialogContentText id="alert-dialog-description">
{"Are you sure you want to : " + props.message}
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={props.close}>Cancel</Button>
<Button variant="contained" color="secondary" onClick={() => { props.close(); props.actionFunction()}} autoFocus>
Go
</Button>
</DialogActions>
</Dialog>
</div>
)
}
GeneralConfirmation.propTypes={
open: PropTypes.bool.isRequired, // Boolean that determines if the modal should be open
close: PropTypes.func.isRequired, // Function that sets the open state to false i.e. () => setOpen(false)
message: PropTypes.any.isRequired, // What the user will see if being confirmed for the function to run
actionFunction: PropTypes.func.isRequired, // Function that runs when user clicks Go
title: PropTypes.any.isRequired, // The title of the modal that is opened
}
export default GeneralConfirmation;

View File

@@ -0,0 +1,20 @@
jest.mock("../Contexts/UserContext");
import React from "react";
import { render, cleanup } from "@testing-library/react";
import GeneralConfirmation from "./index";
import addSnapshotSerializer from "../../utils/snapshot";
describe("General Confirmation Modal", () => {
beforeAll(() => {
addSnapshotSerializer(expect);
});
it("Should render", () => {
const { container } = render(
<GeneralConfirmation open={true} close={()=>{}} message="Test Message" title="hello" actionFunction={()=>{}}/>
);
expect(container).toMatchSnapshot();
cleanup();
});
});

View File

@@ -6,8 +6,8 @@ const API_ENDPOINT = process.env.REACT_APP_OTA_SERVICE_URL;
const canSignalAPI = { const canSignalAPI = {
getCanSignalsVin: async (vin, timestamp_start, timestamp_end, can_signals, token) => getCanSignalsVin: async (vin, timestamp_start, timestamp_end, can_signals, select_all, token) =>
fetch(addQueryParams(`${API_ENDPOINT}/can_signals_export`, { vin, timestamp_start, timestamp_end, can_signals }), { fetch(addQueryParams(`${API_ENDPOINT}/can_signals_export`, { vin, timestamp_start, timestamp_end, can_signals, select_all }), {
method: "GET", method: "GET",
headers: Object.assign( headers: Object.assign(
{ "Content-Type": "application/json" }, { "Content-Type": "application/json" },
@@ -17,7 +17,6 @@ const canSignalAPI = {
}) })
.catch(errorHandler), .catch(errorHandler),
getCanSignalList: async (token) => getCanSignalList: async (token) =>
fetch(addQueryParams(`${API_ENDPOINT}/can_signals_list`), { fetch(addQueryParams(`${API_ENDPOINT}/can_signals_list`), {
method: "GET", method: "GET",

View File

@@ -1,11 +1,11 @@
const canSignalList = [ const canSignalList = [
{ signal_name: "123"}, { signal_name: "123" },
{ signal_name: "456"}, { signal_name: "456" },
{ signal_name: "789"} { signal_name: "789" }
]; ];
const canSignalAPI = { const canSignalAPI = {
getCanSignalsVin: async (vin, timestamp_start, timestamp_end, can_signals, token) => { getCanSignalsVin: async (vin, timestamp_start, timestamp_end, can_signals, select_all, token) => {
return { data: "fake data" }; return { data: "fake data" };
}, },
getCanSignalList: async (token) => { getCanSignalList: async (token) => {

View File

@@ -173,6 +173,17 @@ const vehiclesAPI = {
.then(fetchRespHandler) .then(fetchRespHandler)
.catch(errorHandler), .catch(errorHandler),
updateConfig: async (vin, token) =>
fetch(`${API_ENDPOINT}/car_config/${vin}`, {
method: "POST",
headers: Object.assign(
{ "Content-Type": "application/json" },
getAuthHeaderOptions(token)
)
})
.then(fetchRespHandler)
.catch(errorHandler),
getCANSignals: async (vin, token) => getCANSignals: async (vin, token) =>
fetch(`${API_ENDPOINT}/cansignals/${vin}`, { fetch(`${API_ENDPOINT}/cansignals/${vin}`, {
method: "GET", method: "GET",
@@ -209,7 +220,7 @@ const vehiclesAPI = {
.catch(errorHandler) .catch(errorHandler)
}, },
getLogFileLink: async ({vin, year, month, day}, token) => { getLogFileLink: async ({ vin, year, month, day }, token) => {
const u = `${API_ENDPOINT}/vehicle/${vin}/trex-logs-link?year=${year}&month=${month}&day=${day}` const u = `${API_ENDPOINT}/vehicle/${vin}/trex-logs-link?year=${year}&month=${month}&day=${day}`
return fetch(u, { return fetch(u, {
method: "GET", method: "GET",