Skip to content

Commit

Permalink
DataViews: Only show elligible actions in the bulk editing menu (Word…
Browse files Browse the repository at this point in the history
…Press#63473)

Co-authored-by: youknowriad <[email protected]>
Co-authored-by: jameskoster <[email protected]>
  • Loading branch information
3 people authored and carstingaxion committed Jul 18, 2024
1 parent 648f3dd commit d10af6b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/dataviews/src/bulk-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ function BulkActionItem< Item >( {
return (
<DropdownMenuItem
key={ action.id }
disabled={ eligibleItems.length === 0 }
hideOnClick={ ! shouldShowModal }
onClick={ async () => {
if ( shouldShowModal ) {
Expand All @@ -142,9 +141,7 @@ function BulkActionItem< Item >( {
action.callback( eligibleItems, { registry } );
}
} }
suffix={
eligibleItems.length > 0 ? eligibleItems.length : undefined
}
suffix={ eligibleItems.length }
>
{ action.label }
</DropdownMenuItem>
Expand All @@ -156,10 +153,18 @@ function ActionsMenuGroup< Item >( {
selectedItems,
setActionWithModal,
}: ActionsMenuGroupProps< Item > ) {
const elligibleActions = useMemo( () => {
return actions.filter( ( action ) => {
return selectedItems.some(
( item ) => ! action.isEligible || action.isEligible( item )
);
} );
}, [ actions, selectedItems ] );

return (
<>
<DropdownMenuGroup>
{ actions.map( ( action ) => (
{ elligibleActions.map( ( action ) => (
<BulkActionItem
key={ action.id }
action={ action }
Expand Down

0 comments on commit d10af6b

Please sign in to comment.