From f491361551e952056a65fb557b761ac67d6126a0 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Wed, 4 Dec 2024 10:47:46 +0200 Subject: [PATCH] DataViews: Create a single component for rendering the actions list --- .../dataviews-item-actions/index.tsx | 53 ++++++++++--------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/packages/dataviews/src/components/dataviews-item-actions/index.tsx b/packages/dataviews/src/components/dataviews-item-actions/index.tsx index b5eaac11bcd8d0..c5e1cb09adf15f 100644 --- a/packages/dataviews/src/components/dataviews-item-actions/index.tsx +++ b/packages/dataviews/src/components/dataviews-item-actions/index.tsx @@ -65,6 +65,12 @@ interface PrimaryActionsProps< Item > { actions: Action< Item >[]; registry: ReturnType< typeof useRegistry >; } +interface ActionsListProps< Item > { + item: Item; + actions: Action< Item >[]; + registry: ReturnType< typeof useRegistry >; + ActionTrigger: ( props: ActionTriggerProps< Item > ) => ReactElement; +} function ButtonTrigger< Item >( { action, @@ -160,28 +166,12 @@ export function ActionsMenuGroup< Item >( { const registry = useRegistry(); return ( - { actions.map( ( action ) => { - if ( 'RenderModal' in action ) { - return ( - - ); - } - return ( - { - action.callback( [ item ], { registry } ); - } } - items={ [ item ] } - /> - ); - } ) } + ); } @@ -286,7 +276,22 @@ function PrimaryActions< Item >( { if ( ! Array.isArray( actions ) || actions.length === 0 ) { return null; } + return ( + + ); +} +function ActionsList< Item >( { + item, + actions, + registry, + ActionTrigger, +}: ActionsListProps< Item > ) { return actions.map( ( action ) => { if ( 'RenderModal' in action ) { return ( @@ -294,12 +299,12 @@ function PrimaryActions< Item >( { key={ action.id } action={ action } items={ [ item ] } - ActionTrigger={ ButtonTrigger } + ActionTrigger={ ActionTrigger } /> ); } return ( - {