Merge branch 'release/0.0.3'

This commit is contained in:
jwu-fisker
2023-02-19 21:07:10 -08:00
18 changed files with 317 additions and 110 deletions

View File

@@ -1,10 +1,13 @@
import React, { useContext, useState } from "react";
import api from "../../services/updatesAPI";
import { validateSoftwareVersion } from "../../utils/softwareVersions";
import { validateStatusMessage } from "../../utils/statusMessage";
export const SELECT_VERSION = "Select Version";
const FINAL_UPDATE_STATES = ["package_install_complete"];
const CarUpdatesContext = React.createContext();
const SELECT_VERSION_OBJ = { version: SELECT_VERSION }
const validateDeployClosure = (data, propertyName, errPfx) => {
if (data === null) {
@@ -32,10 +35,26 @@ const validateDeployFleetUpdates = (data) => {
export const CarUpdatesProvider = ({ children }) => {
const [busy, setBusy] = useState(false);
const [carUpdates, setCarUpdates] = useState([]);
const [versions, setVersions] = useState([SELECT_VERSION_OBJ]);
const [totalCarUpdates, setTotalCarUpdates] = useState(0);
const [delayCount, setDelayCount] = useState(0);
let progressTimer = 0;
const cancelUpdate = async (id, token) => {
let result;
try {
setBusy(true);
result = await api.cancelCarUpdate(id, token);
if (result.error)
throw new Error(`Cancel car update error. ${result.message}`);
} finally {
setBusy(false);
}
return result;
};
const deployCarUpdates = async (data, token) => {
let result;
@@ -223,14 +242,36 @@ export const CarUpdatesProvider = ({ children }) => {
return result;
};
const cancelUpdate = async (id, token) => {
const getSUMSVersions = async (token) => {
let result;
try {
setBusy(true);
result = await api.cancelCarUpdate(id, token);
result = await api.getSUMSVersions(token);
if (result.error)
throw new Error(`Cancel car update error. ${result.message}`);
throw new Error(`Get software versions error. ${result.message}`);
result.data.unshift(SELECT_VERSION_OBJ)
setVersions(result.data);
} finally {
setBusy(false);
}
return result;
};
const updateSUMSVersion = async (id, version, token) => {
let result;
try {
setBusy(true);
if (!validateSoftwareVersion(version)) throw new Error(`invalid version ${version}`);
result = await api.updateSUMSVersion(id, version, token);
if (result.error)
throw new Error(`Update manifest version error. ${result.message}`);
} finally {
setBusy(false);
}
@@ -244,14 +285,17 @@ export const CarUpdatesProvider = ({ children }) => {
busy,
carUpdates,
totalCarUpdates,
versions,
cancelUpdate,
deployCarUpdates,
deployFleetUpdates,
getCarUpdates,
getLog,
getSUMSVersions,
getVINUpdates,
startMonitor,
stopMonitor,
updateSUMSVersion,
}}
>
{children}
@@ -259,4 +303,4 @@ export const CarUpdatesProvider = ({ children }) => {
);
};
export const useCarUpdatesContext = () => useContext(CarUpdatesContext);
export const useCarUpdatesContext = () => useContext(CarUpdatesContext);

View File

@@ -60,6 +60,10 @@ let carUpdateLog = {
total: 3,
};
let sumsVersions = {
"data": ["2023.02.01.0.0.A", "2023.02.01.0.0.B"]
}
export const CarUpdatesProvider = ({ children }) => {
return <div data-testid="mocked-carupdatesprovider">{children}</div>;
};
@@ -77,4 +81,6 @@ export const useCarUpdatesContext = () => ({
startMonitor: jest.fn(),
stopMonitor: jest.fn(),
approveUpdate: jest.fn(),
});
getSUMSVersions: jest.fn(() => sumsVersions),
updateSUMSVersion: jest.fn(),
});