CEC-4729: add retry button to active car updates (#414) (#417)

* add deploy button

* disable control if inactive

* add cases

(cherry picked from commit 91b2a8c8aab546221db8da8eaed22bca78c4d91f)

Co-authored-by: Tristan Timblin <ttimblin@fiskerinc.com>
This commit is contained in:
Eduard Voronkin
2023-08-15 12:21:43 -07:00
committed by GitHub
parent e1f4da2232
commit 0c05663443
3 changed files with 69 additions and 6 deletions

View File

@@ -55,6 +55,21 @@ export const CarUpdatesProvider = ({ children }) => {
return result; return result;
}; };
const deployUpdate = async (id, token) => {
let result;
try {
setBusy(true);
result = await api.deployCarUpdate(id, token);
if (result.error)
throw new Error(`Cancel car update error. ${result.message}`);
} finally {
setBusy(false);
}
return result;
};
const deployCarUpdates = async (data, token) => { const deployCarUpdates = async (data, token) => {
let result; let result;
@@ -295,6 +310,7 @@ export const CarUpdatesProvider = ({ children }) => {
totalCarUpdates, totalCarUpdates,
versions, versions,
cancelUpdate, cancelUpdate,
deployUpdate,
deployCarUpdates, deployCarUpdates,
deployFleetUpdates, deployFleetUpdates,
getCarUpdates, getCarUpdates,

View File

@@ -1,4 +1,5 @@
import { import {
IconButton,
LinearProgress, LinearProgress,
Table, Table,
TableBody, TableBody,
@@ -6,9 +7,9 @@ import {
TableFooter, TableFooter,
TablePagination, TablePagination,
TableRow, TableRow,
Tooltip
} from "@material-ui/core"; } from "@material-ui/core";
import CancelIcon from "@material-ui/icons/Cancel"; import CancelIcon from "@material-ui/icons/Cancel";
import ReplayIcon from "@material-ui/icons/Replay";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
@@ -71,6 +72,7 @@ const MainForm = ({ vin, token }) => {
const [order, setOrder] = useState("desc"); const [order, setOrder] = useState("desc");
const { const {
cancelUpdate, cancelUpdate,
deployUpdate,
getCarUpdates, getCarUpdates,
carUpdates, carUpdates,
totalCarUpdates, totalCarUpdates,
@@ -158,6 +160,28 @@ const MainForm = ({ vin, token }) => {
} }
}; };
const sendDeploy = async (row) => {
try {
await deployUpdate(row.id, token);
setMessage(`Sent deploy for ${updateName(row)}`);
} catch (e) {
setMessage(e.message);
}
};
const isActiveCarUpdate = (status) => {
switch (status) {
case "manifest_error":
case "manifest_rollback":
case "manifest_succeeded":
case "manifest_cancelled":
case "cleanup_succeeded":
return false;
default:
return true;
}
}
return ( return (
<Table> <Table>
<TableHeaderSortable <TableHeaderSortable
@@ -200,11 +224,22 @@ const MainForm = ({ vin, token }) => {
providers={providers} providers={providers}
rolesPerProvider={Permissions.FiskerMagnaCreate} rolesPerProvider={Permissions.FiskerMagnaCreate}
> >
<Tooltip key={row.vin} title={`Send cancel for ${row.vin}`}> <IconButton
<Link to="#" onClick={() => sendCancel(row)}> onClick={() => sendCancel(row)}
<CancelIcon /> aria-label={`Send cancel for ${row.vin}`}
</Link> size="small"
</Tooltip> color="primary"
>
<CancelIcon fontSize="inherit" />
</IconButton>
<IconButton
onClick={() => sendDeploy(row)}
aria-label={`Send deploy for ${row.vin}`}
size="small"
disabled={!isActiveCarUpdate(row.status)}
>
<ReplayIcon fontSize="inherit" />
</IconButton>
</RoleWrap> </RoleWrap>
</TableCell> </TableCell>
</TableRow> </TableRow>

View File

@@ -87,6 +87,18 @@ const updatesAPI = {
.catch(errorHandler); .catch(errorHandler);
}, },
deployCarUpdate: async (id, token) => {
return fetch(`${API_ENDPOINT}/carupdate/${id}/deploy`, {
method: "POST",
headers: Object.assign(
{ "Content-Type": "application/json" },
getAuthHeaderOptions(token)
),
})
.then(fetchRespHandler)
.catch(errorHandler);
},
getSUMSVersions: async (token) => { getSUMSVersions: async (token) => {
return fetch(`${API_ENDPOINT}/manifest/sums`, { return fetch(`${API_ENDPOINT}/manifest/sums`, {
method: "GET", method: "GET",