From d7b6a1a60bd0028de632d4ea02b4c170a3163092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Fri, 1 Dec 2023 18:44:35 +0100 Subject: [PATCH 01/30] ViewList: bootstrap view with previewField and onClickPreviewField --- packages/dataviews/src/dataviews.js | 2 + packages/dataviews/src/view-list.js | 47 +++++++++++++++++-- .../src/components/page-pages/index.js | 18 +++---- 3 files changed, 52 insertions(+), 15 deletions(-) diff --git a/packages/dataviews/src/dataviews.js b/packages/dataviews/src/dataviews.js index b75155e8fddf0a..486601b962e738 100644 --- a/packages/dataviews/src/dataviews.js +++ b/packages/dataviews/src/dataviews.js @@ -28,6 +28,7 @@ export default function DataViews( { isLoading = false, paginationInfo, supportedLayouts, + onClickPreviewField, } ) { const ViewComponent = VIEW_LAYOUTS.find( ( v ) => v.type === view.type @@ -72,6 +73,7 @@ export default function DataViews( { data={ data } getItemId={ getItemId } isLoading={ isLoading } + onClickPreviewField={ onClickPreviewField } /> ; +export default function ViewList( { + view, + fields, + data, + getItemId, + onClickPreviewField, +} ) { + const shownData = useAsyncList( data, { step: 3 } ); + const previewField = fields.find( + ( field ) => field.id === view.layout.previewField + ); + return ( + + ); } diff --git a/packages/edit-site/src/components/page-pages/index.js b/packages/edit-site/src/components/page-pages/index.js index bac881f2ceb218..b65abc74b9e612 100644 --- a/packages/edit-site/src/components/page-pages/index.js +++ b/packages/edit-site/src/components/page-pages/index.js @@ -48,6 +48,9 @@ const defaultConfigPerViewType = { mediaField: 'featured-image', primaryField: 'title', }, + [ LAYOUT_LIST ]: { + previewField: 'title', + }, }; function useView( type ) { @@ -126,6 +129,8 @@ export default function PagePages() { const [ view, setView ] = useView( postType ); const [ selection, setSelection ] = useState( [] ); + const onClickPreviewField = ( item ) => setSelection( [ item.id ] ); + const queryArgs = useMemo( () => { const filters = {}; view.filters.forEach( ( filter ) => { @@ -205,7 +210,7 @@ export default function PagePages() { header: __( 'Title' ), id: 'title', getValue: ( { item } ) => item.title?.rendered || item.slug, - render: ( { item, view: { type } } ) => { + render: ( { item } ) => { return ( @@ -215,16 +220,6 @@ export default function PagePages() { postType: item.type, canvas: 'edit', } } - onClick={ ( event ) => { - if ( - VIEW_LAYOUTS.find( - ( v ) => v.type === type - )?.supports?.preview - ) { - event.preventDefault(); - setSelection( [ item.id ] ); - } - } } > { decodeEntities( item.title?.rendered || item.slug @@ -324,6 +319,7 @@ export default function PagePages() { isLoading={ isLoadingPages || isLoadingAuthors } view={ view } onChangeView={ onChangeView } + onClickPreviewField={ onClickPreviewField } /> { VIEW_LAYOUTS.find( ( v ) => v.type === view.type )?.supports From 047a1c7759038e89a9cd717113e2b25a098fb7b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Fri, 1 Dec 2023 22:50:22 +0100 Subject: [PATCH 02/30] Remove dependency from View supports --- packages/dataviews/src/constants.js | 9 --------- .../edit-site/src/components/page-pages/index.js | 15 +++++++-------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/packages/dataviews/src/constants.js b/packages/dataviews/src/constants.js index c4d1d9242f08a3..4512ddd880e1e4 100644 --- a/packages/dataviews/src/constants.js +++ b/packages/dataviews/src/constants.js @@ -29,26 +29,17 @@ export const VIEW_LAYOUTS = [ label: __( 'Table' ), component: ViewTable, icon: blockTable, - supports: { - preview: false, - }, }, { type: LAYOUT_GRID, label: __( 'Grid' ), component: ViewGrid, icon: category, - supports: { - preview: false, - }, }, { type: LAYOUT_LIST, label: __( 'List' ), component: ViewList, icon: drawerLeft, - supports: { - preview: true, - }, }, ]; diff --git a/packages/edit-site/src/components/page-pages/index.js b/packages/edit-site/src/components/page-pages/index.js index b65abc74b9e612..83f5580c907f1b 100644 --- a/packages/edit-site/src/components/page-pages/index.js +++ b/packages/edit-site/src/components/page-pages/index.js @@ -12,7 +12,7 @@ import { useState, useMemo, useCallback, useEffect } from '@wordpress/element'; import { dateI18n, getDate, getSettings } from '@wordpress/date'; import { privateApis as routerPrivateApis } from '@wordpress/router'; import { useSelect, useDispatch } from '@wordpress/data'; -import { DataViews, VIEW_LAYOUTS } from '@wordpress/dataviews'; +import { DataViews } from '@wordpress/dataviews'; /** * Internal dependencies @@ -127,9 +127,9 @@ const DEFAULT_STATUSES = 'draft,future,pending,private,publish'; // All but 'tra export default function PagePages() { const postType = 'page'; const [ view, setView ] = useView( postType ); - const [ selection, setSelection ] = useState( [] ); + const [ previewItem, setPreview ] = useState(); - const onClickPreviewField = ( item ) => setSelection( [ item.id ] ); + const onClickPreviewField = ( item ) => setPreview( item.id ); const queryArgs = useMemo( () => { const filters = {}; @@ -322,17 +322,16 @@ export default function PagePages() { onClickPreviewField={ onClickPreviewField } /> - { VIEW_LAYOUTS.find( ( v ) => v.type === view.type )?.supports - ?.preview && ( + { view.layout.previewField && (
- { selection.length === 1 && ( + { previewItem && ( ) } - { selection.length !== 1 && ( + { ! previewItem && (
Date: Fri, 1 Dec 2023 23:00:07 +0100 Subject: [PATCH 03/30] Document API for preview --- packages/dataviews/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/dataviews/README.md b/packages/dataviews/README.md index 2ee1d7f42eff5b..64c1c464a5d0d5 100644 --- a/packages/dataviews/README.md +++ b/packages/dataviews/README.md @@ -22,6 +22,7 @@ npm install @wordpress/dataviews --save fields={ fields } actions={ [ trashPostAction ] } paginationInfo={ { totalItems, totalPages } } + onClickPreviewField={ ( item ) => { /* handle preview */ } } /> ``` @@ -77,6 +78,7 @@ Example: - `layout`: config that is specific to a particular layout type. - `mediaField`: used by the `grid` layout. The `id` of the field to be used for rendering each card's media. - `primaryField`: used by the `grid` layout. The `id` of the field to be used for rendering each card's title. + - `previewField`: used by the `list` layout. The `id` of the field to be used for triggering the preview. ### View <=> data From 448cd122efc1f9f7a31a712e9d6f1ec1d8a9db7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Fri, 1 Dec 2023 23:29:23 +0100 Subject: [PATCH 04/30] Let the previewField handle its render --- packages/dataviews/src/style.scss | 12 ++++++++++ packages/dataviews/src/view-list.js | 34 ++++++++++------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/dataviews/src/style.scss b/packages/dataviews/src/style.scss index 5dd89f4c279707..a31da90968d2af 100644 --- a/packages/dataviews/src/style.scss +++ b/packages/dataviews/src/style.scss @@ -127,6 +127,18 @@ } } +.dataviews-list-view { + li { + padding: $grid-unit-20 $grid-unit-40; + border-bottom: $border-width solid $gray-100; + &:last-child { + border-bottom: 0; + } + &:hover { + background-color: $gray-100; + } + } +} .dataviews-action-modal { z-index: z-index(".dataviews-action-modal"); } diff --git a/packages/dataviews/src/view-list.js b/packages/dataviews/src/view-list.js index 9a0788919abcac..9c2f901e0bd075 100644 --- a/packages/dataviews/src/view-list.js +++ b/packages/dataviews/src/view-list.js @@ -1,13 +1,10 @@ /** * WordPress dependencies */ -import { __experimentalHeading as Heading } from '@wordpress/components'; import { useAsyncList } from '@wordpress/compose'; - -/** - * Internal dependencies - */ -import Link from '../routes/link'; +import { Icon, + __experimentalHStack as HStack,} from '@wordpress/components'; +import { chevronRight } from '@wordpress/icons'; export default function ViewList( { view, @@ -21,25 +18,16 @@ export default function ViewList( { ( field ) => field.id === view.layout.previewField ); return ( -
    +
      { shownData.map( ( item, index ) => { return ( -
    • - - { - event.preventDefault(); - onClickPreviewField( item ); - } } - > - { previewField.getValue( { item } ) } - - +
    • { + onClickPreviewField( item ); + }}> + + { previewField?.render( { item } ) } + +
    • ); } ) } From 4ab95f6bbad15244aa1038c0bf13389383207d20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Mon, 4 Dec 2023 09:34:48 +0100 Subject: [PATCH 05/30] Use primaryField/preview from view.layout --- packages/dataviews/README.md | 6 +++--- packages/dataviews/src/dataviews.js | 4 ++-- packages/dataviews/src/view-list.js | 12 +++++++----- .../edit-site/src/components/page-pages/index.js | 9 +++++---- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/packages/dataviews/README.md b/packages/dataviews/README.md index 64c1c464a5d0d5..758249518d0068 100644 --- a/packages/dataviews/README.md +++ b/packages/dataviews/README.md @@ -22,7 +22,7 @@ npm install @wordpress/dataviews --save fields={ fields } actions={ [ trashPostAction ] } paginationInfo={ { totalItems, totalPages } } - onClickPreviewField={ ( item ) => { /* handle preview */ } } + onClickPreview={ ( item ) => { /* handle preview */ } } /> ``` @@ -77,8 +77,8 @@ Example: - `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` layout. The `id` of the field to be used for rendering each card's media. - - `primaryField`: used by the `grid` layout. The `id` of the field to be used for rendering each card's title. - - `previewField`: used by the `list` layout. The `id` of the field to be used for triggering the preview. + - `primaryField`: used by the `grid` and `list` layouts. The `id` of the field to be highlighted in each card/list item. + - `preview`: boolean. Only supported by the `list` view. Whether or not previews are supported. ### View <=> data diff --git a/packages/dataviews/src/dataviews.js b/packages/dataviews/src/dataviews.js index 486601b962e738..236211f2f7ad33 100644 --- a/packages/dataviews/src/dataviews.js +++ b/packages/dataviews/src/dataviews.js @@ -28,7 +28,7 @@ export default function DataViews( { isLoading = false, paginationInfo, supportedLayouts, - onClickPreviewField, + onClickPreview, } ) { const ViewComponent = VIEW_LAYOUTS.find( ( v ) => v.type === view.type @@ -73,7 +73,7 @@ export default function DataViews( { data={ data } getItemId={ getItemId } isLoading={ isLoading } - onClickPreviewField={ onClickPreviewField } + onClickPreview={ onClickPreview } /> field.id === view.layout.previewField + const primaryField = fields.find( + ( field ) => field.id === view.layout.primaryField ); return (
        { shownData.map( ( item, index ) => { return ( + // TODO: make li interactive. + // fix jsx-a11y/click-events-have-key-events and jsx-a11y/no-noninteractive-element-interactions
      • { - onClickPreviewField( item ); + onClickPreview( item ); }}> - { previewField?.render( { item } ) } + { primaryField?.render( { item } ) }
      • diff --git a/packages/edit-site/src/components/page-pages/index.js b/packages/edit-site/src/components/page-pages/index.js index 83f5580c907f1b..995e1bff69c33d 100644 --- a/packages/edit-site/src/components/page-pages/index.js +++ b/packages/edit-site/src/components/page-pages/index.js @@ -49,7 +49,8 @@ const defaultConfigPerViewType = { primaryField: 'title', }, [ LAYOUT_LIST ]: { - previewField: 'title', + primaryField: 'title', + preview: true, }, }; @@ -129,7 +130,7 @@ export default function PagePages() { const [ view, setView ] = useView( postType ); const [ previewItem, setPreview ] = useState(); - const onClickPreviewField = ( item ) => setPreview( item.id ); + const onClickPreview = ( item ) => setPreview( item.id ); const queryArgs = useMemo( () => { const filters = {}; @@ -319,10 +320,10 @@ export default function PagePages() { isLoading={ isLoadingPages || isLoadingAuthors } view={ view } onChangeView={ onChangeView } - onClickPreviewField={ onClickPreviewField } + onClickPreview={ onClickPreview } /> - { view.layout.previewField && ( + { view.layout.preview && (
        { previewItem && ( From 122b7436741d4e9af1516600527030fd90249675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Mon, 4 Dec 2023 09:44:08 +0100 Subject: [PATCH 06/30] Take into account layout.preview to render interactivity hook & event handler --- packages/dataviews/src/view-list.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/dataviews/src/view-list.js b/packages/dataviews/src/view-list.js index 3e3b781ab54e8c..eaf7c6f351039f 100644 --- a/packages/dataviews/src/view-list.js +++ b/packages/dataviews/src/view-list.js @@ -17,6 +17,7 @@ export default function ViewList( { const primaryField = fields.find( ( field ) => field.id === view.layout.primaryField ); + return (
          { shownData.map( ( item, index ) => { @@ -24,11 +25,13 @@ export default function ViewList( { // TODO: make li interactive. // fix jsx-a11y/click-events-have-key-events and jsx-a11y/no-noninteractive-element-interactions
        • { - onClickPreview( item ); + if (view.layout.preview) { + onClickPreview( item ); + } }}> { primaryField?.render( { item } ) } - + { view.layout.preview && }
        • ); From 494a1c993b02da9479b80b7cbb596b7b240bc12a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Mon, 4 Dec 2023 18:42:48 +0100 Subject: [PATCH 07/30] Remove preview field: the list view should always have a preview --- packages/dataviews/README.md | 1 - packages/dataviews/src/view-list.js | 19 ++++++++++--------- .../src/components/page-pages/index.js | 3 +-- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/dataviews/README.md b/packages/dataviews/README.md index 758249518d0068..b46cadb251600c 100644 --- a/packages/dataviews/README.md +++ b/packages/dataviews/README.md @@ -78,7 +78,6 @@ Example: - `layout`: config that is specific to a particular layout type. - `mediaField`: used by the `grid` layout. The `id` of the field to be used for rendering each card's media. - `primaryField`: used by the `grid` and `list` layouts. The `id` of the field to be highlighted in each card/list item. - - `preview`: boolean. Only supported by the `list` view. Whether or not previews are supported. ### View <=> data diff --git a/packages/dataviews/src/view-list.js b/packages/dataviews/src/view-list.js index eaf7c6f351039f..feea519fa0c37c 100644 --- a/packages/dataviews/src/view-list.js +++ b/packages/dataviews/src/view-list.js @@ -2,8 +2,7 @@ * WordPress dependencies */ import { useAsyncList } from '@wordpress/compose'; -import { Icon, - __experimentalHStack as HStack,} from '@wordpress/components'; +import { Icon, __experimentalHStack as HStack } from '@wordpress/components'; import { chevronRight } from '@wordpress/icons'; export default function ViewList( { @@ -23,17 +22,19 @@ export default function ViewList( { { shownData.map( ( item, index ) => { return ( // TODO: make li interactive. - // fix jsx-a11y/click-events-have-key-events and jsx-a11y/no-noninteractive-element-interactions -
        • { - if (view.layout.preview) { + /* eslint-disable jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions */ +
        • { onClickPreview( item ); - } - }}> + } } + > - { primaryField?.render( { item } ) } - { view.layout.preview && } + { primaryField?.render( { item } ) } +
        • + /* eslint-enable jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions */ ); } ) }
        diff --git a/packages/edit-site/src/components/page-pages/index.js b/packages/edit-site/src/components/page-pages/index.js index 995e1bff69c33d..2c50501ff0f444 100644 --- a/packages/edit-site/src/components/page-pages/index.js +++ b/packages/edit-site/src/components/page-pages/index.js @@ -50,7 +50,6 @@ const defaultConfigPerViewType = { }, [ LAYOUT_LIST ]: { primaryField: 'title', - preview: true, }, }; @@ -323,7 +322,7 @@ export default function PagePages() { onClickPreview={ onClickPreview } /> - { view.layout.preview && ( + { view.type === LAYOUT_LIST && (
        { previewItem && ( From 658e444735713a5789b2433d757c82852b2e2f88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Mon, 4 Dec 2023 18:45:15 +0100 Subject: [PATCH 08/30] onClickPreview to onSelectionChange --- packages/dataviews/README.md | 2 +- packages/dataviews/src/dataviews.js | 4 ++-- packages/dataviews/src/view-list.js | 4 ++-- packages/edit-site/src/components/page-pages/index.js | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/dataviews/README.md b/packages/dataviews/README.md index b46cadb251600c..8ff98b79180143 100644 --- a/packages/dataviews/README.md +++ b/packages/dataviews/README.md @@ -22,7 +22,7 @@ npm install @wordpress/dataviews --save fields={ fields } actions={ [ trashPostAction ] } paginationInfo={ { totalItems, totalPages } } - onClickPreview={ ( item ) => { /* handle preview */ } } + onSelectionChange={ ( items ) => { /* ... */ } } /> ``` diff --git a/packages/dataviews/src/dataviews.js b/packages/dataviews/src/dataviews.js index 236211f2f7ad33..b680aeb4bd67db 100644 --- a/packages/dataviews/src/dataviews.js +++ b/packages/dataviews/src/dataviews.js @@ -28,7 +28,7 @@ export default function DataViews( { isLoading = false, paginationInfo, supportedLayouts, - onClickPreview, + onSelectionChange, } ) { const ViewComponent = VIEW_LAYOUTS.find( ( v ) => v.type === view.type @@ -73,7 +73,7 @@ export default function DataViews( { data={ data } getItemId={ getItemId } isLoading={ isLoading } - onClickPreview={ onClickPreview } + onSelectionChange={ onSelectionChange } /> { - onClickPreview( item ); + onSelectionChange( [ item ] ); } } > diff --git a/packages/edit-site/src/components/page-pages/index.js b/packages/edit-site/src/components/page-pages/index.js index 2c50501ff0f444..2ddd4c336d625d 100644 --- a/packages/edit-site/src/components/page-pages/index.js +++ b/packages/edit-site/src/components/page-pages/index.js @@ -129,7 +129,7 @@ export default function PagePages() { const [ view, setView ] = useView( postType ); const [ previewItem, setPreview ] = useState(); - const onClickPreview = ( item ) => setPreview( item.id ); + const onSelectionChange = ( item ) => setPreview( item.id ); const queryArgs = useMemo( () => { const filters = {}; @@ -319,7 +319,7 @@ export default function PagePages() { isLoading={ isLoadingPages || isLoadingAuthors } view={ view } onChangeView={ onChangeView } - onClickPreview={ onClickPreview } + onSelectionChange={ onSelectionChange } /> { view.type === LAYOUT_LIST && ( From a0254f11c7f33dd8e7b6757494643cb241f16b4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Mon, 4 Dec 2023 18:50:27 +0100 Subject: [PATCH 09/30] Fix up rebase --- packages/edit-site/src/components/page-pages/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/edit-site/src/components/page-pages/index.js b/packages/edit-site/src/components/page-pages/index.js index 2ddd4c336d625d..adce6d5e512f65 100644 --- a/packages/edit-site/src/components/page-pages/index.js +++ b/packages/edit-site/src/components/page-pages/index.js @@ -24,6 +24,7 @@ import { ENUMERATION_TYPE, LAYOUT_GRID, LAYOUT_TABLE, + LAYOUT_LIST, OPERATOR_IN, OPERATOR_NOT_IN, } from '../../utils/constants'; From 623151f83ef1aa412d41c189c8760099fc8044cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Mon, 4 Dec 2023 18:59:00 +0100 Subject: [PATCH 10/30] Improve code legibility --- packages/dataviews/src/view-list.js | 4 +--- .../edit-site/src/components/page-pages/index.js | 12 ++++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/dataviews/src/view-list.js b/packages/dataviews/src/view-list.js index 151654b5f8243b..ad9523d4e3b4d8 100644 --- a/packages/dataviews/src/view-list.js +++ b/packages/dataviews/src/view-list.js @@ -25,9 +25,7 @@ export default function ViewList( { /* eslint-disable jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions */
      • { - onSelectionChange( [ item ] ); - } } + onClick={ () => onSelectionChange( [ item ] ) } > { primaryField?.render( { item } ) } diff --git a/packages/edit-site/src/components/page-pages/index.js b/packages/edit-site/src/components/page-pages/index.js index adce6d5e512f65..3033ee190e62c5 100644 --- a/packages/edit-site/src/components/page-pages/index.js +++ b/packages/edit-site/src/components/page-pages/index.js @@ -128,9 +128,10 @@ const DEFAULT_STATUSES = 'draft,future,pending,private,publish'; // All but 'tra export default function PagePages() { const postType = 'page'; const [ view, setView ] = useView( postType ); - const [ previewItem, setPreview ] = useState(); + const [ pageId, setPageId ] = useState( null ); - const onSelectionChange = ( item ) => setPreview( item.id ); + const onSelectionChange = ( items ) => + setPageId( items?.length === 1 ? items[ 0 ].id : null ); const queryArgs = useMemo( () => { const filters = {}; @@ -326,13 +327,12 @@ export default function PagePages() { { view.type === LAYOUT_LIST && (
        - { previewItem && ( + { pageId !== null ? ( - ) } - { ! previewItem && ( + ) : (
        Date: Mon, 4 Dec 2023 19:18:54 +0100 Subject: [PATCH 11/30] Do not pass the view to the render --- packages/dataviews/src/view-grid.js | 7 +++---- packages/dataviews/src/view-table.js | 3 +-- packages/edit-site/src/components/page-pages/index.js | 6 +++--- .../src/components/page-templates/dataviews-templates.js | 6 +++--- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/dataviews/src/view-grid.js b/packages/dataviews/src/view-grid.js index 89dd7d393430d9..d28bfa055d946b 100644 --- a/packages/dataviews/src/view-grid.js +++ b/packages/dataviews/src/view-grid.js @@ -43,14 +43,14 @@ export default function ViewGrid( { data, fields, view, actions, getItemId } ) { className="dataviews-view-grid__card" >
        - { mediaField?.render( { item, view } ) } + { mediaField?.render( { item } ) }
        - { primaryField?.render( { item, view } ) } + { primaryField?.render( { item } ) } { const renderedValue = field.render( { item, - view, } ); if ( ! renderedValue ) { return null; @@ -80,7 +79,7 @@ export default function ViewGrid( { data, fields, view, actions, getItemId } ) { { field.header }
        - { field.render( { item, view } ) } + { field.render( { item } ) }
        ); diff --git a/packages/dataviews/src/view-table.js b/packages/dataviews/src/view-table.js index 8b6422b4be11a7..5ce9456344f695 100644 --- a/packages/dataviews/src/view-table.js +++ b/packages/dataviews/src/view-table.js @@ -344,8 +344,7 @@ function ViewTable( { const columns = useMemo( () => { const _columns = fields.map( ( field ) => { const { render, getValue, ...column } = field; - column.cell = ( props ) => - render( { item: props.row.original, view } ); + column.cell = ( props ) => render( { item: props.row.original } ); if ( getValue ) { column.accessorFn = ( item ) => getValue( { item } ); } diff --git a/packages/edit-site/src/components/page-pages/index.js b/packages/edit-site/src/components/page-pages/index.js index 3033ee190e62c5..c530df3d6e6257 100644 --- a/packages/edit-site/src/components/page-pages/index.js +++ b/packages/edit-site/src/components/page-pages/index.js @@ -194,13 +194,13 @@ export default function PagePages() { id: 'featured-image', header: __( 'Featured Image' ), getValue: ( { item } ) => item.featured_media, - render: ( { item, view: currentView } ) => + render: ( { item } ) => !! item.featured_media ? ( { + render: ( { item } ) => { return ( ); }, @@ -229,7 +229,7 @@ export default function DataviewsTemplates() { elements: authors, }, ], - [ authors ] + [ authors, view ] ); const { shownTemplates, paginationInfo } = useMemo( () => { From e70540b9224a09041c4be2fd09a0b938cac92613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Mon, 4 Dec 2023 19:28:38 +0100 Subject: [PATCH 12/30] Make sure media field sizes are set for all views --- packages/edit-site/src/components/page-pages/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/edit-site/src/components/page-pages/index.js b/packages/edit-site/src/components/page-pages/index.js index c530df3d6e6257..291eb99ed46a86 100644 --- a/packages/edit-site/src/components/page-pages/index.js +++ b/packages/edit-site/src/components/page-pages/index.js @@ -200,9 +200,9 @@ export default function PagePages() { className="edit-site-page-pages__featured-image" id={ item.featured_media } size={ - view.type === 'list' - ? [ 'thumbnail', 'medium', 'large', 'full' ] - : [ 'large', 'full', 'medium', 'thumbnail' ] + view.type === LAYOUT_GRID + ? [ 'large', 'full', 'medium', 'thumbnail' ] + : [ 'thumbnail', 'medium', 'large', 'full' ] } /> ) : null, From 58b2a57569605ec0aaaffc928edbf63aa6dd2e07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Tue, 5 Dec 2023 10:15:08 +0100 Subject: [PATCH 13/30] Remove icon: it is meant to open the page details --- packages/dataviews/src/view-list.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/dataviews/src/view-list.js b/packages/dataviews/src/view-list.js index ad9523d4e3b4d8..9d2e00601cfd38 100644 --- a/packages/dataviews/src/view-list.js +++ b/packages/dataviews/src/view-list.js @@ -2,8 +2,7 @@ * WordPress dependencies */ import { useAsyncList } from '@wordpress/compose'; -import { Icon, __experimentalHStack as HStack } from '@wordpress/components'; -import { chevronRight } from '@wordpress/icons'; +import { __experimentalHStack as HStack } from '@wordpress/components'; export default function ViewList( { view, @@ -27,10 +26,7 @@ export default function ViewList( { key={ getItemId?.( item ) || index } onClick={ () => onSelectionChange( [ item ] ) } > - - { primaryField?.render( { item } ) } - - + { primaryField?.render( { item } ) }
      • /* eslint-enable jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions */ ); From e2fbf38d36a0c7ba118af0f856944539f335e66b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Tue, 5 Dec 2023 10:27:14 +0100 Subject: [PATCH 14/30] Display other fields --- packages/dataviews/src/style.scss | 5 +++++ packages/dataviews/src/view-list.js | 26 ++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/packages/dataviews/src/style.scss b/packages/dataviews/src/style.scss index a31da90968d2af..43e7519503a5ab 100644 --- a/packages/dataviews/src/style.scss +++ b/packages/dataviews/src/style.scss @@ -138,7 +138,12 @@ background-color: $gray-100; } } + + .dataviews-list-view__fields { + color: $gray-700; + } } + .dataviews-action-modal { z-index: z-index(".dataviews-action-modal"); } diff --git a/packages/dataviews/src/view-list.js b/packages/dataviews/src/view-list.js index 9d2e00601cfd38..dce31676fb448e 100644 --- a/packages/dataviews/src/view-list.js +++ b/packages/dataviews/src/view-list.js @@ -2,7 +2,10 @@ * WordPress dependencies */ import { useAsyncList } from '@wordpress/compose'; -import { __experimentalHStack as HStack } from '@wordpress/components'; +import { + __experimentalHStack as HStack, + __experimentalVStack as VStack, +} from '@wordpress/components'; export default function ViewList( { view, @@ -15,6 +18,11 @@ export default function ViewList( { const primaryField = fields.find( ( field ) => field.id === view.layout.primaryField ); + const visibleFields = fields.filter( + ( field ) => + ! view.hiddenFields.includes( field.id ) && + view.layout.primaryField !== field.id + ); return (
          @@ -26,7 +34,21 @@ export default function ViewList( { key={ getItemId?.( item ) || index } onClick={ () => onSelectionChange( [ item ] ) } > - { primaryField?.render( { item } ) } + + { primaryField?.render( { item } ) } + + { visibleFields.map( ( field ) => { + return ( + + { field.render( { item } ) } + + ); + } ) } + + /* eslint-enable jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions */ ); From 6910c9f5169052719f181f1e0737ff182b85340c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Tue, 5 Dec 2023 11:07:05 +0100 Subject: [PATCH 15/30] Display mediaField --- packages/dataviews/src/style.scss | 12 ++++++ packages/dataviews/src/view-list.js | 42 ++++++++++++------- .../src/components/page-pages/index.js | 1 + 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/packages/dataviews/src/style.scss b/packages/dataviews/src/style.scss index 43e7519503a5ab..f44f44bcf4078c 100644 --- a/packages/dataviews/src/style.scss +++ b/packages/dataviews/src/style.scss @@ -139,6 +139,18 @@ } } + .edit-site-page-pages__featured-image, + .dataviews-list-view__media-placeholder { + width: 45px; + height: 45px; + margin-right: 1em; + } + + .dataviews-list-view__media-placeholder { + background-color: $gray-200; + border-radius: $radius-block-ui; + } + .dataviews-list-view__fields { color: $gray-700; } diff --git a/packages/dataviews/src/view-list.js b/packages/dataviews/src/view-list.js index dce31676fb448e..55fae860f2b173 100644 --- a/packages/dataviews/src/view-list.js +++ b/packages/dataviews/src/view-list.js @@ -15,13 +15,18 @@ export default function ViewList( { onSelectionChange, } ) { const shownData = useAsyncList( data, { step: 3 } ); + const mediaField = fields.find( + ( field ) => field.id === view.layout.mediaField + ); const primaryField = fields.find( ( field ) => field.id === view.layout.primaryField ); const visibleFields = fields.filter( ( field ) => ! view.hiddenFields.includes( field.id ) && - view.layout.primaryField !== field.id + ! [ view.layout.primaryField, view.layout.mediaField ].includes( + field.id + ) ); return ( @@ -34,21 +39,28 @@ export default function ViewList( { key={ getItemId?.( item ) || index } onClick={ () => onSelectionChange( [ item ] ) } > - - { primaryField?.render( { item } ) } - - { visibleFields.map( ( field ) => { - return ( - - { field.render( { item } ) } - - ); - } ) } + + { mediaField?.render( { item } ) || ( +
          + ) } + + + { primaryField?.render( { item } ) } + + { visibleFields.map( ( field ) => { + return ( + + { field.render( { item } ) } + + ); + } ) } + + -
          + /* eslint-enable jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions */ ); diff --git a/packages/edit-site/src/components/page-pages/index.js b/packages/edit-site/src/components/page-pages/index.js index 291eb99ed46a86..2a7a66298744c6 100644 --- a/packages/edit-site/src/components/page-pages/index.js +++ b/packages/edit-site/src/components/page-pages/index.js @@ -51,6 +51,7 @@ const defaultConfigPerViewType = { }, [ LAYOUT_LIST ]: { primaryField: 'title', + mediaField: 'featured-image', }, }; From b822691d2c3df5082733255c627f0f20e7995ef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Tue, 5 Dec 2023 11:19:19 +0100 Subject: [PATCH 16/30] Document use of mediaField --- packages/dataviews/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dataviews/README.md b/packages/dataviews/README.md index 8ff98b79180143..c0d0a01cbc3e28 100644 --- a/packages/dataviews/README.md +++ b/packages/dataviews/README.md @@ -76,7 +76,7 @@ Example: - `value`: the actual value selected by the user. - `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` layout. The `id` of the field to be used for rendering each card's media. + - `mediaField`: used by the `grid` and `list` layouts. The `id` of the field to be used for rendering each card's media. - `primaryField`: used by the `grid` and `list` layouts. The `id` of the field to be highlighted in each card/list item. ### View <=> data From 4d6994b6f960c9877da720389ba65cde4b6307d4 Mon Sep 17 00:00:00 2001 From: James Koster Date: Tue, 5 Dec 2023 12:16:56 +0000 Subject: [PATCH 17/30] Styling --- packages/dataviews/src/style.scss | 44 +++++++++++++++++++++++++---- packages/dataviews/src/view-list.js | 16 +++++------ 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/packages/dataviews/src/style.scss b/packages/dataviews/src/style.scss index f44f44bcf4078c..91d70839a30fc9 100644 --- a/packages/dataviews/src/style.scss +++ b/packages/dataviews/src/style.scss @@ -129,30 +129,64 @@ .dataviews-list-view { li { - padding: $grid-unit-20 $grid-unit-40; + padding: $grid-unit-15 $grid-unit-40; border-bottom: $border-width solid $gray-100; + margin: 0; &:last-child { border-bottom: 0; } &:hover { background-color: $gray-100; } + h3 { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + } + } + + .dataviews-list-view__media-wrapper { + min-width: $grid-unit-40; + height: $grid-unit-40; + border-radius: $grid-unit-05; + overflow: hidden; + position: relative; + + &:after { + content: ""; + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + box-shadow: inset 0 0 0 $border-width rgba(0,0,0,0.1); + border-radius: $grid-unit-05; + } } .edit-site-page-pages__featured-image, .dataviews-list-view__media-placeholder { - width: 45px; - height: 45px; - margin-right: 1em; + min-width: $grid-unit-40; + height: $grid-unit-40; } .dataviews-list-view__media-placeholder { background-color: $gray-200; - border-radius: $radius-block-ui; } .dataviews-list-view__fields { color: $gray-700; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + + .dataviews-list-view__field { + margin-right: $grid-unit-15; + + &:last-child { + margin-right: 0; + } + } } } diff --git a/packages/dataviews/src/view-list.js b/packages/dataviews/src/view-list.js index 55fae860f2b173..b8ede1d6115f69 100644 --- a/packages/dataviews/src/view-list.js +++ b/packages/dataviews/src/view-list.js @@ -39,25 +39,25 @@ export default function ViewList( { key={ getItemId?.( item ) || index } onClick={ () => onSelectionChange( [ item ] ) } > - + { mediaField?.render( { item } ) || (
          ) } - + { primaryField?.render( { item } ) } - +
          { visibleFields.map( ( field ) => { return ( - + { field.render( { item } ) } ); } ) } - +
          From d0aaf512bef7a5fd49f86650e1d7cb94f79687bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Tue, 5 Dec 2023 13:25:04 +0100 Subject: [PATCH 18/30] Use an element other than li as interactive --- packages/dataviews/package.json | 1 + packages/dataviews/src/style.scss | 10 +++-- packages/dataviews/src/view-list.js | 68 +++++++++++++++++------------ 3 files changed, 48 insertions(+), 31 deletions(-) diff --git a/packages/dataviews/package.json b/packages/dataviews/package.json index 40a09050b94321..3d15ea435ab4f8 100644 --- a/packages/dataviews/package.json +++ b/packages/dataviews/package.json @@ -35,6 +35,7 @@ "@wordpress/element": "file:../element", "@wordpress/i18n": "file:../i18n", "@wordpress/icons": "file:../icons", + "@wordpress/keycodes": "file:../keycodes", "@wordpress/private-apis": "file:../private-apis", "classnames": "^2.3.1", "remove-accents": "^0.5.0" diff --git a/packages/dataviews/src/style.scss b/packages/dataviews/src/style.scss index 91d70839a30fc9..19992c9c2bbbaf 100644 --- a/packages/dataviews/src/style.scss +++ b/packages/dataviews/src/style.scss @@ -129,13 +129,17 @@ .dataviews-list-view { li { - padding: $grid-unit-15 $grid-unit-40; border-bottom: $border-width solid $gray-100; - margin: 0; &:last-child { border-bottom: 0; } - &:hover { + } + + .dataviews-list-view__item { + padding: $grid-unit-15 $grid-unit-40; + margin: 0; + &:hover, + &:focus { background-color: $gray-100; } h3 { diff --git a/packages/dataviews/src/view-list.js b/packages/dataviews/src/view-list.js index b8ede1d6115f69..84b101683f32f5 100644 --- a/packages/dataviews/src/view-list.js +++ b/packages/dataviews/src/view-list.js @@ -6,6 +6,7 @@ import { __experimentalHStack as HStack, __experimentalVStack as VStack, } from '@wordpress/components'; +import { ENTER } from '@wordpress/keycodes'; export default function ViewList( { view, @@ -29,40 +30,51 @@ export default function ViewList( { ) ); + const onEnter = ( item ) => ( event ) => { + const { keyCode } = event; + if ( keyCode === ENTER ) { + onSelectionChange( [ item ] ); + } + }; + return (
            { shownData.map( ( item, index ) => { return ( - // TODO: make li interactive. - /* eslint-disable jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions */ -
          • onSelectionChange( [ item ] ) } - > - - { mediaField?.render( { item } ) || ( -
            - ) } - - - { primaryField?.render( { item } ) } -
            - { visibleFields.map( ( field ) => { - return ( - - { field.render( { item } ) } - - ); - } ) } -
            -
            +
          • +
            onSelectionChange( [ item ] ) } + > + + { mediaField?.render( { item } ) || ( +
            + ) } + + + { primaryField?.render( { item } ) } +
            + { visibleFields.map( ( field ) => { + return ( + + { field.render( { + item, + } ) } + + ); + } ) } +
            +
            +
            - +
          • - /* eslint-enable jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions */ ); } ) }
          From b081b155d2d0d14600732e8c405d9b1a0af5cb55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Tue, 5 Dec 2023 14:27:15 +0100 Subject: [PATCH 19/30] Track selection --- packages/dataviews/src/dataviews.js | 12 ++++++++++-- packages/dataviews/src/style.scss | 8 ++++++-- packages/dataviews/src/view-list.js | 14 +++++++++++++- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/packages/dataviews/src/dataviews.js b/packages/dataviews/src/dataviews.js index b680aeb4bd67db..21d5b24aec345d 100644 --- a/packages/dataviews/src/dataviews.js +++ b/packages/dataviews/src/dataviews.js @@ -5,7 +5,7 @@ import { __experimentalVStack as VStack, __experimentalHStack as HStack, } from '@wordpress/components'; -import { useMemo } from '@wordpress/element'; +import { useMemo, useState } from '@wordpress/element'; /** * Internal dependencies @@ -30,6 +30,13 @@ export default function DataViews( { supportedLayouts, onSelectionChange, } ) { + const [ selection, setSelection ] = useState( [] ); + + const onSetSelection = ( items ) => { + setSelection( items.map( ( item ) => item.id ) ); + onSelectionChange( items ); + }; + const ViewComponent = VIEW_LAYOUTS.find( ( v ) => v.type === view.type ).component; @@ -73,7 +80,8 @@ export default function DataViews( { data={ data } getItemId={ getItemId } isLoading={ isLoading } - onSelectionChange={ onSelectionChange } + onSelectionChange={ onSetSelection } + selection={ selection } /> onSelectionChange( [ item ] ) } > From 771f5f471e95bcefcd849377a6e138b23659043f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Tue, 5 Dec 2023 14:30:33 +0100 Subject: [PATCH 20/30] Do not render a link for the primary field in the list view --- .../src/components/page-pages/index.js | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/packages/edit-site/src/components/page-pages/index.js b/packages/edit-site/src/components/page-pages/index.js index 2a7a66298744c6..d283264a096efd 100644 --- a/packages/edit-site/src/components/page-pages/index.js +++ b/packages/edit-site/src/components/page-pages/index.js @@ -217,17 +217,25 @@ export default function PagePages() { return ( - - { decodeEntities( + { [ LAYOUT_TABLE, LAYOUT_GRID ].includes( + view.type + ) ? ( + + { decodeEntities( + item.title?.rendered || item.slug + ) || __( '(no title)' ) } + + ) : ( + decodeEntities( item.title?.rendered || item.slug - ) || __( '(no title)' ) } - + ) || __( '(no title)' ) + ) } ); From 32dcc5d983977da68c2fc38038865ed7993bf170 Mon Sep 17 00:00:00 2001 From: James Koster Date: Tue, 5 Dec 2023 13:47:53 +0000 Subject: [PATCH 21/30] Media wrapper and list item margin --- packages/dataviews/src/style.scss | 2 +- packages/dataviews/src/view-list.js | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/dataviews/src/style.scss b/packages/dataviews/src/style.scss index b1a4168a549df3..c8ff62439e7dda 100644 --- a/packages/dataviews/src/style.scss +++ b/packages/dataviews/src/style.scss @@ -130,6 +130,7 @@ .dataviews-list-view { li { border-bottom: $border-width solid $gray-100; + margin: 0; &:last-child { border-bottom: 0; } @@ -137,7 +138,6 @@ .dataviews-list-view__item { padding: $grid-unit-15 $grid-unit-40; - margin: 0; &:hover, &:focus { background-color: $gray-100; diff --git a/packages/dataviews/src/view-list.js b/packages/dataviews/src/view-list.js index bb2385058b0471..329a89db4a4d96 100644 --- a/packages/dataviews/src/view-list.js +++ b/packages/dataviews/src/view-list.js @@ -62,9 +62,11 @@ export default function ViewList( { onClick={ () => onSelectionChange( [ item ] ) } > - { mediaField?.render( { item } ) || ( -
          - ) } +
          + { mediaField?.render( { item } ) || ( +
          + ) } +
          { primaryField?.render( { item } ) } From c0e1a365d85e6a62d6588238f9c01ad5c087d47c Mon Sep 17 00:00:00 2001 From: James Koster Date: Tue, 5 Dec 2023 13:55:17 +0000 Subject: [PATCH 22/30] Item interaction styles --- packages/dataviews/src/style.scss | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/dataviews/src/style.scss b/packages/dataviews/src/style.scss index c8ff62439e7dda..439f1a02421516 100644 --- a/packages/dataviews/src/style.scss +++ b/packages/dataviews/src/style.scss @@ -138,9 +138,9 @@ .dataviews-list-view__item { padding: $grid-unit-15 $grid-unit-40; - &:hover, - &:focus { - background-color: $gray-100; + cursor: default; + &:hover { + background-color: lighten($gray-100,3%); } h3 { overflow: hidden; @@ -149,8 +149,9 @@ } } - .dataviews-list-view__item-selected { - background-color: $gray-200; + .dataviews-list-view__item-selected, + .dataviews-list-view__item-selected:hover { + background-color: $gray-100; } .dataviews-list-view__media-wrapper { From 525c93c8f861b918c5bd4f87051ed028dfae2211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Tue, 5 Dec 2023 16:01:26 +0100 Subject: [PATCH 23/30] Fix CSS lint issue --- packages/dataviews/src/style.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dataviews/src/style.scss b/packages/dataviews/src/style.scss index 439f1a02421516..0a50d189bc9225 100644 --- a/packages/dataviews/src/style.scss +++ b/packages/dataviews/src/style.scss @@ -140,7 +140,7 @@ padding: $grid-unit-15 $grid-unit-40; cursor: default; &:hover { - background-color: lighten($gray-100,3%); + background-color: lighten($gray-100, 3%); } h3 { overflow: hidden; From a8447bba92666367f8c231a5454e634d3e7b6abe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Tue, 5 Dec 2023 16:03:02 +0100 Subject: [PATCH 24/30] Selected item focus: use same styles as hover --- packages/dataviews/src/style.scss | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/dataviews/src/style.scss b/packages/dataviews/src/style.scss index 0a50d189bc9225..1e0800885e09ba 100644 --- a/packages/dataviews/src/style.scss +++ b/packages/dataviews/src/style.scss @@ -139,6 +139,7 @@ .dataviews-list-view__item { padding: $grid-unit-15 $grid-unit-40; cursor: default; + &:focus, &:hover { background-color: lighten($gray-100, 3%); } @@ -150,7 +151,8 @@ } .dataviews-list-view__item-selected, - .dataviews-list-view__item-selected:hover { + .dataviews-list-view__item-selected:hover, + .dataviews-list-view__item-selected:focus { background-color: $gray-100; } From 1f72b3605e952150dab038bc74def4cca6a3560b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Tue, 5 Dec 2023 16:19:26 +0100 Subject: [PATCH 25/30] Add keycodes to package-lock --- package-lock.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package-lock.json b/package-lock.json index 80a3f384e808ed..ec0fbd96b0cb19 100644 --- a/package-lock.json +++ b/package-lock.json @@ -55075,6 +55075,7 @@ "@wordpress/element": "file:../element", "@wordpress/i18n": "file:../i18n", "@wordpress/icons": "file:../icons", + "@wordpress/keycodes": "file:../keycodes", "@wordpress/private-apis": "file:../private-apis", "classnames": "^2.3.1", "remove-accents": "^0.5.0" @@ -70411,6 +70412,7 @@ "@wordpress/element": "file:../element", "@wordpress/i18n": "file:../i18n", "@wordpress/icons": "file:../icons", + "@wordpress/keycodes": "file:../keycodes", "@wordpress/private-apis": "file:../private-apis", "classnames": "^2.3.1", "remove-accents": "^0.5.0" From 9013662f983b36b13b9d7bd8b9074dea77963705 Mon Sep 17 00:00:00 2001 From: James Koster Date: Tue, 5 Dec 2023 15:42:45 +0000 Subject: [PATCH 26/30] Focus styles --- packages/dataviews/src/style.scss | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/dataviews/src/style.scss b/packages/dataviews/src/style.scss index 1e0800885e09ba..b4f4ac0c28f956 100644 --- a/packages/dataviews/src/style.scss +++ b/packages/dataviews/src/style.scss @@ -143,6 +143,9 @@ &:hover { background-color: lighten($gray-100, 3%); } + &:focus { + box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color); + } h3 { overflow: hidden; text-overflow: ellipsis; @@ -151,9 +154,12 @@ } .dataviews-list-view__item-selected, - .dataviews-list-view__item-selected:hover, - .dataviews-list-view__item-selected:focus { + .dataviews-list-view__item-selected:hover { background-color: $gray-100; + + &:focus { + box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color); + } } .dataviews-list-view__media-wrapper { From ed554c5130e7d7097a912a024dc4fae489d74824 Mon Sep 17 00:00:00 2001 From: James Koster Date: Tue, 5 Dec 2023 16:04:50 +0000 Subject: [PATCH 27/30] Heading weight --- packages/edit-site/src/components/page-pages/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/edit-site/src/components/page-pages/index.js b/packages/edit-site/src/components/page-pages/index.js index d283264a096efd..fe6f50a4a9c070 100644 --- a/packages/edit-site/src/components/page-pages/index.js +++ b/packages/edit-site/src/components/page-pages/index.js @@ -216,7 +216,7 @@ export default function PagePages() { render: ( { item } ) => { return ( - + { [ LAYOUT_TABLE, LAYOUT_GRID ].includes( view.type ) ? ( From 4d3a7f280976912f53bc65e0842df3fdc6b336a9 Mon Sep 17 00:00:00 2001 From: James Koster Date: Tue, 5 Dec 2023 16:27:45 +0000 Subject: [PATCH 28/30] Use formatListBullets for list view --- packages/dataviews/src/constants.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/dataviews/src/constants.js b/packages/dataviews/src/constants.js index 4512ddd880e1e4..387050a1dca5b6 100644 --- a/packages/dataviews/src/constants.js +++ b/packages/dataviews/src/constants.js @@ -1,8 +1,13 @@ /** * WordPress dependencies */ -import { __ } from '@wordpress/i18n'; -import { blockTable, category, drawerLeft } from '@wordpress/icons'; +import { __, isRTL } from '@wordpress/i18n'; +import { + blockTable, + category, + formatListBullets, + formatListBulletsRTL, +} from '@wordpress/icons'; /** * Internal dependencies @@ -40,6 +45,6 @@ export const VIEW_LAYOUTS = [ type: LAYOUT_LIST, label: __( 'List' ), component: ViewList, - icon: drawerLeft, + icon: isRTL() ? formatListBulletsRTL : formatListBullets, }, ]; From 5621413d68a91707405c59e69c1769eb640f1389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Tue, 5 Dec 2023 17:34:01 +0100 Subject: [PATCH 29/30] Button role: support SPACE --- packages/dataviews/src/view-list.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/dataviews/src/view-list.js b/packages/dataviews/src/view-list.js index 329a89db4a4d96..10c74aff2ecf14 100644 --- a/packages/dataviews/src/view-list.js +++ b/packages/dataviews/src/view-list.js @@ -11,7 +11,7 @@ import { __experimentalHStack as HStack, __experimentalVStack as VStack, } from '@wordpress/components'; -import { ENTER } from '@wordpress/keycodes'; +import { ENTER, SPACE } from '@wordpress/keycodes'; export default function ViewList( { view, @@ -38,7 +38,7 @@ export default function ViewList( { const onEnter = ( item ) => ( event ) => { const { keyCode } = event; - if ( keyCode === ENTER ) { + if ( [ ENTER, SPACE ].includes( keyCode ) ) { onSelectionChange( [ item ] ); } }; From 4d0011d221fdc0b146bec5baa480e28a84d7a77e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Tue, 5 Dec 2023 17:35:19 +0100 Subject: [PATCH 30/30] Button role: add aria-pressed --- packages/dataviews/src/view-list.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/dataviews/src/view-list.js b/packages/dataviews/src/view-list.js index 10c74aff2ecf14..cd9b651cabca55 100644 --- a/packages/dataviews/src/view-list.js +++ b/packages/dataviews/src/view-list.js @@ -51,6 +51,7 @@ export default function ViewList( {