From 4632958a2421cdd9f066554e6feab0ce21cc5368 Mon Sep 17 00:00:00 2001 From: Tristan Timblin Date: Tue, 20 Jun 2023 14:27:26 -0700 Subject: [PATCH] CEC-4524: add bulk delete action (#364) * CEC-4524: add bulk delete action --- .../App/__snapshots__/App.test.js.snap | 1 + .../List/__snapshots__/index.test.jsx.snap | 1 + src/components/Cars/List/index.jsx | 32 ++++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/components/App/__snapshots__/App.test.js.snap b/src/components/App/__snapshots__/App.test.js.snap index 7205472..00e9ac4 100644 --- a/src/components/App/__snapshots__/App.test.js.snap +++ b/src/components/App/__snapshots__/App.test.js.snap @@ -12658,6 +12658,7 @@ exports[`App Route /vehicles authenticated 1`] = `
+
diff --git a/src/components/Cars/List/__snapshots__/index.test.jsx.snap b/src/components/Cars/List/__snapshots__/index.test.jsx.snap index af1eb20..fe97dcd 100644 --- a/src/components/Cars/List/__snapshots__/index.test.jsx.snap +++ b/src/components/Cars/List/__snapshots__/index.test.jsx.snap @@ -482,6 +482,7 @@ exports[`VehicleTable Render 1`] = ` +
diff --git a/src/components/Cars/List/index.jsx b/src/components/Cars/List/index.jsx index 41485da..e2adbb4 100644 --- a/src/components/Cars/List/index.jsx +++ b/src/components/Cars/List/index.jsx @@ -17,6 +17,7 @@ import TransformModal from "../../TransformModal"; import { useLocalStorage } from "../../useLocalStorage"; import useStyles from "../../useStyles"; import TaskRunner from "../../../utils/taskRunner"; +import GeneralConfirmation from "../../GeneralConfirmation"; const MainForm = () => { const classes = useStyles(); @@ -93,6 +94,23 @@ const MainForm = () => { .catch((error) => setMessage(error.message)); }; + const handleDelete = async (fn) => { + const taskRunner = new TaskRunner(5); + const request = (vin) => { + return async () => { + return fn(vin, token) + .then(() => { + setMessage(`Deleted ${selectedVins.length} vehicles`); + setSelectedVins([]); + }) + .catch((error) => { + setMessage(error.message); + }) + } + } + selectedVins.forEach((vin) => taskRunner.push(request(vin))); + }; + const actions = [ { name: "Update Configs", @@ -103,7 +121,12 @@ const MainForm = () => { name: "Add Tags", disabled: selectedVins.length === 0, trigger: () => setActiveModal("addTags"), - } + }, + { + name: "Delete", + disabled: selectedVins.length === 0, + trigger: () => setActiveModal("delete"), + }, ]; const handleOnlineHMI = (event) => { @@ -187,6 +210,13 @@ const MainForm = () => { setData={setTagsToAdd} submit={() => handleAddTags(context.addTags)} /> + setActiveModal(null)} + title="Delete" + message={`You are about to delete the following VINs: ${selectedVins.join(", ")}`} + actionFunction={() => handleDelete(context.deleteVehicle)} + /> )}