diff --git a/packages/dataviews/CHANGELOG.md b/packages/dataviews/CHANGELOG.md index 7da51ec32ecc2d..cf9398c9c77be0 100644 --- a/packages/dataviews/CHANGELOG.md +++ b/packages/dataviews/CHANGELOG.md @@ -11,9 +11,10 @@ ### 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 selected items. ([#61942](https://github.com/WordPress/gutenberg/pull/61942)). +- `label` prop in Actions API can be either a `sting` 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) diff --git a/packages/dataviews/README.md b/packages/dataviews/README.md index d91f6e566b1b1e..31540e90d611a0 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 (