From ea9021406bea0bb172eedef4227234c392bd275b Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Fri, 12 Jul 2024 10:53:54 +0200 Subject: [PATCH] DataViews: Only show elligible actions in the bulk editing menu --- packages/dataviews/src/bulk-actions.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/dataviews/src/bulk-actions.tsx b/packages/dataviews/src/bulk-actions.tsx index adafbe5799ccb8..3530b0b849c901 100644 --- a/packages/dataviews/src/bulk-actions.tsx +++ b/packages/dataviews/src/bulk-actions.tsx @@ -133,7 +133,6 @@ function BulkActionItem< Item >( { return ( { if ( shouldShowModal ) { @@ -142,9 +141,7 @@ function BulkActionItem< Item >( { action.callback( eligibleItems, { registry } ); } } } - suffix={ - eligibleItems.length > 0 ? eligibleItems.length : undefined - } + suffix={ eligibleItems.length } > { action.label } @@ -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 ( <> - { actions.map( ( action ) => ( + { elligibleActions.map( ( action ) => (