Skip to content

Commit a8071d3

Browse files
Merge pull request #4202 from Zacgoose/dev
Feat: Bulk actions now consider conditions when selected
2 parents 22a4ac1 + a8b3273 commit a8071d3

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/components/CippTable/CIPPTableToptoolbar.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DeveloperMode, SevereCold, Sync, Tune, ViewColumn, MoreVert } from "@mui/icons-material";
1+
import { DeveloperMode, SevereCold, Sync, Tune, ViewColumn } from "@mui/icons-material";
22
import {
33
Button,
44
Checkbox,
@@ -74,8 +74,11 @@ export const CIPPTableToptoolbar = ({
7474
const handleActionMenuOpen = (event) => setActionMenuAnchor(event.currentTarget);
7575
const handleActionMenuClose = () => setActionMenuAnchor(null);
7676

77-
const getBulkActions = (actions) => {
78-
return actions?.filter((action) => !action.link && !action?.hideBulk) || [];
77+
const getBulkActions = (actions, selectedRows) => {
78+
return actions?.filter((action) => !action.link && !action?.hideBulk)?.map(action => ({
79+
...action,
80+
disabled: action.condition ? !selectedRows.every(row => action.condition(row.original)) : false
81+
})) || [];
7982
};
8083

8184
useEffect(() => {
@@ -490,7 +493,7 @@ export const CIPPTableToptoolbar = ({
490493
<SevereCold />
491494
</Tooltip>
492495
)}
493-
{actions && getBulkActions(actions).length > 0 && (table.getIsSomeRowsSelected() || table.getIsAllRowsSelected()) && (
496+
{actions && getBulkActions(actions, table.getSelectedRowModel().rows).length > 0 && (table.getIsSomeRowsSelected() || table.getIsAllRowsSelected()) && (
494497
<>
495498
<Button
496499
onClick={popover.handleOpen}
@@ -525,10 +528,12 @@ export const CIPPTableToptoolbar = ({
525528
vertical: "top",
526529
}}
527530
>
528-
{getBulkActions(actions).map((action, index) => (
531+
{getBulkActions(actions, table.getSelectedRowModel().rows).map((action, index) => (
529532
<MenuItem
530533
key={index}
534+
disabled={action.disabled}
531535
onClick={() => {
536+
if (action.disabled) return;
532537
setActionData({
533538
data: table.getSelectedRowModel().rows.map((row) => row.original),
534539
action: action,

0 commit comments

Comments
 (0)