Merge branch 'release/0.0.3'

This commit is contained in:
jwu-fisker
2022-09-28 09:01:19 -07:00
parent 56043dc375
commit a1ac3888fa
31 changed files with 959 additions and 437 deletions

658
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -2434,6 +2434,10 @@ exports[`App Route /package-status authenticated 1`] = `
> >
Updated Updated
</th> </th>
<th
class="MuiTableCell-root MuiTableCell-head MuiTableCell-alignCenter"
scope="col"
/>
</tr> </tr>
</thead> </thead>
<tbody <tbody
@@ -2472,6 +2476,26 @@ exports[`App Route /package-status authenticated 1`] = `
> >
7/12/2021 6:22:13 PM 7/12/2021 6:22:13 PM
</td> </td>
<td
class="MuiTableCell-root MuiTableCell-body"
>
<a
class=""
href="/package-status/1"
title="Send cancel for 1G1FP87S3GN100062"
>
<svg
aria-hidden="true"
class="MuiSvgIcon-root"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2zm5 13.59L15.59 17 12 13.41 8.41 17 7 15.59 10.59 12 7 8.41 8.41 7 12 10.59 15.59 7 17 8.41 13.41 12 17 15.59z"
/>
</svg>
</a>
</td>
</tr> </tr>
</tbody> </tbody>
<tfoot <tfoot
@@ -2482,7 +2506,7 @@ exports[`App Route /package-status authenticated 1`] = `
> >
<td <td
class="MuiTableCell-root MuiTableCell-footer MuiTablePagination-root" class="MuiTableCell-root MuiTableCell-footer MuiTablePagination-root"
colspan="5" colspan="6"
> >
<div <div
class="MuiToolbar-root MuiToolbar-regular MuiTablePagination-toolbar MuiToolbar-gutters" class="MuiToolbar-root MuiToolbar-regular MuiTablePagination-toolbar MuiToolbar-gutters"
@@ -3287,23 +3311,26 @@ exports[`App Route /packages authenticated 1`] = `
/> />
</svg> </svg>
</a> </a>
<a <div>
class="" <a
href="/packages" class=""
title="Delete \\"Test Manifest 1.0\\"" href="/packages"
> title="Delete \\"Test Manifest 1.0\\""
<svg
aria-hidden="true"
aria-label="Delete Test Manifest 1.0"
class="MuiSvgIcon-root"
focusable="false"
viewBox="0 0 24 24"
> >
<path <svg
d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z" aria-hidden="true"
/> aria-label="Delete Test Manifest 1.0"
</svg> class="MuiSvgIcon-root"
</a> focusable="false"
viewBox="0 0 24 24"
>
<path
d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"
/>
</svg>
</a>
<div />
</div>
</td> </td>
</tr> </tr>
</tbody> </tbody>
@@ -7024,6 +7051,7 @@ exports[`App Route /vehicle-status authenticated 1`] = `
</a> </a>
</div> </div>
</div> </div>
<div />
</div> </div>
</div> </div>
</div> </div>

View File

@@ -149,6 +149,29 @@ exports[`CANFiltersTable Render 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"
>
Fleet
<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"
@@ -173,6 +196,13 @@ exports[`CANFiltersTable Render 1`] = `
> >
1000 1000
</td> </td>
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter"
>
<a
href="/fleet/undefined"
/>
</td>
<td <td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter" class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter"
> >
@@ -226,6 +256,13 @@ exports[`CANFiltersTable Render 1`] = `
> >
2000 2000
</td> </td>
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter"
>
<a
href="/fleet/undefined"
/>
</td>
<td <td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter" class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter"
> >
@@ -279,6 +316,13 @@ exports[`CANFiltersTable Render 1`] = `
> >
0 0
</td> </td>
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter"
>
<a
href="/fleet/undefined"
/>
</td>
<td <td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter" class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter"
> >

View File

@@ -39,6 +39,10 @@ const tableColumns = [
id: "interval", id: "interval",
label: "Interval (ms)" label: "Interval (ms)"
}, },
{
id: "fleet",
label: "Fleet"
},
{ {
id: "", id: "",
label: "Actions" label: "Actions"
@@ -178,6 +182,9 @@ const MainForm = ({ vin }) => {
<TableRow key={row.can_id}> <TableRow key={row.can_id}>
<TableCell align="center">{row.can_id}</TableCell> <TableCell align="center">{row.can_id}</TableCell>
<TableCell align="center">{row.interval}</TableCell> <TableCell align="center">{row.interval}</TableCell>
<TableCell align="center">
<Link to={`/fleet/${row.fleet}`}>{row.fleet}</Link>
</TableCell>
<TableCell align="center">{Actions(row)}</TableCell> <TableCell align="center">{Actions(row)}</TableCell>
</TableRow> </TableRow>
))} ))}

View File

@@ -28,6 +28,7 @@ exports[`VehicleDetailsTab Render 1`] = `
VIN VIN
</b> </b>
: :
TESTVIN1234567890
</p> </p>
<p> <p>
<b> <b>
@@ -84,13 +85,13 @@ exports[`VehicleDetailsTab Render 1`] = `
> >
<a <a
class="" class=""
href="/vehicle-update?vin=undefined" href="/vehicle-update?vin=TESTVIN1234567890"
style="margin: 5px;" style="margin: 5px;"
title="Update \\"undefined\\"" title="Update \\"TESTVIN1234567890\\""
> >
<svg <svg
aria-hidden="true" aria-hidden="true"
aria-label="Update \\"undefined\\"" aria-label="Update \\"TESTVIN1234567890\\""
class="MuiSvgIcon-root" class="MuiSvgIcon-root"
focusable="false" focusable="false"
viewBox="0 0 24 24" viewBox="0 0 24 24"
@@ -103,11 +104,11 @@ exports[`VehicleDetailsTab Render 1`] = `
<a <a
class="" class=""
href="/" href="/"
title="Delete \\"undefined\\"" title="Delete \\"TESTVIN1234567890\\""
> >
<svg <svg
aria-hidden="true" aria-hidden="true"
aria-label="Delete \\"undefined\\"" aria-label="Delete \\"TESTVIN1234567890\\""
class="MuiSvgIcon-root" class="MuiSvgIcon-root"
focusable="false" focusable="false"
viewBox="0 0 24 24" viewBox="0 0 24 24"
@@ -119,6 +120,7 @@ exports[`VehicleDetailsTab Render 1`] = `
</a> </a>
</div> </div>
</div> </div>
<div />
</div> </div>
</div> </div>
</div> </div>

View File

@@ -14,12 +14,14 @@ import { useStatusContext } from "../../../Contexts/StatusContext";
import useStyles from "../../../useStyles"; import useStyles from "../../../useStyles";
import { logger } from "../../../../services/monitoring"; import { logger } from "../../../../services/monitoring";
import { useVehicleContext, VehicleProvider } from "../../../Contexts/VehicleContext"; import { useVehicleContext, VehicleProvider } from "../../../Contexts/VehicleContext";
import DeleteConfirmation from "../../../DeleteConfirmation";
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 } = useVehicleContext();
const [redirect, setRedirect] = useState(null); const [redirect, setRedirect] = useState(null);
const [showDeleteModal, setShowDeleteModal] = useState(false)
const { token: { idToken: { jwtToken: token } } } = useUserContext(); const { token: { idToken: { jwtToken: token } } } = useUserContext();
useEffect(() => { useEffect(() => {
@@ -76,12 +78,13 @@ const MainForm = ({ vin }) => {
</Link> </Link>
</Tooltip> </Tooltip>
<Tooltip key={`delete-${vin}`} title={`Delete "${vin}"`}> <Tooltip key={`delete-${vin}`} title={`Delete "${vin}"`}>
<Link to="#" onClick={onDelete}> <Link to="#" onClick={() => setShowDeleteModal(true)}>
<DeleteIcon aria-label={`Delete "${vin}"`} /> <DeleteIcon aria-label={`Delete "${vin}"`} />
</Link> </Link>
</Tooltip> </Tooltip>
</Grid> </Grid>
</Grid> </Grid>
<DeleteConfirmation message={vin} open={showDeleteModal} close={()=> setShowDeleteModal(false)} deleteFunction={onDelete}/>
</div > </div >
); );
}; };

View File

@@ -4,6 +4,7 @@ jest.mock("../../../Contexts/UserContext");
import { render, waitFor } from "@testing-library/react"; import { render, waitFor } from "@testing-library/react";
import { BrowserRouter } from "react-router-dom"; import { BrowserRouter } from "react-router-dom";
import routeData from "react-router";
import { VehicleProvider } from "../../../Contexts/VehicleContext"; import { VehicleProvider } from "../../../Contexts/VehicleContext";
import { StatusProvider } from "../../../Contexts/StatusContext"; import { StatusProvider } from "../../../Contexts/StatusContext";
@@ -18,7 +19,7 @@ const renderVehicleDetailsTab = async () => {
<StatusProvider> <StatusProvider>
<UserProvider> <UserProvider>
<BrowserRouter> <BrowserRouter>
<MainForm /> <MainForm vin="TESTVIN1234567890"/>
</BrowserRouter> </BrowserRouter>
</UserProvider> </UserProvider>
</StatusProvider> </StatusProvider>
@@ -35,6 +36,11 @@ describe("VehicleDetailsTab", () => {
addSnapshotSerializer(expect); addSnapshotSerializer(expect);
}); });
beforeEach(() => {
// Does not work if placed in beforeAll
jest.spyOn(routeData, 'useParams').mockReturnValue({ vin: "TESTVIN1234567890" })
})
it("Render", async () => { it("Render", async () => {
setToken(TEST_AUTH_OBJECT); setToken(TEST_AUTH_OBJECT);
const container = await renderVehicleDetailsTab(); const container = await renderVehicleDetailsTab();

View File

@@ -148,6 +148,29 @@ exports[`CANFiltersTab Render 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"
>
Fleet
<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"
@@ -172,6 +195,13 @@ exports[`CANFiltersTab Render 1`] = `
> >
1000 1000
</td> </td>
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter"
>
<a
href="/fleet/undefined"
/>
</td>
<td <td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter" class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter"
> >
@@ -225,6 +255,13 @@ exports[`CANFiltersTab Render 1`] = `
> >
2000 2000
</td> </td>
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter"
>
<a
href="/fleet/undefined"
/>
</td>
<td <td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter" class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter"
> >
@@ -278,6 +315,13 @@ exports[`CANFiltersTab Render 1`] = `
> >
0 0
</td> </td>
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter"
>
<a
href="/fleet/undefined"
/>
</td>
<td <td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter" class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter"
> >

View File

@@ -149,6 +149,10 @@ exports[`CarUpdatesTab Render 1`] = `
</svg> </svg>
</span> </span>
</th> </th>
<th
class="MuiTableCell-root MuiTableCell-head MuiTableCell-alignCenter"
scope="col"
/>
</tr> </tr>
</thead> </thead>
<tbody <tbody
@@ -162,7 +166,7 @@ exports[`CarUpdatesTab Render 1`] = `
> >
<td <td
class="MuiTableCell-root MuiTableCell-footer MuiTablePagination-root" class="MuiTableCell-root MuiTableCell-footer MuiTablePagination-root"
colspan="5" colspan="6"
> >
<div <div
class="MuiToolbar-root MuiToolbar-regular MuiTablePagination-toolbar MuiToolbar-gutters" class="MuiToolbar-root MuiToolbar-regular MuiTablePagination-toolbar MuiToolbar-gutters"

View File

@@ -128,6 +128,7 @@ exports[`DetailsTab Render 1`] = `
</a> </a>
</div> </div>
</div> </div>
<div />
</div> </div>
</div> </div>
</div> </div>

View File

@@ -175,6 +175,7 @@ exports[`CarStatus Render 1`] = `
VIN VIN
</b> </b>
: :
TESTVIN1234567890
</p> </p>
</div> </div>
<div <div
@@ -182,13 +183,13 @@ exports[`CarStatus Render 1`] = `
> >
<a <a
class="" class=""
href="/vehicle-update?vin=undefined" href="/vehicle-update?vin=TESTVIN1234567890"
style="margin: 5px;" style="margin: 5px;"
title="Update \\"undefined\\"" title="Update \\"TESTVIN1234567890\\""
> >
<svg <svg
aria-hidden="true" aria-hidden="true"
aria-label="Update \\"undefined\\"" aria-label="Update \\"TESTVIN1234567890\\""
class="MuiSvgIcon-root" class="MuiSvgIcon-root"
focusable="false" focusable="false"
viewBox="0 0 24 24" viewBox="0 0 24 24"
@@ -201,11 +202,11 @@ exports[`CarStatus Render 1`] = `
<a <a
class="" class=""
href="/" href="/"
title="Delete \\"undefined\\"" title="Delete \\"TESTVIN1234567890\\""
> >
<svg <svg
aria-hidden="true" aria-hidden="true"
aria-label="Delete \\"undefined\\"" aria-label="Delete \\"TESTVIN1234567890\\""
class="MuiSvgIcon-root" class="MuiSvgIcon-root"
focusable="false" focusable="false"
viewBox="0 0 24 24" viewBox="0 0 24 24"
@@ -217,6 +218,7 @@ exports[`CarStatus Render 1`] = `
</a> </a>
</div> </div>
</div> </div>
<div />
</div> </div>
</div> </div>
</div> </div>

View File

@@ -7,6 +7,7 @@ jest.mock("@material-ui/core/utils/unstable_useId", () =>
import { render, waitFor } from "@testing-library/react"; import { render, waitFor } from "@testing-library/react";
import { BrowserRouter } from "react-router-dom"; import { BrowserRouter } from "react-router-dom";
import routeData from "react-router";
import { CANFiltersProvider } from "../../Contexts/CANFiltersContext"; import { CANFiltersProvider } from "../../Contexts/CANFiltersContext";
import { StatusProvider } from "../../Contexts/StatusContext"; import { StatusProvider } from "../../Contexts/StatusContext";
@@ -38,6 +39,11 @@ describe("CarStatus", () => {
addSnapshotSerializer(expect); addSnapshotSerializer(expect);
}); });
beforeEach(() => {
// Does not work if placed in beforeAll
jest.spyOn(routeData, 'useParams').mockReturnValue({ vin: "TESTVIN1234567890" })
})
it("Render", async () => { it("Render", async () => {
setToken(TEST_AUTH_OBJECT); setToken(TEST_AUTH_OBJECT);
const container = await renderCarStatus(); const container = await renderCarStatus();

View File

@@ -6,7 +6,6 @@ import { validateStatusMessage } from "../../utils/statusMessage";
const FINAL_UPDATE_STATES = ["package_install_complete"]; const FINAL_UPDATE_STATES = ["package_install_complete"];
const CarUpdatesContext = React.createContext(); const CarUpdatesContext = React.createContext();
const validateDeployClosure = (data, propertyName, errPfx) => { const validateDeployClosure = (data, propertyName, errPfx) => {
if (data === null) { if (data === null) {
throw new Error("No car update data"); throw new Error("No car update data");
@@ -20,17 +19,16 @@ const validateDeployClosure = (data, propertyName, errPfx) => {
if (!value || value.length === 0) { if (!value || value.length === 0) {
throw new Error(`${errPfx} are required`); throw new Error(`${errPfx} are required`);
} }
} };
const validateDeployCarUpdates = (data) => { const validateDeployCarUpdates = (data) => {
return validateDeployClosure(data, 'vins', 'Cars') return validateDeployClosure(data, "vins", "Cars");
}; };
const validateDeployFleetUpdates = (data) => { const validateDeployFleetUpdates = (data) => {
return validateDeployClosure(data, 'fleet_names', 'Fleets') return validateDeployClosure(data, "fleet_names", "Fleets");
}; };
export const CarUpdatesProvider = ({ children }) => { export const CarUpdatesProvider = ({ children }) => {
const [busy, setBusy] = useState(false); const [busy, setBusy] = useState(false);
const [carUpdates, setCarUpdates] = useState([]); const [carUpdates, setCarUpdates] = useState([]);
@@ -61,14 +59,14 @@ export const CarUpdatesProvider = ({ children }) => {
setBusy(true); setBusy(true);
validateDeployFleetUpdates(data); validateDeployFleetUpdates(data);
result = await api.createFleetUpdates(data, token); result = await api.createFleetUpdates(data, token);
if (result.error) if (result.error)
throw new Error(`Deploy fleet updates error. ${result.message}`); throw new Error(`Deploy fleet updates error. ${result.message}`);
} finally { } finally {
setBusy(false); setBusy(false);
} }
return result; return result;
} };
const getCarUpdates = async (search, token) => { const getCarUpdates = async (search, token) => {
let result; let result;
@@ -224,12 +222,28 @@ export const CarUpdatesProvider = ({ children }) => {
return result; return result;
}; };
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;
};
return ( return (
<CarUpdatesContext.Provider <CarUpdatesContext.Provider
value={{ value={{
busy, busy,
carUpdates, carUpdates,
totalCarUpdates, totalCarUpdates,
cancelUpdate,
deployCarUpdates, deployCarUpdates,
deployFleetUpdates, deployFleetUpdates,
getCarUpdates, getCarUpdates,

View File

@@ -6,8 +6,10 @@ import {
TableFooter, TableFooter,
TablePagination, TablePagination,
TableRow, TableRow,
Tooltip,
} from "@material-ui/core"; } from "@material-ui/core";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import CancelIcon from "@material-ui/icons/Cancel";
import { LocalDateTimeString } from "../../../utils/dates"; import { LocalDateTimeString } from "../../../utils/dates";
import TableHeaderSortable from "../../Table/HeaderSortable"; import TableHeaderSortable from "../../Table/HeaderSortable";
@@ -18,7 +20,7 @@ import {
import { useStatusContext } from "../../Contexts/StatusContext"; import { useStatusContext } from "../../Contexts/StatusContext";
import useStyles from "../../useStyles"; import useStyles from "../../useStyles";
import { logger } from "../../../services/monitoring"; import { logger } from "../../../services/monitoring";
import {useLocalStorage} from "../../useLocalStorage"; import { useLocalStorage } from "../../useLocalStorage";
const tableColumns = [ const tableColumns = [
{ {
@@ -41,6 +43,10 @@ const tableColumns = [
id: "updated_at", id: "updated_at",
label: "Updated", label: "Updated",
}, },
{
id: "",
label: "",
},
]; ];
const PAGE_SIZE = "CAR_UPDATES_TABLE_PAGE_SIZE"; const PAGE_SIZE = "CAR_UPDATES_TABLE_PAGE_SIZE";
@@ -51,7 +57,8 @@ const MainForm = ({ vin, token }) => {
const [pageIndex, setPageIndex] = useState(0); const [pageIndex, setPageIndex] = useState(0);
const [orderBy, setOrderBy] = useState("id"); const [orderBy, setOrderBy] = useState("id");
const [order, setOrder] = useState("desc"); const [order, setOrder] = useState("desc");
const { getCarUpdates, carUpdates, totalCarUpdates } = useCarUpdatesContext(); const { cancelUpdate, getCarUpdates, carUpdates, totalCarUpdates } =
useCarUpdatesContext();
const { setMessage } = useStatusContext(); const { setMessage } = useStatusContext();
useEffect(() => { useEffect(() => {
@@ -107,6 +114,15 @@ const MainForm = ({ vin, token }) => {
return "None"; return "None";
}; };
const sendCancel = async (row) => {
try {
await cancelUpdate(row.id, token);
setMessage(`Sent cancel for ${updateName(row)}`);
} catch (e) {
setMessage(e.message);
}
};
return ( return (
<Table> <Table>
<TableHeaderSortable <TableHeaderSortable
@@ -132,6 +148,13 @@ const MainForm = ({ vin, token }) => {
<TableCell align="center"> <TableCell align="center">
{LocalDateTimeString(row.updated)} {LocalDateTimeString(row.updated)}
</TableCell> </TableCell>
<TableCell>
<Tooltip key={row.vin} title={`Send cancel for ${row.vin}`}>
<Link to="#" onClick={() => sendCancel(row)}>
<CancelIcon />
</Link>
</Tooltip>
</TableCell>
</TableRow> </TableRow>
))} ))}
</TableBody> </TableBody>
@@ -139,7 +162,7 @@ const MainForm = ({ vin, token }) => {
<TableRow> <TableRow>
<TablePagination <TablePagination
rowsPerPageOptions={[5, 10, 25, 100]} rowsPerPageOptions={[5, 10, 25, 100]}
colSpan={5} colSpan={6}
count={totalCarUpdates} count={totalCarUpdates}
rowsPerPage={pageSize} rowsPerPage={pageSize}
page={pageIndex} page={pageIndex}

View File

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

View File

@@ -0,0 +1,36 @@
import React from "react";
import PropTypes from "prop-types";
import {Dialog, DialogTitle, DialogContentText, Button, DialogActions, DialogContent} from '@material-ui/core';
const DeleteConfirmation = (props) => {
return (
<div>
<Dialog open={props.open}
onClose={props.close}>
<DialogTitle id="alert-dialog-title">
{"Delete Resource?"}
</DialogTitle>
<DialogContent>
<DialogContentText id="alert-dialog-description">
{"Are you sure you want to delete: " + props.message}
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={props.close}>Cancel</Button>
<Button variant="contained" color="secondary" onClick={() => { props.close(); props.deleteFunction()}} autoFocus>
Delete
</Button>
</DialogActions>
</Dialog>
</div>
)
}
DeleteConfirmation.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 to be deleted
deleteFunction: PropTypes.func.isRequired, // Function that runs when user clicks delete
}
export default DeleteConfirmation;

View File

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

View File

@@ -28,6 +28,7 @@ exports[`FleetDetailsTab Render 1`] = `
Name Name
</b> </b>
: :
Test Fleet
</p> </p>
<p> <p>
<b> <b>
@@ -91,13 +92,13 @@ exports[`FleetDetailsTab Render 1`] = `
> >
<a <a
class="" class=""
href="/fleet-update?name=undefined" href="/fleet-update?name=Test Fleet"
style="margin: 5px;" style="margin: 5px;"
title="Update \\"undefined\\"" title="Update \\"Test Fleet\\""
> >
<svg <svg
aria-hidden="true" aria-hidden="true"
aria-label="Update \\"undefined\\"" aria-label="Update \\"Test Fleet\\""
class="MuiSvgIcon-root" class="MuiSvgIcon-root"
focusable="false" focusable="false"
viewBox="0 0 24 24" viewBox="0 0 24 24"
@@ -110,11 +111,11 @@ exports[`FleetDetailsTab Render 1`] = `
<a <a
class="" class=""
href="/" href="/"
title="Delete \\"undefined\\"" title="Delete \\"Test Fleet\\""
> >
<svg <svg
aria-hidden="true" aria-hidden="true"
aria-label="Delete \\"undefined\\"" aria-label="Delete \\"Test Fleet\\""
class="MuiSvgIcon-root" class="MuiSvgIcon-root"
focusable="false" focusable="false"
viewBox="0 0 24 24" viewBox="0 0 24 24"
@@ -126,6 +127,7 @@ exports[`FleetDetailsTab Render 1`] = `
</a> </a>
</div> </div>
</div> </div>
<div />
</div> </div>
</div> </div>
</div> </div>

View File

@@ -14,12 +14,14 @@ import { useStatusContext } from "../../../Contexts/StatusContext";
import { FleetProvider, useFleetContext } from "../../../Contexts/FleetContext" import { FleetProvider, useFleetContext } from "../../../Contexts/FleetContext"
import useStyles from "../../../useStyles"; import useStyles from "../../../useStyles";
import { logger } from "../../../../services/monitoring"; import { logger } from "../../../../services/monitoring";
import DeleteConfirmation from "../../../DeleteConfirmation";
const MainForm = ({ name }) => { const MainForm = ({ name }) => {
const classes = useStyles(); const classes = useStyles();
const { setMessage } = useStatusContext(); const { setMessage } = useStatusContext();
const { fleet, getFleet, deleteFleet } = useFleetContext(); const { fleet, getFleet, deleteFleet } = useFleetContext();
const [redirect, setRedirect] = useState(null); const [redirect, setRedirect] = useState(null);
const [showDeleteModal, setShowDeleteModal] = useState(false)
const { token: { idToken: { jwtToken: token } } } = useUserContext(); const { token: { idToken: { jwtToken: token } } } = useUserContext();
useEffect(() => { useEffect(() => {
@@ -77,12 +79,13 @@ const MainForm = ({ name }) => {
</Link> </Link>
</Tooltip> </Tooltip>
<Tooltip key={`delete-${name}`} title={`Delete "${name}"`}> <Tooltip key={`delete-${name}`} title={`Delete "${name}"`}>
<Link to="#" onClick={onDelete}> <Link to="#" onClick={() => setShowDeleteModal(true)}>
<DeleteIcon aria-label={`Delete "${name}"`} /> <DeleteIcon aria-label={`Delete "${name}"`} />
</Link> </Link>
</Tooltip> </Tooltip>
</Grid> </Grid>
</Grid> </Grid>
<DeleteConfirmation message={name} open={showDeleteModal} close={()=> setShowDeleteModal(false)} deleteFunction={onDelete}/>
</div > </div >
); );
}; };

View File

@@ -4,6 +4,7 @@ jest.mock("../../../Contexts/UserContext");
import { render, waitFor } from "@testing-library/react"; import { render, waitFor } from "@testing-library/react";
import { BrowserRouter } from "react-router-dom"; import { BrowserRouter } from "react-router-dom";
import routeData from "react-router";
import { FleetProvider } from "../../../Contexts/FleetContext"; import { FleetProvider } from "../../../Contexts/FleetContext";
import { StatusProvider } from "../../../Contexts/StatusContext"; import { StatusProvider } from "../../../Contexts/StatusContext";
@@ -18,7 +19,7 @@ const renderFleetDetailsTab = async () => {
<StatusProvider> <StatusProvider>
<UserProvider> <UserProvider>
<BrowserRouter> <BrowserRouter>
<MainForm /> <MainForm name="Test Fleet"/>
</BrowserRouter> </BrowserRouter>
</UserProvider> </UserProvider>
</StatusProvider> </StatusProvider>
@@ -35,6 +36,11 @@ describe("FleetDetailsTab", () => {
addSnapshotSerializer(expect); addSnapshotSerializer(expect);
}); });
beforeEach(() => {
// Does not work if placed in beforeAll
jest.spyOn(routeData, 'useParams').mockReturnValue({ name: "Test Fleet" })
})
it("Render", async () => { it("Render", async () => {
setToken(TEST_AUTH_OBJECT); setToken(TEST_AUTH_OBJECT);
const container = await renderFleetDetailsTab(); const container = await renderFleetDetailsTab();

View File

@@ -153,23 +153,26 @@ exports[`FleetVehiclesTable Render 1`] = `
<td <td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter" class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter"
> >
<a <div>
class="" <a
href="/" class=""
title="Delete \\"USWESTVIN12345678\\"" href="/"
> title="Delete \\"USWESTVIN12345678\\""
<svg
aria-hidden="true"
aria-label="Delete USWESTVIN12345678"
class="MuiSvgIcon-root"
focusable="false"
viewBox="0 0 24 24"
> >
<path <svg
d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z" aria-hidden="true"
/> aria-label="Delete USWESTVIN12345678"
</svg> class="MuiSvgIcon-root"
</a> focusable="false"
viewBox="0 0 24 24"
>
<path
d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"
/>
</svg>
</a>
<div />
</div>
</td> </td>
</tr> </tr>
<tr <tr
@@ -187,23 +190,26 @@ exports[`FleetVehiclesTable Render 1`] = `
<td <td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter" class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter"
> >
<a <div>
class="" <a
href="/" class=""
title="Delete \\"USWESTVIN12345679\\"" href="/"
> title="Delete \\"USWESTVIN12345679\\""
<svg
aria-hidden="true"
aria-label="Delete USWESTVIN12345679"
class="MuiSvgIcon-root"
focusable="false"
viewBox="0 0 24 24"
> >
<path <svg
d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z" aria-hidden="true"
/> aria-label="Delete USWESTVIN12345679"
</svg> class="MuiSvgIcon-root"
</a> focusable="false"
viewBox="0 0 24 24"
>
<path
d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"
/>
</svg>
</a>
<div />
</div>
</td> </td>
</tr> </tr>
<tr <tr
@@ -221,23 +227,26 @@ exports[`FleetVehiclesTable Render 1`] = `
<td <td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter" class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter"
> >
<a <div>
class="" <a
href="/" class=""
title="Delete \\"USWESTVIN12345670\\"" href="/"
> title="Delete \\"USWESTVIN12345670\\""
<svg
aria-hidden="true"
aria-label="Delete USWESTVIN12345670"
class="MuiSvgIcon-root"
focusable="false"
viewBox="0 0 24 24"
> >
<path <svg
d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z" aria-hidden="true"
/> aria-label="Delete USWESTVIN12345670"
</svg> class="MuiSvgIcon-root"
</a> focusable="false"
viewBox="0 0 24 24"
>
<path
d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"
/>
</svg>
</a>
<div />
</div>
</td> </td>
</tr> </tr>
</tbody> </tbody>

View File

@@ -1,5 +1,5 @@
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { Link } from 'react-router-dom'; import { Link } from "react-router-dom";
import { import {
Grid, Grid,
Table, Table,
@@ -15,24 +15,28 @@ import DeleteIcon from "@material-ui/icons/Delete";
import clsx from "clsx"; import clsx from "clsx";
import TableHeaderSortable from "../../../../Table/HeaderSortable"; import TableHeaderSortable from "../../../../Table/HeaderSortable";
import { useUserContext } from "../../../../Contexts/UserContext" import { useUserContext } from "../../../../Contexts/UserContext";
import { useStatusContext } from "../../../../Contexts/StatusContext"; import { useStatusContext } from "../../../../Contexts/StatusContext";
import { FleetProvider, useFleetContext } from "../../../../Contexts/FleetContext" import {
FleetProvider,
useFleetContext,
} from "../../../../Contexts/FleetContext";
import useStyles from "../../../../useStyles"; import useStyles from "../../../../useStyles";
import SearchField from "../../../../Controls/SearchField"; import SearchField from "../../../../Controls/SearchField";
import { logger } from "../../../../../services/monitoring"; import { logger } from "../../../../../services/monitoring";
import { Roles, hasRole } from "../../../../../utils/roles"; import { Roles, hasRole } from "../../../../../utils/roles";
import {useLocalStorage} from "../../../../useLocalStorage"; import { useLocalStorage } from "../../../../useLocalStorage";
import DeleteConfirmation from "../../../../DeleteConfirmation";
const tableColumns = [ const tableColumns = [
{ {
id: "vin", id: "vin",
label: "VIN" label: "VIN",
}, },
{ {
id: "", id: "",
label: "Actions" label: "Actions",
} },
]; ];
const PAGE_SIZE = "FLEET_STATUS_VEHICLES_TABLE_PAGE_SIZE"; const PAGE_SIZE = "FLEET_STATUS_VEHICLES_TABLE_PAGE_SIZE";
@@ -43,10 +47,21 @@ const MainForm = ({ name }) => {
const [orderBy, setOrderBy] = useState("id"); const [orderBy, setOrderBy] = useState("id");
const [order, setOrder] = useState("desc"); const [order, setOrder] = useState("desc");
const [search, setSearch] = useState(""); const [search, setSearch] = useState("");
const [showDeleteModal, setShowDeleteModal] = useState(false);
const classes = useStyles(); const classes = useStyles();
const { setMessage } = useStatusContext(); const { setMessage } = useStatusContext();
const { fleetVehicles, totalFleetVehicles, getFleetVehicles, deleteFleetVehicle } = useFleetContext(); const {
const { token: { idToken: { jwtToken: token } }, groups } = useUserContext(); fleetVehicles,
totalFleetVehicles,
getFleetVehicles,
deleteFleetVehicle,
} = useFleetContext();
const {
token: {
idToken: { jwtToken: token },
},
groups,
} = useUserContext();
const handleSearch = (query) => { const handleSearch = (query) => {
setSearch(query); setSearch(query);
@@ -103,7 +118,7 @@ const MainForm = ({ name }) => {
const onDelete = async (vin) => { const onDelete = async (vin) => {
try { try {
await deleteFleetVehicle(name, { vin: vin }, token); await deleteFleetVehicle(name, { vin: vin }, token);
setMessage(`Deleted ${vin}`) setMessage(`Deleted ${vin}`);
} catch (e) { } catch (e) {
setMessage(e.message); setMessage(e.message);
logger.warn(e.stack); logger.warn(e.stack);
@@ -116,8 +131,8 @@ const MainForm = ({ name }) => {
actions.push({ actions.push({
tip: `Delete "${vin}"`, tip: `Delete "${vin}"`,
id: vin, id: vin,
icon: <DeleteIcon aria-label={`Delete ${vin}`} /> icon: <DeleteIcon aria-label={`Delete ${vin}`} />,
}) });
} }
if (actions.length === 0) return ["No actions"]; if (actions.length === 0) return ["No actions"];
@@ -132,11 +147,19 @@ const MainForm = ({ name }) => {
); );
} else { } else {
return ( return (
<Tooltip key={`delete-${action.id}`} title={action.tip}> <div>
<Link to="#" onClick={() => onDelete(action.id)}> <Tooltip key={`delete-${action.id}`} title={action.tip}>
{action.icon} <Link to="#" onClick={() => onDelete(action.id)}>
</Link> {action.icon}
</Tooltip> </Link>
</Tooltip>
<DeleteConfirmation
message={action.id}
open={showDeleteModal}
close={() => setShowDeleteModal(false)}
deleteFunction={() => onDelete(action.id)}
/>
</div>
); );
} }
}); });
@@ -146,12 +169,15 @@ const MainForm = ({ name }) => {
<div className={clsx(classes.paper, classes.tableSize)}> <div className={clsx(classes.paper, classes.tableSize)}>
<Grid container className={classes.root} spacing={2}> <Grid container className={classes.root} spacing={2}>
<Grid item md={4} className={classes.textJustifyAlign}> <Grid item md={4} className={classes.textJustifyAlign}>
<Link to={`/fleet/${name}/vehicle-add`} className={classes.labelInline}> <Link
to={`/fleet/${name}/vehicle-add`}
className={classes.labelInline}
>
<AddCircleIcon fontSize="large" /> <AddCircleIcon fontSize="large" />
</Link> </Link>
</Grid> </Grid>
<Grid item md={8} align="right" className={classes.textCenterAlign}> <Grid item md={8} align="right" className={classes.textCenterAlign}>
<SearchField classes={classes} onSearch={handleSearch}/> <SearchField classes={classes} onSearch={handleSearch} />
</Grid> </Grid>
</Grid> </Grid>
<Table> <Table>
@@ -163,7 +189,7 @@ const MainForm = ({ name }) => {
onSortRequest={handleSort} onSortRequest={handleSort}
/> />
<TableBody> <TableBody>
{fleetVehicles.map(vin => ( {fleetVehicles.map((vin) => (
<TableRow key={vin}> <TableRow key={vin}>
<TableCell align="center"> <TableCell align="center">
<Link to={`/vehicle-status/${vin}`}>{vin}</Link> <Link to={`/vehicle-status/${vin}`}>{vin}</Link>
@@ -190,7 +216,7 @@ const MainForm = ({ name }) => {
</TableRow> </TableRow>
</TableFooter> </TableFooter>
</Table> </Table>
</div > </div>
); );
}; };

View File

@@ -135,6 +135,7 @@ exports[`DetailsTab Render 1`] = `
</a> </a>
</div> </div>
</div> </div>
<div />
</div> </div>
</div> </div>
</div> </div>

View File

@@ -152,23 +152,26 @@ exports[`VehiclesTab Render 1`] = `
<td <td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter" class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter"
> >
<a <div>
class="" <a
href="/" class=""
title="Delete \\"USWESTVIN12345678\\"" href="/"
> title="Delete \\"USWESTVIN12345678\\""
<svg
aria-hidden="true"
aria-label="Delete USWESTVIN12345678"
class="MuiSvgIcon-root"
focusable="false"
viewBox="0 0 24 24"
> >
<path <svg
d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z" aria-hidden="true"
/> aria-label="Delete USWESTVIN12345678"
</svg> class="MuiSvgIcon-root"
</a> focusable="false"
viewBox="0 0 24 24"
>
<path
d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"
/>
</svg>
</a>
<div />
</div>
</td> </td>
</tr> </tr>
<tr <tr
@@ -186,23 +189,26 @@ exports[`VehiclesTab Render 1`] = `
<td <td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter" class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter"
> >
<a <div>
class="" <a
href="/" class=""
title="Delete \\"USWESTVIN12345679\\"" href="/"
> title="Delete \\"USWESTVIN12345679\\""
<svg
aria-hidden="true"
aria-label="Delete USWESTVIN12345679"
class="MuiSvgIcon-root"
focusable="false"
viewBox="0 0 24 24"
> >
<path <svg
d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z" aria-hidden="true"
/> aria-label="Delete USWESTVIN12345679"
</svg> class="MuiSvgIcon-root"
</a> focusable="false"
viewBox="0 0 24 24"
>
<path
d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"
/>
</svg>
</a>
<div />
</div>
</td> </td>
</tr> </tr>
<tr <tr
@@ -220,23 +226,26 @@ exports[`VehiclesTab Render 1`] = `
<td <td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter" class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter"
> >
<a <div>
class="" <a
href="/" class=""
title="Delete \\"USWESTVIN12345670\\"" href="/"
> title="Delete \\"USWESTVIN12345670\\""
<svg
aria-hidden="true"
aria-label="Delete USWESTVIN12345670"
class="MuiSvgIcon-root"
focusable="false"
viewBox="0 0 24 24"
> >
<path <svg
d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z" aria-hidden="true"
/> aria-label="Delete USWESTVIN12345670"
</svg> class="MuiSvgIcon-root"
</a> focusable="false"
viewBox="0 0 24 24"
>
<path
d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"
/>
</svg>
</a>
<div />
</div>
</td> </td>
</tr> </tr>
</tbody> </tbody>

View File

@@ -124,6 +124,7 @@ exports[`FleetStatus Render 1`] = `
Name Name
</b> </b>
: :
Fleet Name
</p> </p>
<p> <p>
<b> <b>
@@ -187,13 +188,13 @@ exports[`FleetStatus Render 1`] = `
> >
<a <a
class="" class=""
href="/fleet-update?name=undefined" href="/fleet-update?name=Fleet Name"
style="margin: 5px;" style="margin: 5px;"
title="Update \\"undefined\\"" title="Update \\"Fleet Name\\""
> >
<svg <svg
aria-hidden="true" aria-hidden="true"
aria-label="Update \\"undefined\\"" aria-label="Update \\"Fleet Name\\""
class="MuiSvgIcon-root" class="MuiSvgIcon-root"
focusable="false" focusable="false"
viewBox="0 0 24 24" viewBox="0 0 24 24"
@@ -206,11 +207,11 @@ exports[`FleetStatus Render 1`] = `
<a <a
class="" class=""
href="/" href="/"
title="Delete \\"undefined\\"" title="Delete \\"Fleet Name\\""
> >
<svg <svg
aria-hidden="true" aria-hidden="true"
aria-label="Delete \\"undefined\\"" aria-label="Delete \\"Fleet Name\\""
class="MuiSvgIcon-root" class="MuiSvgIcon-root"
focusable="false" focusable="false"
viewBox="0 0 24 24" viewBox="0 0 24 24"
@@ -222,6 +223,7 @@ exports[`FleetStatus Render 1`] = `
</a> </a>
</div> </div>
</div> </div>
<div />
</div> </div>
</div> </div>
</div> </div>

View File

@@ -7,6 +7,7 @@ jest.mock("@material-ui/core/utils/unstable_useId", () =>
import { render, waitFor } from "@testing-library/react"; import { render, waitFor } from "@testing-library/react";
import { BrowserRouter } from "react-router-dom"; import { BrowserRouter } from "react-router-dom";
import routeData from "react-router";
import { FleetProvider } from "../../Contexts/FleetContext"; import { FleetProvider } from "../../Contexts/FleetContext";
import { StatusProvider } from "../../Contexts/StatusContext"; import { StatusProvider } from "../../Contexts/StatusContext";
@@ -38,6 +39,11 @@ describe("FleetStatus", () => {
addSnapshotSerializer(expect); addSnapshotSerializer(expect);
}); });
beforeEach(() => {
// Does not work if placed in beforeAll
jest.spyOn(routeData, 'useParams').mockReturnValue({ name: "Fleet Name" })
})
it("Render", async () => { it("Render", async () => {
setToken(TEST_AUTH_OBJECT); setToken(TEST_AUTH_OBJECT);
const container = await renderCarStatus(); const container = await renderCarStatus();

View File

@@ -30,6 +30,7 @@ import ECUList from "../../Controls/ECUList";
import { Roles, hasRole } from "../../../utils/roles"; import { Roles, hasRole } from "../../../utils/roles";
import { useLocalStorage } from "../../useLocalStorage"; import { useLocalStorage } from "../../useLocalStorage";
import { TYPE_MANIFEST_SOFTWARE } from "../../../utils/manifest_types"; import { TYPE_MANIFEST_SOFTWARE } from "../../../utils/manifest_types";
import DeleteConfirmation from "../../DeleteConfirmation";
const tableColumns = [ const tableColumns = [
{ {
@@ -67,6 +68,7 @@ const MainForm = () => {
const [orderBy, setOrderBy] = useState("id"); const [orderBy, setOrderBy] = useState("id");
const [order, setOrder] = useState("asc"); const [order, setOrder] = useState("asc");
const [search, setSearch] = useState(""); const [search, setSearch] = useState("");
const [showDeleteModal, setShowDeleteModal] = useState(false);
const { getManifests, deleteManifest, manifests, totalManifests } = const { getManifests, deleteManifest, manifests, totalManifests } =
useManifestsContext(); useManifestsContext();
const { setMessage, setTitle, setSitePath } = useStatusContext(); const { setMessage, setTitle, setSitePath } = useStatusContext();
@@ -178,11 +180,19 @@ const MainForm = () => {
); );
} else { } else {
return ( return (
<Tooltip key={`delete-${action.id}`} title={action.tip}> <div>
<Link to="#" onClick={() => onDelete(action.id)}> <Tooltip key={`delete-${action.id}`} title={action.tip}>
{action.icon} <Link to="#" onClick={() => onDelete(action.id)}>
</Link> {action.icon}
</Tooltip> </Link>
</Tooltip>
<DeleteConfirmation
message={action.id}
open={showDeleteModal}
close={() => setShowDeleteModal(false)}
deleteFunction={() => onDelete(action.id)}
/>
</div>
); );
} }
}); });

View File

@@ -10,7 +10,9 @@ import {
TableHead, TableHead,
TablePagination, TablePagination,
TableRow, TableRow,
Tooltip,
} from "@material-ui/core"; } from "@material-ui/core";
import CancelIcon from "@material-ui/icons/Cancel";
import clsx from "clsx"; import clsx from "clsx";
import { import {
@@ -27,9 +29,9 @@ import useStyles from "../../useStyles";
import { LocalDateTimeString } from "../../../utils/dates"; import { LocalDateTimeString } from "../../../utils/dates";
import { logger } from "../../../services/monitoring"; import { logger } from "../../../services/monitoring";
import ManifestDetails from "../Details"; import ManifestDetails from "../Details";
import {useLocalStorage} from "../../useLocalStorage"; import { useLocalStorage } from "../../useLocalStorage";
const PAGE_SIZE="MANIFEST_STATUS_PAGE_SIZE"; const PAGE_SIZE = "MANIFEST_STATUS_PAGE_SIZE";
const MainForm = () => { const MainForm = () => {
const { manifest_id } = useParams(); const { manifest_id } = useParams();
@@ -38,6 +40,7 @@ const MainForm = () => {
const [pageIndex, setPageIndex] = useState(0); const [pageIndex, setPageIndex] = useState(0);
const { getManifests, manifests } = useManifestsContext(); const { getManifests, manifests } = useManifestsContext();
const { const {
cancelUpdate,
getCarUpdates, getCarUpdates,
carUpdates, carUpdates,
totalCarUpdates, totalCarUpdates,
@@ -127,6 +130,15 @@ const MainForm = () => {
setPageIndex(0); setPageIndex(0);
}; };
const sendCancel = async ({ id, vin }) => {
try {
await cancelUpdate(id, token);
setMessage(`Sent cancel for ${vin}`);
} catch (e) {
setMessage(e.message);
}
};
return ( return (
<div className={clsx(classes.paper, classes.tableSize)}> <div className={clsx(classes.paper, classes.tableSize)}>
<Table> <Table>
@@ -137,6 +149,7 @@ const MainForm = () => {
<TableCell align="center">Status</TableCell> <TableCell align="center">Status</TableCell>
<TableCell align="center">Created</TableCell> <TableCell align="center">Created</TableCell>
<TableCell align="center">Updated</TableCell> <TableCell align="center">Updated</TableCell>
<TableCell align="center"></TableCell>
</TableRow> </TableRow>
</TableHead> </TableHead>
<TableBody> <TableBody>
@@ -158,6 +171,13 @@ const MainForm = () => {
<TableCell align="center"> <TableCell align="center">
{LocalDateTimeString(row.updated)} {LocalDateTimeString(row.updated)}
</TableCell> </TableCell>
<TableCell>
<Tooltip key={row.vin} title={`Send cancel for ${row.vin}`}>
<Link to="#" onClick={() => sendCancel(row)}>
<CancelIcon />
</Link>
</Tooltip>
</TableCell>
</TableRow> </TableRow>
))} ))}
</TableBody> </TableBody>
@@ -165,7 +185,7 @@ const MainForm = () => {
<TableRow> <TableRow>
<TablePagination <TablePagination
rowsPerPageOptions={[5, 10, 25, 100]} rowsPerPageOptions={[5, 10, 25, 100]}
colSpan={5} colSpan={6}
count={totalCarUpdates} count={totalCarUpdates}
rowsPerPage={pageSize} rowsPerPage={pageSize}
page={pageIndex} page={pageIndex}

View File

@@ -22,6 +22,10 @@ const updatesAPI = {
getCarUpdateProgress: async (carupdateids, token) => { getCarUpdateProgress: async (carupdateids, token) => {
return { statuses: [] }; return { statuses: [] };
}, },
cancelCarUpdate: async (id, token) => {
return { message: "OK" };
},
}; };
export default updatesAPI; export default updatesAPI;

View File

@@ -8,17 +8,18 @@ import {
const API_ENDPOINT = process.env.REACT_APP_UPLOAD_SERVICE_URL; const API_ENDPOINT = process.env.REACT_APP_UPLOAD_SERVICE_URL;
const createDeployUpdatesClosure = (suffix) => { const createDeployUpdatesClosure = (suffix) => {
return async (data, token) => fetch(`${API_ENDPOINT}/${suffix}`, { return async (data, token) =>
method: "POST", fetch(`${API_ENDPOINT}/${suffix}`, {
headers: Object.assign( method: "POST",
{ "Content-Type": "application/json" }, headers: Object.assign(
getAuthHeaderOptions(token) { "Content-Type": "application/json" },
), getAuthHeaderOptions(token)
body: JSON.stringify(data), ),
}) body: JSON.stringify(data),
.then(fetchRespHandler) })
.catch(errorHandler) .then(fetchRespHandler)
} .catch(errorHandler);
};
const updatesAPI = { const updatesAPI = {
createFleetUpdates: createDeployUpdatesClosure("fleetupdate"), createFleetUpdates: createDeployUpdatesClosure("fleetupdate"),
@@ -76,6 +77,18 @@ const updatesAPI = {
.then(fetchRespHandler) .then(fetchRespHandler)
.catch(errorHandler); .catch(errorHandler);
}, },
cancelCarUpdate: async (id, token) => {
return fetch(`${API_ENDPOINT}/carupdate/${id}/cancel`, {
method: "POST",
headers: Object.assign(
{ "Content-Type": "application/json" },
getAuthHeaderOptions(token)
),
})
.then(fetchRespHandler)
.catch(errorHandler);
},
}; };
export default updatesAPI; export default updatesAPI;