From fe40df67ad88740d83c4c60735603d09a0ca5d55 Mon Sep 17 00:00:00 2001 From: Nik Tsekouras Date: Tue, 28 May 2024 16:03:24 +0300 Subject: [PATCH] DataViews: `label` prop in Actions API can be either a `string` or a `function` (#61942) Co-authored-by: ntsekouras Co-authored-by: youknowriad Co-authored-by: jorgefilipecosta --- packages/dataviews/CHANGELOG.md | 4 ++ packages/dataviews/README.md | 63 ++++++++++--------- .../dataviews/src/bulk-actions-toolbar.tsx | 6 +- packages/dataviews/src/bulk-actions.tsx | 6 +- packages/dataviews/src/item-actions.tsx | 17 ++++- packages/dataviews/src/types.ts | 4 +- packages/dataviews/src/view-list.tsx | 9 ++- .../src/components/post-actions/actions.js | 11 +++- .../src/components/post-actions/index.js | 8 ++- 9 files changed, 86 insertions(+), 42 deletions(-) diff --git a/packages/dataviews/CHANGELOG.md b/packages/dataviews/CHANGELOG.md index 85aaddc25bb645..1b772a002ff7be 100644 --- a/packages/dataviews/CHANGELOG.md +++ b/packages/dataviews/CHANGELOG.md @@ -12,6 +12,10 @@ - Remove some unused dependencies ([#62010](https://github.com/WordPress/gutenberg/pull/62010)). +### Enhancement + +- `label` prop in Actions API can be either a `string` value or a `function`, in case we want to use information from the selected items. ([#61942](https://github.com/WordPress/gutenberg/pull/61942)). + ## 1.2.0 (2024-05-16) ### Internal diff --git a/packages/dataviews/README.md b/packages/dataviews/README.md index d0eab0c46d0598..41595b4d58adcd 100644 --- a/packages/dataviews/README.md +++ b/packages/dataviews/README.md @@ -14,7 +14,6 @@ npm install @wordpress/dataviews --save ```jsx const Example = () => { - // Declare data, fields, etc. return ( @@ -27,7 +26,7 @@ const Example = () => { paginationInfo={ paginationInfo } /> ); -} +}; ``` ## Properties @@ -42,12 +41,14 @@ Example: const data = [ { id: 1, - title: "Title", - author: "Admin", - date: "2012-04-23T18:25:43.511Z" + title: 'Title', + author: 'Admin', + date: '2012-04-23T18:25:43.511Z', }, - { /* ... */ } -] + { + /* ... */ + }, +]; ``` By default, dataviews would use each record's `id` as an unique identifier. If it's not, the consumer should provide a `getItemId` function that returns one. @@ -125,8 +126,8 @@ Each field is an object with the following properties: - `enableSorting`: whether the data can be sorted by the given field. True by default. - `enableHiding`: whether the field can be hidden. True by default. - `filterBy`: configuration for the filters. - - `operators`: the list of operators supported by the field. - - `isPrimary`: whether it is a primary filter. A primary filter is always visible and is not listed in the "Add filter" component, except for the list layout where it behaves like a secondary filter. + - `operators`: the list of operators supported by the field. + - `isPrimary`: whether it is a primary filter. A primary filter is always visible and is not listed in the "Add filter" component, except for the list layout where it behaves like a secondary filter. ### `view`: `object` @@ -140,7 +141,7 @@ const view = { search: '', filters: [ { field: 'author', operator: 'is', value: 2 }, - { field: 'status', operator: 'isAny', value: [ 'publish', 'draft'] } + { field: 'status', operator: 'isAny', value: [ 'publish', 'draft' ] }, ], page: 1, perPage: 5, @@ -150,7 +151,7 @@ const view = { }, hiddenFields: [ 'date', 'featured-image' ], layout: {}, -} +}; ``` Properties: @@ -164,8 +165,8 @@ Properties: - `perPage`: number of records to show per page. - `page`: the page that is visible. - `sort`: - - `field`: the field used for sorting the dataset. - - `direction`: the direction to use for sorting, one of `asc` or `desc`. + - `field`: the field used for sorting the dataset. + - `direction`: the direction to use for sorting, one of `asc` or `desc`. - `hiddenFields`: the `id` of the fields that are hidden in the UI. - `layout`: config that is specific to a particular layout type. - `mediaField`: used by the `grid` and `list` layouts. The `id` of the field to be used for rendering each card's media. @@ -192,7 +193,11 @@ function MyCustomPageTable() { search: '', filters: [ { field: 'author', operator: 'is', value: 2 }, - { field: 'status', operator: 'isAny', value: [ 'publish', 'draft' ] } + { + field: 'status', + operator: 'isAny', + value: [ 'publish', 'draft' ], + }, ], hiddenFields: [ 'date', 'featured-image' ], layout: {}, @@ -219,9 +224,7 @@ function MyCustomPageTable() { }; }, [ view ] ); - const { - records - } = useEntityRecords( 'postType', 'page', queryArgs ); + const { records } = useEntityRecords( 'postType', 'page', queryArgs ); return (