CEC-3672 Use SUMS version instead of Version (#279)

This commit is contained in:
John Wu
2023-02-10 16:31:19 -08:00
committed by GitHub
parent 9cf84fc426
commit 0da2289f37
7 changed files with 79 additions and 52 deletions

View File

@@ -3229,22 +3229,6 @@ exports[`App Route /package-deploy authenticated 1`] = `
<main <main
class="MuiContainer-root MuiContainer-maxWidthLg" class="MuiContainer-root MuiContainer-maxWidthLg"
> >
<div
class="MuiSnackbar-root MuiSnackbar-anchorOriginTopCenter"
>
<div
class="MuiPaper-root MuiSnackbarContent-root MuiPaper-elevation6"
direction="down"
role="alert"
style="opacity: 1; transform: scale(1, 1); transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,transform 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;"
>
<div
class="MuiSnackbarContent-message"
>
getSoftwareVersions is not a function
</div>
</div>
</div>
<div <div
data-testid="mocked-manifestsprovider" data-testid="mocked-manifestsprovider"
> >
@@ -5270,6 +5254,29 @@ exports[`App Route /packages authenticated 1`] = `
</svg> </svg>
</span> </span>
</th> </th>
<th
class="MuiTableCell-root MuiTableCell-head MuiTableCell-alignCenter"
scope="col"
>
<span
aria-disabled="false"
class="MuiButtonBase-root MuiTableSortLabel-root"
role="button"
tabindex="0"
>
SUMS
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiTableSortLabel-icon MuiTableSortLabel-iconDirectionAsc"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M20 12l-1.41-1.41L13 16.17V4h-2v12.17l-5.58-5.59L4 12l8 8 8-8z"
/>
</svg>
</span>
</th>
<th <th
class="MuiTableCell-root MuiTableCell-head MuiTableCell-alignCenter" class="MuiTableCell-root MuiTableCell-head MuiTableCell-alignCenter"
scope="col" scope="col"
@@ -5368,6 +5375,9 @@ exports[`App Route /packages authenticated 1`] = `
> >
1.0 1.0
</td> </td>
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter"
/>
<td <td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter" class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter"
> >
@@ -5451,7 +5461,7 @@ exports[`App Route /packages authenticated 1`] = `
> >
<td <td
class="MuiTableCell-root MuiTableCell-footer MuiTablePagination-root" class="MuiTableCell-root MuiTableCell-footer MuiTablePagination-root"
colspan="6" colspan="8"
> >
<div <div
class="MuiToolbar-root MuiToolbar-regular MuiTablePagination-toolbar MuiToolbar-gutters" class="MuiToolbar-root MuiToolbar-regular MuiTablePagination-toolbar MuiToolbar-gutters"

View File

@@ -242,13 +242,13 @@ export const CarUpdatesProvider = ({ children }) => {
return result; return result;
}; };
const getSoftwareVersions = async (token) => { const getSUMSVersions = async (token) => {
let result; let result;
try { try {
setBusy(true); setBusy(true);
result = await api.getSoftwareVersions(token); result = await api.getSUMSVersions(token);
if (result.error) if (result.error)
throw new Error(`Get software versions error. ${result.message}`); throw new Error(`Get software versions error. ${result.message}`);
@@ -261,7 +261,7 @@ export const CarUpdatesProvider = ({ children }) => {
return result; return result;
}; };
const updateManifestVersion = async (id, version, token) => { const updateSUMSVersion = async (id, version, token) => {
let result; let result;
try { try {
@@ -269,7 +269,7 @@ export const CarUpdatesProvider = ({ children }) => {
if (!validateSoftwareVersion(version)) throw new Error(`invalid version ${version}`); if (!validateSoftwareVersion(version)) throw new Error(`invalid version ${version}`);
result = await api.updateManifestVersion(id, version, token); result = await api.updateSUMSVersion(id, version, token);
if (result.error) if (result.error)
throw new Error(`Update manifest version error. ${result.message}`); throw new Error(`Update manifest version error. ${result.message}`);
} finally { } finally {
@@ -291,11 +291,11 @@ export const CarUpdatesProvider = ({ children }) => {
deployFleetUpdates, deployFleetUpdates,
getCarUpdates, getCarUpdates,
getLog, getLog,
getSoftwareVersions, getSUMSVersions,
getVINUpdates, getVINUpdates,
startMonitor, startMonitor,
stopMonitor, stopMonitor,
updateManifestVersion, updateSUMSVersion,
}} }}
> >
{children} {children}

View File

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

View File

@@ -26,7 +26,7 @@ const MainForm = () => {
const [updateType, setUpdateType] = useState(CAR_UPDATE); const [updateType, setUpdateType] = useState(CAR_UPDATE);
const {manifest_id} = useParams(); const {manifest_id} = useParams();
const {getManifests, manifests, busy} = useManifestsContext(); const {getManifests, manifests, busy} = useManifestsContext();
const {deployCarUpdates, deployFleetUpdates, getSoftwareVersions, versions, updateManifestVersion} = useCarUpdatesContext(); const {deployCarUpdates, deployFleetUpdates, getSUMSVersions, versions, updateSUMSVersion} = useCarUpdatesContext();
const { const {
groups, groups,
providers, providers,
@@ -37,6 +37,7 @@ const MainForm = () => {
const {setMessage, setTitle, setSitePath} = useStatusContext(); const {setMessage, setTitle, setSitePath} = useStatusContext();
const [manifestName, setManifestName] = useState(""); const [manifestName, setManifestName] = useState("");
const [version, setVersion] = useState(""); const [version, setVersion] = useState("");
const [sumsVersion, setSUMSersion] = useState("");
const [createDate, setCreateDate] = useState(""); const [createDate, setCreateDate] = useState("");
const [selected, setSelected] = useState([]); const [selected, setSelected] = useState([]);
const [search, setSearch] = useState(""); const [search, setSearch] = useState("");
@@ -79,7 +80,9 @@ const MainForm = () => {
const data = { const data = {
manifest_id: parseInt(manifest_id), manifest_id: parseInt(manifest_id),
} }
await updateManifestVersion(manifest_id, softwareVersion, token); if (sumsVersion.length === 0) {
await updateSUMSVersion(manifest_id, softwareVersion, token);
}
if (updateType === CAR_UPDATE) { if (updateType === CAR_UPDATE) {
data.vins = selected; data.vins = selected;
@@ -101,7 +104,7 @@ const MainForm = () => {
const getData = async () => { const getData = async () => {
try { try {
await getManifests({id: parseInt(manifest_id)}, token); await getManifests({id: parseInt(manifest_id)}, token);
await getSoftwareVersions(token); await getSUMSVersions(token);
} catch (e) { } catch (e) {
setMessage(e.message); setMessage(e.message);
logger.warn(e.stack); logger.warn(e.stack);
@@ -138,6 +141,7 @@ const MainForm = () => {
setManifestName(data.name); setManifestName(data.name);
setVersion(data.version); setVersion(data.version);
setSUMSersion(data.sums || "");
setCreateDate(LocalDateTimeString(data.created)); setCreateDate(LocalDateTimeString(data.created));
}, [manifests]); }, [manifests]);
@@ -172,6 +176,7 @@ const MainForm = () => {
<SearchField classes={classes} onSearch={handleSearch}/> <SearchField classes={classes} onSearch={handleSearch}/>
</Grid> </Grid>
<Grid item md={4} container justifyContent="flex-end"> <Grid item md={4} container justifyContent="flex-end">
{sumsVersion.length === 0 &&
<DropDownList <DropDownList
label="Software Version" label="Software Version"
labelField="version" labelField="version"
@@ -180,9 +185,10 @@ const MainForm = () => {
data={versions} data={versions}
classes={classes} classes={classes}
onChange={changeVersion} /> onChange={changeVersion} />
}
<Button <Button
type="submit" type="submit"
disabled={busy || selected.length === 0 || softwareVersion === SELECT_VERSION} disabled={busy || selected.length === 0 || (sumsVersion.length === 0 && softwareVersion === SELECT_VERSION)}
color="primary" color="primary"
onClick={onSubmit} onClick={onSubmit}
> >

View File

@@ -6,15 +6,15 @@ import {
TableFooter, TableFooter,
TablePagination, TablePagination,
TableRow, TableRow,
Tooltip, Tooltip
} from "@material-ui/core"; } from "@material-ui/core";
import {
ToggleButton,
ToggleButtonGroup
} from "@mui/material"
import DeleteIcon from "@material-ui/icons/Delete"; import DeleteIcon from "@material-ui/icons/Delete";
import SendIcon from "@material-ui/icons/Send"; import SendIcon from "@material-ui/icons/Send";
import VisibilityIcon from "@material-ui/icons/Visibility"; import VisibilityIcon from "@material-ui/icons/Visibility";
import {
ToggleButton,
ToggleButtonGroup
} from "@mui/material";
import clsx from "clsx"; import clsx from "clsx";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
@@ -26,7 +26,7 @@ import { TYPE_MANIFEST_SOFTWARE } from "../../../utils/manifest_types";
import { hasRole, Permissions } from "../../../utils/roles"; import { hasRole, Permissions } from "../../../utils/roles";
import { import {
ManifestsProvider, ManifestsProvider,
useManifestsContext, useManifestsContext
} from "../../Contexts/ManifestsContext"; } from "../../Contexts/ManifestsContext";
import { useStatusContext } from "../../Contexts/StatusContext"; import { useStatusContext } from "../../Contexts/StatusContext";
import { useUserContext } from "../../Contexts/UserContext"; import { useUserContext } from "../../Contexts/UserContext";
@@ -50,6 +50,10 @@ const tableColumns = [
id: "version", id: "version",
label: "Version", label: "Version",
}, },
{
id: "sums",
label: "SUMS",
},
{ {
id: "type", id: "type",
label: "Type", label: "Type",
@@ -280,6 +284,7 @@ const MainForm = () => {
)} )}
</TableCell> </TableCell>
<TableCell align="center">{row.version}</TableCell> <TableCell align="center">{row.version}</TableCell>
<TableCell align="center">{row.sums}</TableCell>
<TableCell align="center"> <TableCell align="center">
{formatManifestType(row.type)} {formatManifestType(row.type)}
</TableCell> </TableCell>
@@ -297,7 +302,7 @@ const MainForm = () => {
<TableRow> <TableRow>
<TablePagination <TablePagination
rowsPerPageOptions={[5, 10, 25, 100]} rowsPerPageOptions={[5, 10, 25, 100]}
colSpan={6} colSpan={8}
count={totalManifests} count={totalManifests}
rowsPerPage={pageSize} rowsPerPage={pageSize}
page={pageIndex} page={pageIndex}

View File

@@ -27,13 +27,13 @@ const updatesAPI = {
return { message: "OK" }; return { message: "OK" };
}, },
getSoftwareVersions: async (token) => { getSUMSVersions: async (token) => {
return { return {
"data": ["2023.02.01.0.0.A", "2023.02.01.0.0.B"] "data": ["2023.02.01.0.0.A", "2023.02.01.0.0.B"]
}; };
}, },
updateManifestVersion: async (_id, version) => { updateSUMSVersion: async (_id, version) => {
return { version }; return { version };
}, },
}; };

View File

@@ -87,8 +87,8 @@ const updatesAPI = {
.catch(errorHandler); .catch(errorHandler);
}, },
getSoftwareVersions: async (token) => { getSUMSVersions: async (token) => {
return fetch(`${API_ENDPOINT}/manifest/versions`, { return fetch(`${API_ENDPOINT}/manifest/sums`, {
method: "GET", method: "GET",
headers: Object.assign( headers: Object.assign(
{ "Content-Type": "application/json" }, { "Content-Type": "application/json" },
@@ -99,8 +99,8 @@ const updatesAPI = {
.catch(errorHandler); .catch(errorHandler);
}, },
updateManifestVersion: async (id, version, token) => { updateSUMSVersion: async (id, version, token) => {
return fetch(`${API_ENDPOINT}/manifests/${id}/version`, { return fetch(`${API_ENDPOINT}/manifests/${id}/sums`, {
method: "PUT", method: "PUT",
headers: Object.assign( headers: Object.assign(
{ "Content-Type": "application/json" }, { "Content-Type": "application/json" },