From 418a3fc15594126914562c0e18c4993a8822b8b2 Mon Sep 17 00:00:00 2001 From: Nik Tsekouras Date: Wed, 18 Oct 2023 10:28:55 +0300 Subject: [PATCH] [Data views]: Rename accessorFn to getValue (#55434) --- .../src/components/dataviews/dataviews.js | 2 +- .../src/components/dataviews/view-grid.js | 4 ++-- .../src/components/dataviews/view-list.js | 8 +++++-- .../src/components/page-pages/index.js | 24 +++++++++---------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/packages/edit-site/src/components/dataviews/dataviews.js b/packages/edit-site/src/components/dataviews/dataviews.js index 23e0aba02aa400..b488836a91f3eb 100644 --- a/packages/edit-site/src/components/dataviews/dataviews.js +++ b/packages/edit-site/src/components/dataviews/dataviews.js @@ -29,7 +29,7 @@ export default function DataViews( { const _fields = useMemo( () => { return fields.map( ( field ) => ( { ...field, - render: field.render || field.accessorFn, + render: field.render || field.getValue, } ) ); }, [ fields ] ); return ( diff --git a/packages/edit-site/src/components/dataviews/view-grid.js b/packages/edit-site/src/components/dataviews/view-grid.js index 353c2de39a1d9e..30a36b68e2c09e 100644 --- a/packages/edit-site/src/components/dataviews/view-grid.js +++ b/packages/edit-site/src/components/dataviews/view-grid.js @@ -29,7 +29,7 @@ export function ViewGrid( { data, fields, view, actions } ) { return (
- { mediaField?.render( item, view ) || ( + { mediaField?.render( { item, view } ) || ( { visibleFields.map( ( field ) => (
- { field.render( item, view ) } + { field.render( { item, view } ) }
) ) } diff --git a/packages/edit-site/src/components/dataviews/view-list.js b/packages/edit-site/src/components/dataviews/view-list.js index cc54ceccf15b39..22b9a059c2f1bf 100644 --- a/packages/edit-site/src/components/dataviews/view-list.js +++ b/packages/edit-site/src/components/dataviews/view-list.js @@ -146,8 +146,12 @@ function ViewList( { } ) { const columns = useMemo( () => { const _columns = fields.map( ( field ) => { - const { render, ...column } = field; - column.cell = ( props ) => render( props.row.original, view ); + const { render, getValue, ...column } = field; + column.cell = ( props ) => + render( { item: props.row.original, view } ); + if ( getValue ) { + column.accessorFn = ( item ) => getValue( { item } ); + } return column; } ); if ( actions?.length ) { diff --git a/packages/edit-site/src/components/page-pages/index.js b/packages/edit-site/src/components/page-pages/index.js index 0d14a5ffda4d42..4b7fe8228a53a9 100644 --- a/packages/edit-site/src/components/page-pages/index.js +++ b/packages/edit-site/src/components/page-pages/index.js @@ -95,8 +95,8 @@ export default function PagePages() { { id: 'featured-image', header: __( 'Featured Image' ), - accessorFn: ( page ) => page.featured_media, - render: ( item, currentView ) => + getValue: ( { item } ) => item.featured_media, + render: ( { item, view: currentView } ) => !! item.featured_media ? ( page.title?.rendered || page.slug, - render: ( page ) => { + getValue: ( { item } ) => item.title?.rendered || item.slug, + render: ( { item } ) => { return ( { decodeEntities( - page.title?.rendered || page.slug + item.title?.rendered || item.slug ) || __( '(no title)' ) } @@ -141,8 +141,8 @@ export default function PagePages() { { header: __( 'Author' ), id: 'author', - accessorFn: ( page ) => page._embedded?.author[ 0 ]?.name, - render: ( item ) => { + getValue: ( { item } ) => item._embedded?.author[ 0 ]?.name, + render: ( { item } ) => { const author = item._embedded?.author[ 0 ]; return ( @@ -165,8 +165,8 @@ export default function PagePages() { { header: __( 'Status' ), id: 'status', - accessorFn: ( page ) => - postStatuses[ page.status ] ?? page.status, + getValue: ( { item } ) => + postStatuses[ item.status ] ?? item.status, filters: [ { type: 'enumeration', id: 'status' } ], elements: [ { label: __( 'All' ), value: 'publish,draft' }, @@ -186,7 +186,7 @@ export default function PagePages() { { header: 'Date', id: 'date', - render: ( item ) => { + render: ( { item } ) => { const formattedDate = dateI18n( getSettings().formats.datetimeAbbreviated, getDate( item.date )