CEC-3672 Update manifest version on deploy (#277)

* CEC-3672 Add versions to CarUpdatesContext
Stub out getSoftwareVersions and updateManifestVersion

* CEC-3672 update version on deploy

* Validate version before updating
This commit is contained in:
John Wu
2023-02-09 11:51:23 -08:00
committed by GitHub
parent f863f37a9a
commit 9cf84fc426
10 changed files with 240 additions and 75 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,6 +35,7 @@ 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;
@@ -238,20 +242,60 @@ export const CarUpdatesProvider = ({ children }) => {
return result;
};
const getSoftwareVersions = async (token) => {
let result;
try {
setBusy(true);
result = await api.getSoftwareVersions(token);
if (result.error)
throw new Error(`Get software versions error. ${result.message}`);
result.data.unshift(SELECT_VERSION_OBJ)
setVersions(result.data);
} finally {
setBusy(false);
}
return result;
};
const updateManifestVersion = async (id, version, token) => {
let result;
try {
setBusy(true);
if (!validateSoftwareVersion(version)) throw new Error(`invalid version ${version}`);
result = await api.updateManifestVersion(id, version, token);
if (result.error)
throw new Error(`Update manifest version error. ${result.message}`);
} finally {
setBusy(false);
}
return result;
};
return (
<CarUpdatesContext.Provider
value={{
busy,
carUpdates,
totalCarUpdates,
versions,
cancelUpdate,
deployCarUpdates,
deployFleetUpdates,
getCarUpdates,
getLog,
getSoftwareVersions,
getVINUpdates,
startMonitor,
stopMonitor,
updateManifestVersion,
}}
>
{children}