Skip to content

Commit 3ea3ba2

Browse files
ntsekourasMamadukaoandregal
authored
DataViews: Create a single component for rendering the actions list (#67558)
Co-authored-by: ntsekouras <[email protected]> Co-authored-by: Mamaduka <[email protected]> Co-authored-by: oandregal <[email protected]>
1 parent 094bd3a commit 3ea3ba2

File tree

1 file changed

+29
-24
lines changed
  • packages/dataviews/src/components/dataviews-item-actions

1 file changed

+29
-24
lines changed

packages/dataviews/src/components/dataviews-item-actions/index.tsx

+29-24
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ interface PrimaryActionsProps< Item > {
6565
actions: Action< Item >[];
6666
registry: ReturnType< typeof useRegistry >;
6767
}
68+
interface ActionsListProps< Item > {
69+
item: Item;
70+
actions: Action< Item >[];
71+
registry: ReturnType< typeof useRegistry >;
72+
ActionTrigger: ( props: ActionTriggerProps< Item > ) => ReactElement;
73+
}
6874

6975
function ButtonTrigger< Item >( {
7076
action,
@@ -160,28 +166,12 @@ export function ActionsMenuGroup< Item >( {
160166
const registry = useRegistry();
161167
return (
162168
<Menu.Group>
163-
{ actions.map( ( action ) => {
164-
if ( 'RenderModal' in action ) {
165-
return (
166-
<ActionWithModal
167-
key={ action.id }
168-
action={ action }
169-
items={ [ item ] }
170-
ActionTrigger={ MenuItemTrigger }
171-
/>
172-
);
173-
}
174-
return (
175-
<MenuItemTrigger
176-
key={ action.id }
177-
action={ action }
178-
onClick={ () => {
179-
action.callback( [ item ], { registry } );
180-
} }
181-
items={ [ item ] }
182-
/>
183-
);
184-
} ) }
169+
<ActionsList
170+
actions={ actions }
171+
item={ item }
172+
registry={ registry }
173+
ActionTrigger={ MenuItemTrigger }
174+
/>
185175
</Menu.Group>
186176
);
187177
}
@@ -286,20 +276,35 @@ function PrimaryActions< Item >( {
286276
if ( ! Array.isArray( actions ) || actions.length === 0 ) {
287277
return null;
288278
}
279+
return (
280+
<ActionsList
281+
actions={ actions }
282+
item={ item }
283+
registry={ registry }
284+
ActionTrigger={ ButtonTrigger }
285+
/>
286+
);
287+
}
289288

289+
function ActionsList< Item >( {
290+
item,
291+
actions,
292+
registry,
293+
ActionTrigger,
294+
}: ActionsListProps< Item > ) {
290295
return actions.map( ( action ) => {
291296
if ( 'RenderModal' in action ) {
292297
return (
293298
<ActionWithModal
294299
key={ action.id }
295300
action={ action }
296301
items={ [ item ] }
297-
ActionTrigger={ ButtonTrigger }
302+
ActionTrigger={ ActionTrigger }
298303
/>
299304
);
300305
}
301306
return (
302-
<ButtonTrigger
307+
<ActionTrigger
303308
key={ action.id }
304309
action={ action }
305310
onClick={ () => {

0 commit comments

Comments
 (0)