From 652a32ea2a97dc69573cd1c8a5a555085584fd89 Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Mon, 27 Nov 2023 20:04:35 +0000 Subject: [PATCH] Feedback --- .../src/components/dataviews/view-list.js | 104 ++++++++---------- .../src/components/page-pages/index.js | 1 + 2 files changed, 49 insertions(+), 56 deletions(-) diff --git a/packages/edit-site/src/components/dataviews/view-list.js b/packages/edit-site/src/components/dataviews/view-list.js index 6fcd0bca70bd8..2c9d99f5ea0ae 100644 --- a/packages/edit-site/src/components/dataviews/view-list.js +++ b/packages/edit-site/src/components/dataviews/view-list.js @@ -244,7 +244,7 @@ function ViewList( { } ) { const areAllSelected = selection && selection.length === data.length; const columns = useMemo( () => { - const fieldsColumns = fields.map( ( field ) => { + const _columns = fields.map( ( field ) => { const { render, getValue, ...column } = field; column.cell = ( props ) => render( { item: props.row.original, view } ); @@ -253,61 +253,53 @@ function ViewList( { } return column; } ); - const _columns = - selection !== undefined - ? [ - { - header: ( - { - if ( areAllSelected ) { - setSelection( [] ); - } else { - setSelection( - data.map( ( { id } ) => id ) - ); - } - } } - /> - ), - id: 'selection', - cell: ( props ) => { - //console.log({ props }); - const item = props.row.original; - const isSelected = selection.includes( - item.id - ); - //console.log({ item, isSelected }); - return ( - { - if ( ! isSelected ) { - const newSelection = [ - ...selection, - item.id, - ]; - setSelection( newSelection ); - } else { - setSelection( - selection.filter( - ( id ) => id !== item.id - ) - ); - } - } } - /> - ); - }, - enableHiding: false, - width: 40, - }, - ...fieldsColumns, - ] - : fieldsColumns; + if ( selection !== undefined ) { + _columns.unshift( { + header: ( + { + if ( areAllSelected ) { + setSelection( [] ); + } else { + setSelection( data.map( ( { id } ) => id ) ); + } + } } + /> + ), + id: 'selection', + cell: ( props ) => { + //console.log({ props }); + const item = props.row.original; + const isSelected = selection.includes( item.id ); + //console.log({ item, isSelected }); + return ( + { + if ( ! isSelected ) { + const newSelection = [ + ...selection, + item.id, + ]; + setSelection( newSelection ); + } else { + setSelection( + selection.filter( + ( id ) => id !== item.id + ) + ); + } + } } + /> + ); + }, + enableHiding: false, + width: 40, + } ); + } if ( actions?.length ) { _columns.push( { header: __( 'Actions' ), diff --git a/packages/edit-site/src/components/page-pages/index.js b/packages/edit-site/src/components/page-pages/index.js index a967d3c56a3ed..f269c24cb8cec 100644 --- a/packages/edit-site/src/components/page-pages/index.js +++ b/packages/edit-site/src/components/page-pages/index.js @@ -158,6 +158,7 @@ export default function PagePages() { totalPages, } = useEntityRecords( 'postType', postType, queryArgs ); + // Remove any selected pages that are no longer in the list of visible pages. useEffect( () => { if ( selection.some(