CEC-6051 - Select All for fleet bulk actions

This commit is contained in:
padamsen_fisker
2024-05-21 13:58:10 -04:00
parent 207b4c776d
commit 80a338c7b4
3 changed files with 16 additions and 23 deletions

View File

@@ -18,7 +18,7 @@ const DropDownButton = ({ actions = [], payload = [], onClick = () => { } }) =>
const handleClick = () => { const handleClick = () => {
onClick() onClick()
actions[selectedIndex].trigger(...payload); actions[selectedIndex] ? actions[selectedIndex].trigger(...payload) : actions[0].trigger(...payload)
}; };
const handleMenuItemClick = (event, index) => { const handleMenuItemClick = (event, index) => {
@@ -55,9 +55,9 @@ const DropDownButton = ({ actions = [], payload = [], onClick = () => { } }) =>
> >
<Button <Button
onClick={handleClick} onClick={handleClick}
disabled={actions[selectedIndex].disabled} disabled={actions[selectedIndex] ? actions[selectedIndex].disabled : actions[0].disabled}
> >
{actions[selectedIndex].name} {actions[selectedIndex] ? actions[selectedIndex].name : actions[0].name}
</Button> </Button>
<Button <Button
size="small" size="small"

View File

@@ -1,6 +1,5 @@
import { import {
Checkbox, Checkbox,
FormControlLabel,
Grid, Grid,
LinearProgress, LinearProgress,
Table, Table,
@@ -154,13 +153,6 @@ const MainForm = ({ name }) => {
: selected.filter(select => select !== vin)); : selected.filter(select => select !== vin));
}; };
const handleSelectAll = (event) => {
const allSelected = !event.target.checked;
setSelected(() => allSelected
? []
: fleetVehicles.map((vehicle) => vehicle.vin));
}
const bulkActionCallback = (action, _, context) => { const bulkActionCallback = (action, _, context) => {
if (action === "updateFleetVehicles") { if (action === "updateFleetVehicles") {
const vinsToRemove = context.fromFleet === name ? context.fromVehicles : []; const vinsToRemove = context.fromFleet === name ? context.fromVehicles : [];
@@ -176,14 +168,6 @@ const MainForm = ({ name }) => {
<AddCircleIcon fontSize="large" /> <AddCircleIcon fontSize="large" />
</Link> </Link>
</Grid> </Grid>
<Grid item md={2} className={classes.textJustifyAlign}>
<FormControlLabel control={
<Checkbox
checked={selectAllSelected}
onChange={() => setSelectAllSelected(selectAllSelected => !selectAllSelected)}
/>
} label="Select All Vehicles" />
</Grid>
<Grid item md={4}> <Grid item md={4}>
<BulkActions <BulkActions
actions={ actions={
@@ -209,9 +193,15 @@ const MainForm = ({ name }) => {
columnData={tableColumns} columnData={tableColumns}
onSortRequest={handleSort} onSortRequest={handleSort}
multiSelect={true} multiSelect={true}
onSelectAll={handleSelectAll} onSelectAll={
() => {
setSelectAllSelected(selectAllSelected => !selectAllSelected);
setSelected([]);
}
}
selectCount={selected.length} selectCount={selected.length}
rowCount={fleetVehicles.length} rowCount={fleetVehicles.length}
selectAllForAllPages={true}
/> />
<TableBody> <TableBody>
{fleetVehicles && fleetVehicles.map((car) => { {fleetVehicles && fleetVehicles.map((car) => {

View File

@@ -6,9 +6,10 @@ import {
TableSortLabel TableSortLabel
} from "@material-ui/core"; } from "@material-ui/core";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import React from "react"; import React, { useState } from "react";
const HeaderSortable = (props) => { const HeaderSortable = (props) => {
const [selectAll, setSelectAll] = useState(false);
const { const {
classes, classes,
order, order,
@@ -19,6 +20,7 @@ const HeaderSortable = (props) => {
onSelectAll, onSelectAll,
selectCount, selectCount,
rowCount, rowCount,
selectAllForAllPages,
} = props; } = props;
const sortHandler = (property) => (event) => { const sortHandler = (property) => (event) => {
@@ -27,6 +29,7 @@ const HeaderSortable = (props) => {
}; };
const selectAllHandler = (event) => { const selectAllHandler = (event) => {
setSelectAll(selectAll => !selectAll);
if (!onSelectAll) return; if (!onSelectAll) return;
onSelectAll(event); onSelectAll(event);
}; };
@@ -71,8 +74,8 @@ const HeaderSortable = (props) => {
{multiSelect && ( {multiSelect && (
<TableCell padding="checkbox"> <TableCell padding="checkbox">
<Checkbox <Checkbox
indeterminate={selectCount > 0 && selectCount < rowCount} indeterminate={!selectAllForAllPages && selectCount > 0 && selectCount < rowCount}
checked={rowCount > 0 && selectCount === rowCount} checked={selectAllForAllPages ? selectAll : rowCount > 0 && selectCount === rowCount}
onChange={selectAllHandler} onChange={selectAllHandler}
inputProps={{ "aria-label": "select all items" }} inputProps={{ "aria-label": "select all items" }}
/> />