Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataViews: make list layout the default for templates with the experiment enabled #57933

Merged
merged 5 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/edit-site/src/components/page-main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <PageTemplates />;
} else if ( path === '/wp_template_part/all' ) {
return <PageTemplateParts />;
Expand Down
15 changes: 14 additions & 1 deletion packages/edit-site/src/components/page-templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const defaultConfigPerViewType = {
};

const DEFAULT_VIEW = {
type: LAYOUT_TABLE,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got a minimal follow-up #57960

I realized that we may still want to use the table layout when the experiment is disabled ("site editor > templates > manage all templates"), as the list layout is not stable yet.

type: LAYOUT_LIST,
search: '',
page: 1,
perPage: 20,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -363,6 +375,7 @@ export default function DataviewsTemplates() {
view={ view }
onChangeView={ onChangeView }
onSelectionChange={ onSelectionChange }
onDetailsChange={ onDetailsChange }
deferredRendering={
! view.hiddenFields?.includes( 'preview' )
}
Expand Down
6 changes: 5 additions & 1 deletion packages/edit-site/src/components/sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ function SidebarScreens() {
<SidebarNavigationScreenPage />
</SidebarScreenWrapper>
<SidebarScreenWrapper path="/:postType(wp_template)">
<SidebarNavigationScreenTemplates />
{ window?.__experimentalAdminViews ? (
<SidebarNavigationScreenTemplatesBrowse />
) : (
<SidebarNavigationScreenTemplates />
) }
</SidebarScreenWrapper>
<SidebarScreenWrapper path="/patterns">
<SidebarNavigationScreenPatterns />
Expand Down
1 change: 1 addition & 0 deletions packages/edit-site/src/utils/get-is-list-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 19 additions & 3 deletions test/e2e/specs/site-editor/new-templates-list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should start dividing some tests per view..

// Descending by title.
await page
.getByRole( 'button', { name: 'Template', exact: true } )
Expand Down Expand Up @@ -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' );
Expand Down Expand Up @@ -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(
Expand Down
Loading