further improvements
This commit is contained in:
@@ -309,6 +309,26 @@ export const VehicleProvider = ({ children }) => {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getFlashpackECUMappings = async (flashpack, model, year, options, token) => {
|
||||||
|
let result;
|
||||||
|
try {
|
||||||
|
setBusy(true);
|
||||||
|
|
||||||
|
result = await api.getAllFlashpacks(options, token);
|
||||||
|
if (result.error)
|
||||||
|
throw new Error(`Get all flashpacks error. ${result.message}`);
|
||||||
|
|
||||||
|
setFlashpacks(result.data);
|
||||||
|
if (options && options.offset === 0 && result.total) {
|
||||||
|
setTotalFlashpacks(result.total);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
setBusy(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<VehicleContext.Provider
|
<VehicleContext.Provider
|
||||||
value={{
|
value={{
|
||||||
@@ -341,7 +361,7 @@ export const VehicleProvider = ({ children }) => {
|
|||||||
flashpacks,
|
flashpacks,
|
||||||
totalFlashpacks,
|
totalFlashpacks,
|
||||||
getAllFlashpacks,
|
getAllFlashpacks,
|
||||||
// getFlashpackECUMappings,
|
getFlashpackECUMappings,
|
||||||
// addFlashpackECUMapping,
|
// addFlashpackECUMapping,
|
||||||
// deleteFlashpackECUMapping,
|
// deleteFlashpackECUMapping,
|
||||||
}}
|
}}
|
||||||
|
|||||||
159
src/components/Flashpack/Details/index.jsx
Normal file
159
src/components/Flashpack/Details/index.jsx
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableFooter,
|
||||||
|
TablePagination,
|
||||||
|
TableRow,
|
||||||
|
} from "@material-ui/core";
|
||||||
|
import { logger } from "../../../services/monitoring";
|
||||||
|
import React, { useEffect, useState } from "react";
|
||||||
|
import { useVehicleContext, VehicleProvider } from "../../Contexts/VehicleContext";
|
||||||
|
import { useStatusContext } from "../../Contexts/StatusContext";
|
||||||
|
import { useUserContext } from "../../Contexts/UserContext";
|
||||||
|
import TableHeaderSortable from "../../Table/HeaderSortable";
|
||||||
|
import { useLocalStorage } from "../../useLocalStorage";
|
||||||
|
import useStyles from "../../useStyles";
|
||||||
|
|
||||||
|
const tableColumns = [
|
||||||
|
{
|
||||||
|
id: "ecu_name",
|
||||||
|
label: "ECU Name",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "ecu_version",
|
||||||
|
label: "ECU Version",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const PAGE_SIZE = "FLASHPACK_MAPPINGS_TABLE_PAGE_SIZE";
|
||||||
|
|
||||||
|
const MainForm = () => {
|
||||||
|
const classes = useStyles();
|
||||||
|
const { setMessage, setTitle, setSitePath } = useStatusContext();
|
||||||
|
const [pageSize, setPageSize] = useLocalStorage(PAGE_SIZE, 10);
|
||||||
|
const [pageIndex, setPageIndex] = useState(0);
|
||||||
|
const [orderBy, setOrderBy] = useState("flashpack");
|
||||||
|
const [order, setOrder] = useState("desc");
|
||||||
|
const {
|
||||||
|
getAllFlashpacks,
|
||||||
|
flashpacks,
|
||||||
|
totalFlashpacks,
|
||||||
|
} = useVehicleContext();
|
||||||
|
const {
|
||||||
|
token: {
|
||||||
|
idToken: { jwtToken: token },
|
||||||
|
},
|
||||||
|
} = useUserContext();
|
||||||
|
const { flashpack } = useParams();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setTitle(`Flashpack ${flashpack}`);
|
||||||
|
setSitePath([
|
||||||
|
{
|
||||||
|
label: `Flashpack ${flashpack}`,
|
||||||
|
link: `/tools/flashpack/${flashpack}`,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
loadFlashpacks();
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [token, token, pageIndex, pageSize, orderBy, order]);
|
||||||
|
|
||||||
|
const loadFlashpacks = async () => {
|
||||||
|
try {
|
||||||
|
if (!token) return;
|
||||||
|
await getAllFlashpacks(
|
||||||
|
{
|
||||||
|
limit: pageSize,
|
||||||
|
offset: pageSize * pageIndex,
|
||||||
|
order: `${orderBy} ${order}`,
|
||||||
|
},
|
||||||
|
token
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
setMessage(e.message);
|
||||||
|
logger.warn(e.stack);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChangePageIndex = (event, newIndex) => {
|
||||||
|
setPageIndex(newIndex);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChangePageSize = (event) => {
|
||||||
|
setPageSize(parseInt(event.target.value, 10));
|
||||||
|
setPageIndex(0);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSort = (event, property) => {
|
||||||
|
try {
|
||||||
|
if (property === orderBy) {
|
||||||
|
if (order === "asc") {
|
||||||
|
setOrder("desc");
|
||||||
|
} else {
|
||||||
|
setOrder("asc");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setOrderBy(property);
|
||||||
|
setOrder("asc");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logger.warn(e.stack);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Table>
|
||||||
|
<TableHeaderSortable
|
||||||
|
classes={classes}
|
||||||
|
orderBy={orderBy}
|
||||||
|
order={order}
|
||||||
|
columnData={tableColumns}
|
||||||
|
onSortRequest={handleSort}
|
||||||
|
/>
|
||||||
|
<TableBody>
|
||||||
|
{flashpacks && flashpacks.map((row, index) => (
|
||||||
|
<TableRow key={index}>
|
||||||
|
<TableCell align="center">
|
||||||
|
{row}
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableBody>
|
||||||
|
<TableFooter>
|
||||||
|
<TableRow>
|
||||||
|
{!flashpacks || flashpacks.length === 0 ? (
|
||||||
|
<TableCell colSpan={8} align="center">No Flashpack Numbers</TableCell>
|
||||||
|
) : (
|
||||||
|
<TablePagination
|
||||||
|
rowsPerPageOptions={[5, 10, 25, 100]}
|
||||||
|
colSpan={1}
|
||||||
|
count={totalFlashpacks}
|
||||||
|
rowsPerPage={pageSize}
|
||||||
|
page={pageIndex}
|
||||||
|
SelectProps={{
|
||||||
|
inputProps: { "aria-label": "rows per page" },
|
||||||
|
native: true,
|
||||||
|
}}
|
||||||
|
onPageChange={handleChangePageIndex}
|
||||||
|
onRowsPerPageChange={handleChangePageSize}
|
||||||
|
/>)}
|
||||||
|
</TableRow>
|
||||||
|
</TableFooter>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const FlashpackDetails = () => (
|
||||||
|
<VehicleProvider>
|
||||||
|
<MainForm />
|
||||||
|
</VehicleProvider>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default FlashpackDetails;
|
||||||
@@ -46,7 +46,7 @@ const MainForm = () => {
|
|||||||
setTitle("Flashpacks");
|
setTitle("Flashpacks");
|
||||||
setSitePath([
|
setSitePath([
|
||||||
{
|
{
|
||||||
label: "Tools",
|
label: "Flashpacks",
|
||||||
link: "/tools/flashpacks",
|
link: "/tools/flashpacks",
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ const SMSSend = React.lazy(() => import("../SMS/Send"));
|
|||||||
const SuppliersList = React.lazy(() => import("../Suppliers/List"));
|
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 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"));
|
||||||
@@ -290,15 +291,15 @@ const SiteRoutes = () => {
|
|||||||
rolesPerGroup={Permissions.FiskerRead}
|
rolesPerGroup={Permissions.FiskerRead}
|
||||||
providers={providers}
|
providers={providers}
|
||||||
/>
|
/>
|
||||||
{/* <AuthRoute
|
<AuthRoute
|
||||||
path="/tools/flashpack/:flashpack"
|
path="/tools/flashpack/:flashpack"
|
||||||
render={() => <Flashpack />}
|
render={() => <FlashpackDetails />}
|
||||||
type={TYPES.PROTECTED}
|
type={TYPES.PROTECTED}
|
||||||
token={token}
|
token={token}
|
||||||
groups={groups}
|
groups={groups}
|
||||||
rolesPerGroup={Permissions.FiskerCreate}
|
rolesPerGroup={Permissions.FiskerCreate}
|
||||||
providers={providers}
|
providers={providers}
|
||||||
/> */}
|
/>
|
||||||
<AuthRoute
|
<AuthRoute
|
||||||
path="/suppliers"
|
path="/suppliers"
|
||||||
render={() => <SuppliersList />}
|
render={() => <SuppliersList />}
|
||||||
|
|||||||
Reference in New Issue
Block a user