Merge pull request #519 from Fisker-Inc/CEC-5898
CEC-5898 - Bulk action to update flashpack numbers for fleet cars
This commit is contained in:
@@ -0,0 +1,36 @@
|
|||||||
|
import { forwardRef, useImperativeHandle } from "react";
|
||||||
|
import { useStatusContext } from "../../Contexts/StatusContext";
|
||||||
|
import { useUserContext } from "../../Contexts/UserContext";
|
||||||
|
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 vehiclesAPI
|
||||||
|
.flashpackVersionBulkUpdate(ids, token)
|
||||||
|
.then((data) => {
|
||||||
|
if (data.error) {
|
||||||
|
setMessage(`${data.error}: ${data.message}`);
|
||||||
|
} else if (ids.length === 1) {
|
||||||
|
setMessage(`Updating flashpack number for ${ids[0]}`);
|
||||||
|
} else {
|
||||||
|
setMessage(`Updating flashpack numbers for ${ids.length} cars`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
You are updating flashpack numbers for the following VINs: {idCSV}.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
});
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
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 UpdateFlashpackNumbers from "./UpdateFlashpackNumbers";
|
||||||
|
import vehiclesAPI from "../../../services/vehiclesAPI";
|
||||||
|
|
||||||
|
describe("BulkActions/UpdateFlashpackNumbers", () => {
|
||||||
|
beforeAll(() => {
|
||||||
|
setToken(TEST_AUTH_OBJECT_FISKER);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("makes request to update flashpack numbers", async () => {
|
||||||
|
const flashpackVersionBulkUpdate = jest.spyOn(vehiclesAPI, "flashpackVersionBulkUpdate");
|
||||||
|
const ref = React.createRef();
|
||||||
|
|
||||||
|
const vins = ["TESTVIN123456789a", "TESTVIN123456789b", "TESTVIN123456789c"];
|
||||||
|
|
||||||
|
render(
|
||||||
|
<StatusProvider>
|
||||||
|
<UserProvider>
|
||||||
|
<UpdateFlashpackNumbers
|
||||||
|
ref={ref}
|
||||||
|
ids={vins}
|
||||||
|
idCSV=""
|
||||||
|
/>
|
||||||
|
</UserProvider>
|
||||||
|
</StatusProvider>
|
||||||
|
);
|
||||||
|
|
||||||
|
await act(async () => ref.current.submit());
|
||||||
|
expect(flashpackVersionBulkUpdate).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -15,6 +15,7 @@ const RemoteCommand = lazy(() => import("./actions/RemoteCommand"));
|
|||||||
const SendSMS = lazy(() => import("./actions/SendSMS"));
|
const SendSMS = lazy(() => import("./actions/SendSMS"));
|
||||||
const UpdateConfig = lazy(() => import("./actions/UpdateConfig"));
|
const UpdateConfig = lazy(() => import("./actions/UpdateConfig"));
|
||||||
const UpdateFleetVehicles = lazy(() => import("./actions/UpdateFleetVehicles"));
|
const UpdateFleetVehicles = lazy(() => import("./actions/UpdateFleetVehicles"));
|
||||||
|
const UpdateFlashpackNumbers = lazy(() => import("./actions/UpdateFlashpackNumbers"));
|
||||||
|
|
||||||
export default function BulkActions({
|
export default function BulkActions({
|
||||||
ids = [],
|
ids = [],
|
||||||
@@ -79,6 +80,12 @@ export default function BulkActions({
|
|||||||
disabled: false,
|
disabled: false,
|
||||||
trigger: () => setActive("updateFleetVehicles"),
|
trigger: () => setActive("updateFleetVehicles"),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "updateFlashpackNumbers",
|
||||||
|
name: "Update Flashpack Numbers",
|
||||||
|
disabled: false,
|
||||||
|
trigger: () => setActive("updateFlashpackNumbers")
|
||||||
|
}
|
||||||
].filter((action) => actions.includes(action.id));
|
].filter((action) => actions.includes(action.id));
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
@@ -127,6 +134,7 @@ export default function BulkActions({
|
|||||||
{active === "sms" && <SendSMS {...payload} />}
|
{active === "sms" && <SendSMS {...payload} />}
|
||||||
{active === "updateConfig" && <UpdateConfig {...payload} />}
|
{active === "updateConfig" && <UpdateConfig {...payload} />}
|
||||||
{active === "updateFleetVehicles" && <UpdateFleetVehicles {...payload} />}
|
{active === "updateFleetVehicles" && <UpdateFleetVehicles {...payload} />}
|
||||||
|
{active === "updateFlashpackNumbers" && <UpdateFlashpackNumbers {...payload} />}
|
||||||
</section>
|
</section>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ const MainForm = ({ name }) => {
|
|||||||
</Grid>
|
</Grid>
|
||||||
<Grid item md={4}>
|
<Grid item md={4}>
|
||||||
<BulkActions
|
<BulkActions
|
||||||
actions={["updateFleetVehicles", "addTags", "sms", "updateConfig", "remoteCommand", "diagnostic"]}
|
actions={["updateFleetVehicles", "addTags", "sms", "updateConfig", "remoteCommand", "diagnostic", "updateFlashpackNumbers"]}
|
||||||
ids={selected}
|
ids={selected}
|
||||||
fleet={name}
|
fleet={name}
|
||||||
callback={bulkActionCallback}
|
callback={bulkActionCallback}
|
||||||
|
|||||||
@@ -230,6 +230,9 @@ const vehiclesAPI = {
|
|||||||
deleteFlashpackECUMapping: async (data, token) => {
|
deleteFlashpackECUMapping: async (data, token) => {
|
||||||
return { message: "Deleted" };
|
return { message: "Deleted" };
|
||||||
},
|
},
|
||||||
|
flashpackVersionBulkUpdate: async (data, token) => {
|
||||||
|
return { message: "Updated" }
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default vehiclesAPI;
|
export default vehiclesAPI;
|
||||||
|
|||||||
@@ -340,6 +340,18 @@ const vehiclesAPI = {
|
|||||||
}).then(fetchRespHandler)
|
}).then(fetchRespHandler)
|
||||||
.catch(errorHandler)
|
.catch(errorHandler)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
flashpackVersionBulkUpdate: async (vins, token) => {
|
||||||
|
return fetch(`${API_ENDPOINT}/flashpack_version_bulk_update`, {
|
||||||
|
method: "PUT",
|
||||||
|
headers: Object.assign(
|
||||||
|
{ "Content-Type": "application/json" },
|
||||||
|
getAuthHeaderOptions(token),
|
||||||
|
),
|
||||||
|
body: JSON.stringify({ vins }),
|
||||||
|
}).then(fetchRespHandler)
|
||||||
|
.catch(errorHandler)
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default vehiclesAPI;
|
export default vehiclesAPI;
|
||||||
|
|||||||
Reference in New Issue
Block a user