Skip to content

Commit

Permalink
DataViews: Create a single component for rendering the actions list (#…
Browse files Browse the repository at this point in the history
…67558)

Co-authored-by: ntsekouras <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: oandregal <[email protected]>
  • Loading branch information
4 people authored Dec 5, 2024
1 parent 094bd3a commit 3ea3ba2
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions packages/dataviews/src/components/dataviews-item-actions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -160,28 +166,12 @@ export function ActionsMenuGroup< Item >( {
const registry = useRegistry();
return (
<Menu.Group>
{ actions.map( ( action ) => {
if ( 'RenderModal' in action ) {
return (
<ActionWithModal
key={ action.id }
action={ action }
items={ [ item ] }
ActionTrigger={ MenuItemTrigger }
/>
);
}
return (
<MenuItemTrigger
key={ action.id }
action={ action }
onClick={ () => {
action.callback( [ item ], { registry } );
} }
items={ [ item ] }
/>
);
} ) }
<ActionsList
actions={ actions }
item={ item }
registry={ registry }
ActionTrigger={ MenuItemTrigger }
/>
</Menu.Group>
);
}
Expand Down Expand Up @@ -286,20 +276,35 @@ function PrimaryActions< Item >( {
if ( ! Array.isArray( actions ) || actions.length === 0 ) {
return null;
}
return (
<ActionsList
actions={ actions }
item={ item }
registry={ registry }
ActionTrigger={ ButtonTrigger }
/>
);
}

function ActionsList< Item >( {
item,
actions,
registry,
ActionTrigger,
}: ActionsListProps< Item > ) {
return actions.map( ( action ) => {
if ( 'RenderModal' in action ) {
return (
<ActionWithModal
key={ action.id }
action={ action }
items={ [ item ] }
ActionTrigger={ ButtonTrigger }
ActionTrigger={ ActionTrigger }
/>
);
}
return (
<ButtonTrigger
<ActionTrigger
key={ action.id }
action={ action }
onClick={ () => {
Expand Down

1 comment on commit 3ea3ba2

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 3ea3ba2.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12177485248
📝 Reported issues:

Please sign in to comment.