|
1 |
| -import { DeveloperMode, SevereCold, Sync, Tune, ViewColumn, MoreVert } from "@mui/icons-material"; |
| 1 | +import { DeveloperMode, SevereCold, Sync, Tune, ViewColumn } from "@mui/icons-material"; |
2 | 2 | import {
|
3 | 3 | Button,
|
4 | 4 | Checkbox,
|
@@ -74,8 +74,11 @@ export const CIPPTableToptoolbar = ({
|
74 | 74 | const handleActionMenuOpen = (event) => setActionMenuAnchor(event.currentTarget);
|
75 | 75 | const handleActionMenuClose = () => setActionMenuAnchor(null);
|
76 | 76 |
|
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 | + })) || []; |
79 | 82 | };
|
80 | 83 |
|
81 | 84 | useEffect(() => {
|
@@ -490,7 +493,7 @@ export const CIPPTableToptoolbar = ({
|
490 | 493 | <SevereCold />
|
491 | 494 | </Tooltip>
|
492 | 495 | )}
|
493 |
| - {actions && getBulkActions(actions).length > 0 && (table.getIsSomeRowsSelected() || table.getIsAllRowsSelected()) && ( |
| 496 | + {actions && getBulkActions(actions, table.getSelectedRowModel().rows).length > 0 && (table.getIsSomeRowsSelected() || table.getIsAllRowsSelected()) && ( |
494 | 497 | <>
|
495 | 498 | <Button
|
496 | 499 | onClick={popover.handleOpen}
|
@@ -525,10 +528,12 @@ export const CIPPTableToptoolbar = ({
|
525 | 528 | vertical: "top",
|
526 | 529 | }}
|
527 | 530 | >
|
528 |
| - {getBulkActions(actions).map((action, index) => ( |
| 531 | + {getBulkActions(actions, table.getSelectedRowModel().rows).map((action, index) => ( |
529 | 532 | <MenuItem
|
530 | 533 | key={index}
|
| 534 | + disabled={action.disabled} |
531 | 535 | onClick={() => {
|
| 536 | + if (action.disabled) return; |
532 | 537 | setActionData({
|
533 | 538 | data: table.getSelectedRowModel().rows.map((row) => row.original),
|
534 | 539 | action: action,
|
|
0 commit comments