CEC-5421: remove delete functionality (#482)
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
import { forwardRef, useImperativeHandle } from "react";
|
||||
import { useStatusContext } from "../../Contexts/StatusContext";
|
||||
import { useUserContext } from "../../Contexts/UserContext";
|
||||
import TaskRunner from "../../../utils/taskRunner";
|
||||
import vehiclesAPI from "../../../services/vehiclesAPI";
|
||||
|
||||
export default forwardRef(({
|
||||
ids,
|
||||
idCSV,
|
||||
}, ref) => {
|
||||
const { setMessage } = useStatusContext();
|
||||
const { token: { idToken: { jwtToken: token } } } = useUserContext();
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
async submit() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const taskRunner = new TaskRunner(5, ids.length);
|
||||
let errorCount = 0;
|
||||
|
||||
const task = (vin, index) => {
|
||||
const progressMessage = `${index + 1}/${ids.length}`;
|
||||
return async () => vehiclesAPI.deleteVehicle(vin, token)
|
||||
.then((response) => {
|
||||
if (response.error) {
|
||||
errorCount += 1;
|
||||
setMessage(`${progressMessage} ${response.error}: ${response.message}`);
|
||||
} else {
|
||||
setMessage(`${progressMessage} Deleted ${vin}`);
|
||||
}
|
||||
return response;
|
||||
})
|
||||
.catch((error) => reject(error));
|
||||
}
|
||||
|
||||
ids.forEach((vin, i) => {
|
||||
taskRunner.push(task(vin, i));
|
||||
});
|
||||
|
||||
taskRunner.onComplete().then((responses) => {
|
||||
const completeMessage = `${ids.length - errorCount}/${ids.length}`;
|
||||
setMessage(`Successfully deleted ${completeMessage} vehicles.`);
|
||||
resolve(responses);
|
||||
});
|
||||
});
|
||||
},
|
||||
}));
|
||||
|
||||
return (
|
||||
<div>
|
||||
<p>
|
||||
You are about to delete the following VINs: {idCSV}.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
@@ -1,40 +0,0 @@
|
||||
jest.mock("../../Contexts/UserContext");
|
||||
jest.mock("../../Contexts/StatusContext");
|
||||
jest.mock("../../../services/vehiclesAPI");
|
||||
|
||||
import React from "react";
|
||||
import {
|
||||
render,
|
||||
act,
|
||||
} from "@testing-library/react";
|
||||
import { UserProvider, setToken } from "../../Contexts/UserContext";
|
||||
import { StatusProvider } from "../../Contexts/StatusContext";
|
||||
import { TEST_AUTH_OBJECT_FISKER } from "../../../utils/testing";
|
||||
import DeleteVehicles from "./DeleteVehicles";
|
||||
import vehiclesAPI from "../../../services/vehiclesAPI";
|
||||
|
||||
describe("BulkActions/DeleteVehicles", () => {
|
||||
beforeAll(() => {
|
||||
setToken(TEST_AUTH_OBJECT_FISKER);
|
||||
});
|
||||
|
||||
it("makes request to delete multiple vehicles", async () => {
|
||||
const api = jest.spyOn(vehiclesAPI, "deleteVehicle");
|
||||
const ref = React.createRef();
|
||||
|
||||
render(
|
||||
<StatusProvider>
|
||||
<UserProvider>
|
||||
<DeleteVehicles
|
||||
ref={ref}
|
||||
ids={["TESTVIN123456789a", "TESTVIN123456789b", "TESTVIN123456789c"]}
|
||||
idCSV=""
|
||||
/>
|
||||
</UserProvider>
|
||||
</StatusProvider>
|
||||
);
|
||||
|
||||
await act(async () => ref.current.submit());
|
||||
expect(api).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
});
|
||||
@@ -9,7 +9,6 @@ import truncateCSV from "../../utils/truncateCSV";
|
||||
// https://react.dev/reference/react/lazy
|
||||
const AddTags = lazy(() => import("./actions/AddTags"));
|
||||
const AddToFleet = lazy(() => import("./actions/AddToFleet"));
|
||||
const DeleteVehicles = lazy(() => import("./actions/DeleteVehicles"));
|
||||
const UpdateConfig = lazy(() => import("./actions/UpdateConfig"));
|
||||
const SendSMS = lazy(() => import("./actions/SendSMS"));
|
||||
const Cancel = lazy(() => import("./actions/Cancel"));
|
||||
@@ -41,12 +40,6 @@ export default function BulkActions({
|
||||
disabled: false,
|
||||
trigger: () => setActive("addToFleet"),
|
||||
},
|
||||
{
|
||||
id: "deleteVehicles",
|
||||
name: "Delete",
|
||||
disabled: false,
|
||||
trigger: () => setActive("deleteVehicles"),
|
||||
},
|
||||
{
|
||||
id: "updateConfig",
|
||||
name: "Update Config",
|
||||
@@ -125,7 +118,6 @@ export default function BulkActions({
|
||||
<section>
|
||||
{active === "addTags" && <AddTags {...payload} />}
|
||||
{active === "addToFleet" && <AddToFleet {...payload} />}
|
||||
{active === "deleteVehicles" && <DeleteVehicles {...payload} />}
|
||||
{active === "updateConfig" && <UpdateConfig {...payload} />}
|
||||
{active === "sms" && <SendSMS {...payload} />}
|
||||
{active === "cancel" && <Cancel {...payload} />}
|
||||
|
||||
Reference in New Issue
Block a user