Skip to content

Hide bulk requests button correctly when there is no bulk actions and link properties #4127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 32 additions & 30 deletions src/components/CippTable/CIPPTableToptoolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export const CIPPTableToptoolbar = ({
const handleActionMenuOpen = (event) => setActionMenuAnchor(event.currentTarget);
const handleActionMenuClose = () => setActionMenuAnchor(null);

const getBulkActions = (actions) => {
return actions?.filter((action) => !action.link && !action?.hideBulk) || [];
};

useEffect(() => {
//if usedData changes, deselect all rows
table.toggleAllRowsSelected(false);
Expand Down Expand Up @@ -486,7 +490,7 @@ export const CIPPTableToptoolbar = ({
<SevereCold />
</Tooltip>
)}
{actions && (table.getIsSomeRowsSelected() || table.getIsAllRowsSelected()) && (
{actions && getBulkActions(actions).length > 0 && (table.getIsSomeRowsSelected() || table.getIsAllRowsSelected()) && (
<>
<Button
onClick={popover.handleOpen}
Expand Down Expand Up @@ -521,36 +525,34 @@ export const CIPPTableToptoolbar = ({
vertical: "top",
}}
>
{actions
?.filter((action) => !action.link && !action?.hideBulk)
.map((action, index) => (
<MenuItem
key={index}
onClick={() => {
setActionData({
data: table.getSelectedRowModel().rows.map((row) => row.original),
action: action,
ready: true,
});
{getBulkActions(actions).map((action, index) => (
<MenuItem
key={index}
onClick={() => {
setActionData({
data: table.getSelectedRowModel().rows.map((row) => row.original),
action: action,
ready: true,
});

if (action?.noConfirm && action.customFunction) {
table
.getSelectedRowModel()
.rows.map((row) =>
action.customFunction(row.original.original, action, {})
);
} else {
createDialog.handleOpen();
popover.handleClose();
}
}}
>
<SvgIcon fontSize="small" sx={{ minWidth: "30px" }}>
{action.icon}
</SvgIcon>
<ListItemText>{action.label}</ListItemText>
</MenuItem>
))}
if (action?.noConfirm && action.customFunction) {
table
.getSelectedRowModel()
.rows.map((row) =>
action.customFunction(row.original.original, action, {})
);
} else {
createDialog.handleOpen();
popover.handleClose();
}
}}
>
<SvgIcon fontSize="small" sx={{ minWidth: "30px" }}>
{action.icon}
</SvgIcon>
<ListItemText>{action.label}</ListItemText>
</MenuItem>
))}
</Menu>
</>
)}
Expand Down
Loading