delete working
This commit is contained in:
@@ -304,11 +304,11 @@ export const VehicleProvider = ({ children }) => {
|
|||||||
if (options && options.offset === 0 && result.total) {
|
if (options && options.offset === 0 && result.total) {
|
||||||
setTotalFlashpacks(result.total);
|
setTotalFlashpacks(result.total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
} finally {
|
} finally {
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const getFlashpackECUMappings = async (model, year, flashpack, options, token) => {
|
const getFlashpackECUMappings = async (model, year, flashpack, options, token) => {
|
||||||
@@ -324,11 +324,33 @@ export const VehicleProvider = ({ children }) => {
|
|||||||
if (options && options.offset === 0 && result.total) {
|
if (options && options.offset === 0 && result.total) {
|
||||||
setTotalFlashpackECUMappings(result.total);
|
setTotalFlashpackECUMappings(result.total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
} finally {
|
||||||
|
setBusy(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteFlashpackVersion = async (model, year, flashpack, token) => {
|
||||||
|
let result;
|
||||||
|
try {
|
||||||
|
setBusy(true);
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
"car_model": model,
|
||||||
|
"car_year": year,
|
||||||
|
"flashpack": flashpack,
|
||||||
|
}
|
||||||
|
|
||||||
|
result = await api.deleteFlashpackVersion(data, token);
|
||||||
|
if (result.error)
|
||||||
|
throw new Error(`Delete flashpack ecu mappings error. ${result.message}`);
|
||||||
|
|
||||||
|
return result;
|
||||||
} finally {
|
} finally {
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -366,6 +388,7 @@ export const VehicleProvider = ({ children }) => {
|
|||||||
totalFlashpackECUMappings,
|
totalFlashpackECUMappings,
|
||||||
flashpackECUMappings,
|
flashpackECUMappings,
|
||||||
getFlashpackECUMappings,
|
getFlashpackECUMappings,
|
||||||
|
deleteFlashpackVersion,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
0
src/components/Flashpack/Add/index.jsx
Normal file
0
src/components/Flashpack/Add/index.jsx
Normal file
@@ -1,4 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
|
Grid,
|
||||||
|
IconButton,
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableCell,
|
TableCell,
|
||||||
@@ -6,6 +8,9 @@ import {
|
|||||||
TablePagination,
|
TablePagination,
|
||||||
TableRow,
|
TableRow,
|
||||||
} from "@material-ui/core";
|
} from "@material-ui/core";
|
||||||
|
import AddCircleIcon from "@material-ui/icons/AddCircle";
|
||||||
|
import DeleteIcon from "@material-ui/icons/Delete";
|
||||||
|
import clsx from "clsx";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import { logger } from "../../services/monitoring";
|
import { logger } from "../../services/monitoring";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
@@ -14,6 +19,8 @@ import { useStatusContext } from "../Contexts/StatusContext";
|
|||||||
import { useUserContext } from "../Contexts/UserContext";
|
import { useUserContext } from "../Contexts/UserContext";
|
||||||
import TableHeaderSortable from "../Table/HeaderSortable";
|
import TableHeaderSortable from "../Table/HeaderSortable";
|
||||||
import { useLocalStorage } from "../useLocalStorage";
|
import { useLocalStorage } from "../useLocalStorage";
|
||||||
|
import DeleteConfirmation from "../DeleteConfirmation";
|
||||||
|
import { RoleWrap } from "../Controls/RoleWrap";
|
||||||
import useStyles from "../useStyles";
|
import useStyles from "../useStyles";
|
||||||
|
|
||||||
const tableColumns = [
|
const tableColumns = [
|
||||||
@@ -38,17 +45,20 @@ const MainForm = () => {
|
|||||||
const { setMessage, setTitle, setSitePath } = useStatusContext();
|
const { setMessage, setTitle, setSitePath } = useStatusContext();
|
||||||
const [pageSize, setPageSize] = useLocalStorage(PAGE_SIZE, 10);
|
const [pageSize, setPageSize] = useLocalStorage(PAGE_SIZE, 10);
|
||||||
const [pageIndex, setPageIndex] = useState(0);
|
const [pageIndex, setPageIndex] = useState(0);
|
||||||
const [orderBy, setOrderBy] = useState("flashpack");
|
const [showDeleteModal, setShowDeleteModal] = useState(false);
|
||||||
const [order, setOrder] = useState("desc");
|
const [rowToDelete, setRowToDelete] = useState({});
|
||||||
const {
|
const {
|
||||||
getAllFlashpacks,
|
getAllFlashpacks,
|
||||||
flashpacks,
|
flashpacks,
|
||||||
totalFlashpacks,
|
totalFlashpacks,
|
||||||
|
deleteFlashpackVersion,
|
||||||
} = useVehicleContext();
|
} = useVehicleContext();
|
||||||
const {
|
const {
|
||||||
token: {
|
token: {
|
||||||
idToken: { jwtToken: token },
|
idToken: { jwtToken: token },
|
||||||
},
|
},
|
||||||
|
groups,
|
||||||
|
providers,
|
||||||
} = useUserContext();
|
} = useUserContext();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -65,7 +75,7 @@ const MainForm = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadFlashpacks();
|
loadFlashpacks();
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [token, token, pageIndex, pageSize, orderBy, order]);
|
}, [token, token, pageIndex, pageSize]);
|
||||||
|
|
||||||
const loadFlashpacks = async () => {
|
const loadFlashpacks = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -74,7 +84,6 @@ const MainForm = () => {
|
|||||||
{
|
{
|
||||||
limit: pageSize,
|
limit: pageSize,
|
||||||
offset: pageSize * pageIndex,
|
offset: pageSize * pageIndex,
|
||||||
order: `${orderBy} ${order}`,
|
|
||||||
},
|
},
|
||||||
token
|
token
|
||||||
);
|
);
|
||||||
@@ -93,8 +102,35 @@ const MainForm = () => {
|
|||||||
setPageIndex(0);
|
setPageIndex(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onDeleteClick = (row) => {
|
||||||
|
setRowToDelete(row);
|
||||||
|
setShowDeleteModal(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
const sendDelete = async () => {
|
||||||
|
if (rowToDelete) {
|
||||||
|
try {
|
||||||
|
const result = await deleteFlashpackVersion(rowToDelete.car_model, rowToDelete.car_year, rowToDelete.flashpack, token);
|
||||||
|
if (!result || result.error) return;
|
||||||
|
|
||||||
|
setMessage(`Deleted ${rowToDelete.car_year} ${rowToDelete.car_model} ${rowToDelete.flashpack}`);
|
||||||
|
loadFlashpacks();
|
||||||
|
} catch (e) {
|
||||||
|
setMessage(e.message);
|
||||||
|
logger.warn(e.stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
<Grid container className={classes.root} spacing={2}>
|
||||||
|
<Grid item md={4} className={clsx(classes.textJustifyAlign, classes.actionsBar)}>
|
||||||
|
<Link to={`/tools/flashpack/add`} className={classes.labelInline}>
|
||||||
|
<AddCircleIcon fontSize="large" />
|
||||||
|
</Link>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeaderSortable
|
<TableHeaderSortable
|
||||||
classes={classes}
|
classes={classes}
|
||||||
@@ -114,6 +150,22 @@ const MainForm = () => {
|
|||||||
<TableCell align="center">
|
<TableCell align="center">
|
||||||
{row.car_year}
|
{row.car_year}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<RoleWrap
|
||||||
|
groups={groups}
|
||||||
|
providers={providers}
|
||||||
|
rolesPerProvider={Permissions.FiskerDelete}
|
||||||
|
>
|
||||||
|
<IconButton
|
||||||
|
onClick={() => onDeleteClick(row)}
|
||||||
|
aria-label={`Send delete for ${row.car_year} ${row.car_model} ${row.flashpack}`}
|
||||||
|
size="small"
|
||||||
|
color="primary"
|
||||||
|
>
|
||||||
|
<DeleteIcon aria-label={`Delete ${row.car_year} ${row.car_model} ${row.flashpack}`} />
|
||||||
|
</IconButton>
|
||||||
|
</RoleWrap>
|
||||||
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
@@ -138,6 +190,12 @@ const MainForm = () => {
|
|||||||
</TableRow>
|
</TableRow>
|
||||||
</TableFooter>
|
</TableFooter>
|
||||||
</Table>
|
</Table>
|
||||||
|
<DeleteConfirmation
|
||||||
|
message={rowToDelete && rowToDelete.car_year + " " + rowToDelete.car_model + " " + rowToDelete.flashpack}
|
||||||
|
open={showDeleteModal}
|
||||||
|
close={() => setShowDeleteModal(false)}
|
||||||
|
deleteFunction={sendDelete}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ const SuppliersList = React.lazy(() => import("../Suppliers/List"));
|
|||||||
const SupplierDetails = React.lazy(() => import("../Suppliers/Details"));
|
const SupplierDetails = React.lazy(() => import("../Suppliers/Details"));
|
||||||
const Flashpacks = React.lazy(() => import("../Flashpack"));
|
const Flashpacks = React.lazy(() => import("../Flashpack"));
|
||||||
const FlashpackDetails = React.lazy(() => import("../Flashpack/Details"));
|
const FlashpackDetails = React.lazy(() => import("../Flashpack/Details"));
|
||||||
|
const FlashpackAdd = React.lazy(() => import("../Flashpack/Add"))
|
||||||
const Datascope = React.lazy(() => import("../Dashboard"));
|
const Datascope = React.lazy(() => import("../Dashboard"));
|
||||||
const SumsRxSwin = React.lazy(() => import("../SUMS"));
|
const SumsRxSwin = React.lazy(() => import("../SUMS"));
|
||||||
const SumsRxSwinAdd = React.lazy(() => import("../SUMS/Add"));
|
const SumsRxSwinAdd = React.lazy(() => import("../SUMS/Add"));
|
||||||
@@ -300,6 +301,15 @@ const SiteRoutes = () => {
|
|||||||
rolesPerGroup={Permissions.FiskerRead}
|
rolesPerGroup={Permissions.FiskerRead}
|
||||||
providers={providers}
|
providers={providers}
|
||||||
/>
|
/>
|
||||||
|
<AuthRoute
|
||||||
|
path="/tools/flashpack/add"
|
||||||
|
render={() => <FlashpackAdd />}
|
||||||
|
type={TYPES.PROTECTED}
|
||||||
|
token={token}
|
||||||
|
groups={groups}
|
||||||
|
rolesPerGroup={Permissions.FiskerCreate}
|
||||||
|
providers={providers}
|
||||||
|
/>
|
||||||
<AuthRoute
|
<AuthRoute
|
||||||
path="/suppliers"
|
path="/suppliers"
|
||||||
render={() => <SuppliersList />}
|
render={() => <SuppliersList />}
|
||||||
|
|||||||
@@ -295,8 +295,8 @@ const vehiclesAPI = {
|
|||||||
.catch(errorHandler)
|
.catch(errorHandler)
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteFlashpackECUMapping: async (data, token) => {
|
deleteFlashpackVersion: async (data, token) => {
|
||||||
return fetch(`${API_ENDPOINT}/flashpack_ecu_mapping`, {
|
return fetch(`${API_ENDPOINT}/flashpack_version`, {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: Object.assign(
|
headers: Object.assign(
|
||||||
{ "Content-Type": "application/json" },
|
{ "Content-Type": "application/json" },
|
||||||
|
|||||||
Reference in New Issue
Block a user