From 680c4ce3a4e6300826e184b41e4f66b6fa12f101 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Fri, 24 May 2024 15:35:20 +0300 Subject: [PATCH 1/4] DataViews: Add `getLabel` in Actions API --- packages/dataviews/CHANGELOG.md | 3 +++ packages/dataviews/README.md | 3 ++- packages/dataviews/src/bulk-actions-toolbar.tsx | 4 +++- packages/dataviews/src/item-actions.tsx | 11 +++++++++-- packages/dataviews/src/types.ts | 9 ++++++++- .../editor/src/components/post-actions/actions.js | 10 +++++++++- packages/editor/src/components/post-actions/index.js | 8 ++++++-- 7 files changed, 40 insertions(+), 8 deletions(-) diff --git a/packages/dataviews/CHANGELOG.md b/packages/dataviews/CHANGELOG.md index 85aaddc25bb64..7fd806df7cfde 100644 --- a/packages/dataviews/CHANGELOG.md +++ b/packages/dataviews/CHANGELOG.md @@ -11,6 +11,9 @@ ### Internal - Remove some unused dependencies ([#62010](https://github.com/WordPress/gutenberg/pull/62010)). +### Enhancement + +- Add `getLabel` prop in Actions API to support labels that use information from the current item. ([#61941](https://github.com/WordPress/gutenberg/pull/61941)). ## 1.2.0 (2024-05-16) diff --git a/packages/dataviews/README.md b/packages/dataviews/README.md index d0eab0c46d059..d91f6e566b1b1 100644 --- a/packages/dataviews/README.md +++ b/packages/dataviews/README.md @@ -241,7 +241,8 @@ Collection of operations that can be performed upon each record. Each action is an object with the following properties: - `id`: string, required. Unique identifier of the action. For example, `move-to-trash`. -- `label`: string, required. User facing description of the action. For example, `Move to Trash`. +- `label`: string, optional. User facing description of the action. For example, `Move to Trash`. +- `getLabel` function, optional. Accepts the selected records as input and returns the user facing description of the action. It takes precedence over the `label` prop. - `isPrimary`: boolean, optional. Whether the action should be listed inline (primary) or in hidden in the more actions menu (secondary). - `icon`: icon to show for primary actions. It's required for a primary action, otherwise the action would be considered secondary. - `isEligible`: function, optional. Whether the action can be performed for a given record. If not present, the action is considered to be eligible for all items. It takes the given record as input. diff --git a/packages/dataviews/src/bulk-actions-toolbar.tsx b/packages/dataviews/src/bulk-actions-toolbar.tsx index c2b3644b88bce..da875a17aa0e6 100644 --- a/packages/dataviews/src/bulk-actions-toolbar.tsx +++ b/packages/dataviews/src/bulk-actions-toolbar.tsx @@ -65,11 +65,12 @@ function ActionTrigger< Item extends AnyItem >( { action, onClick, isBusy, + items, }: ActionTriggerProps< Item > ) { return ( ( { setActionInProgress( action.id ); action.callback( selectedItems ); } } + items={ selectedEligibleItems } isBusy={ actionInProgress === action.id } /> ); diff --git a/packages/dataviews/src/item-actions.tsx b/packages/dataviews/src/item-actions.tsx index 142fcd99cdfab..3a3647975d3da 100644 --- a/packages/dataviews/src/item-actions.tsx +++ b/packages/dataviews/src/item-actions.tsx @@ -34,6 +34,7 @@ export interface ActionTriggerProps< Item extends AnyItem > { action: Action< Item >; onClick: MouseEventHandler; isBusy?: boolean; + items: Item[]; } interface ActionModalProps< Item extends AnyItem > { @@ -67,10 +68,11 @@ interface CompactItemActionsProps< Item extends AnyItem > { function ButtonTrigger< Item extends AnyItem >( { action, onClick, + items, }: ActionTriggerProps< Item > ) { return (