diff --git a/packages/edit-site/src/components/page-main/index.js b/packages/edit-site/src/components/page-main/index.js index 7cc2025ac2c94..fead1b9dbc11e 100644 --- a/packages/edit-site/src/components/page-main/index.js +++ b/packages/edit-site/src/components/page-main/index.js @@ -20,7 +20,10 @@ export default function PageMain() { params: { path }, } = useLocation(); - if ( path === '/wp_template/all' ) { + if ( + path === '/wp_template/all' || + ( path === '/wp_template' && window?.__experimentalAdminViews ) + ) { return ; } else if ( path === '/wp_template_part/all' ) { return ; diff --git a/packages/edit-site/src/components/page-templates/index.js b/packages/edit-site/src/components/page-templates/index.js index fd28c22298ba1..d9d99200506c6 100644 --- a/packages/edit-site/src/components/page-templates/index.js +++ b/packages/edit-site/src/components/page-templates/index.js @@ -77,7 +77,7 @@ const defaultConfigPerViewType = { }; const DEFAULT_VIEW = { - type: LAYOUT_TABLE, + type: LAYOUT_LIST, search: '', page: 1, perPage: 20, @@ -170,6 +170,18 @@ export default function DataviewsTemplates() { [ setTemplateId ] ); + const onDetailsChange = useCallback( + ( items ) => { + if ( items?.length === 1 ) { + history.push( { + postId: items[ 0 ].id, + postType: TEMPLATE_POST_TYPE, + } ); + } + }, + [ history ] + ); + const authors = useMemo( () => { if ( ! allTemplates ) { return EMPTY_ARRAY; @@ -363,6 +375,7 @@ export default function DataviewsTemplates() { view={ view } onChangeView={ onChangeView } onSelectionChange={ onSelectionChange } + onDetailsChange={ onDetailsChange } deferredRendering={ ! view.hiddenFields?.includes( 'preview' ) } diff --git a/packages/edit-site/src/components/sidebar/index.js b/packages/edit-site/src/components/sidebar/index.js index 73c6aea7e328c..1d0be62982e87 100644 --- a/packages/edit-site/src/components/sidebar/index.js +++ b/packages/edit-site/src/components/sidebar/index.js @@ -76,7 +76,11 @@ function SidebarScreens() { - + { window?.__experimentalAdminViews ? ( + + ) : ( + + ) } diff --git a/packages/edit-site/src/utils/get-is-list-page.js b/packages/edit-site/src/utils/get-is-list-page.js index 9530cd85bf04b..3028b0e65d786 100644 --- a/packages/edit-site/src/utils/get-is-list-page.js +++ b/packages/edit-site/src/utils/get-is-list-page.js @@ -16,6 +16,7 @@ export default function getIsListPage( return ( [ '/wp_template/all', '/wp_template_part/all' ].includes( path ) || ( path === '/page' && window?.__experimentalAdminViews ) || + ( path === '/wp_template' && window?.__experimentalAdminViews ) || ( path === '/patterns' && // Don't treat "/patterns" without categoryType and categoryId as a // list page in mobile because the sidebar covers the whole page. diff --git a/test/e2e/specs/site-editor/new-templates-list.spec.js b/test/e2e/specs/site-editor/new-templates-list.spec.js index 13484abcb13ad..272a3ffff80bf 100644 --- a/test/e2e/specs/site-editor/new-templates-list.spec.js +++ b/test/e2e/specs/site-editor/new-templates-list.spec.js @@ -18,7 +18,11 @@ test.describe( 'Templates', () => { ] ); } ); test( 'Sorting', async ( { admin, page } ) => { - await admin.visitSiteEditor( { path: '/wp_template/all' } ); + await admin.visitSiteEditor( { path: '/wp_template' } ); + // Switch to table layout. + await page.getByLabel( 'View options' ).click(); + await page.getByRole( 'menuitem', { name: 'Layout' } ).click(); + await page.getByRole( 'menuitemradio', { name: 'Table' } ).click(); // Descending by title. await page .getByRole( 'button', { name: 'Template', exact: true } ) @@ -48,7 +52,13 @@ test.describe( 'Templates', () => { title: 'Date Archives', content: 'hi', } ); - await admin.visitSiteEditor( { path: '/wp_template/all' } ); + await admin.visitSiteEditor( { path: '/wp_template' } ); + + // Switch to table layout. + await page.getByLabel( 'View options' ).click(); + await page.getByRole( 'menuitem', { name: 'Layout' } ).click(); + await page.getByRole( 'menuitemradio', { name: 'Table' } ).click(); + // Global search. await page.getByRole( 'searchbox', { name: 'Filter list' } ).click(); await page.keyboard.type( 'tag' ); @@ -84,7 +94,13 @@ test.describe( 'Templates', () => { await expect( titles ).toHaveCount( 2 ); } ); test( 'Field visibility', async ( { admin, page } ) => { - await admin.visitSiteEditor( { path: '/wp_template/all' } ); + await admin.visitSiteEditor( { path: '/wp_template' } ); + + // Switch to table layout. + await page.getByLabel( 'View options' ).click(); + await page.getByRole( 'menuitem', { name: 'Layout' } ).click(); + await page.getByRole( 'menuitemradio', { name: 'Table' } ).click(); + await page.getByRole( 'button', { name: 'Description' } ).click(); await page.getByRole( 'menuitem', { name: 'Hide' } ).click(); await expect(