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

Site Editor: Redirect /wp_template_part/all to /patterns #61446

Merged
merged 7 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 12 additions & 5 deletions packages/edit-site/src/components/layout/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { __ } from '@wordpress/i18n';

import { useEffect } from '@wordpress/element';
/**
* Internal dependencies
*/
Expand Down Expand Up @@ -33,6 +33,14 @@ export default function useLayoutAreas() {
const { params } = useLocation();
const { postType, postId, path, layout, isCustom, canvas } = params;

useEffect( () => {
// `/wp_template_part/all` path is no longer used and redirects to
// Patterns page for backward compatibility.
if ( path === '/wp_template_part/all' ) {
history.replace( { path: '/patterns' } );
}
}, [ history, path ] );

// Note: Since "sidebar" is not yet supported here,
// returning undefined from "mobile" means show the sidebar.

Expand Down Expand Up @@ -140,10 +148,9 @@ export default function useLayoutAreas() {
};
}

/* Patterns and Template Parts
* `/wp_template_part/all` path is no longer used, but uses Patterns page screens for
* backwards compatibility.
*/
// Patterns
// `/wp_template_part/all` path is no longer used and redirects to
// Patterns page for backward compatibility.
if ( path === '/patterns' || path === '/wp_template_part/all' ) {
t-hamano marked this conversation as resolved.
Show resolved Hide resolved
return {
key: 'patterns',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,6 @@ export default function SidebarNavigationScreenPatterns( { backPath } ) {
[]
);

/**
* This sidebar needs to temporarily accomodate two different "URLs":
*
* 1. path = /patterns
* Block based themes. Also classic themes can access this URL, though it's not linked anywhere.
*
* 2. path = /wp_template_part/all
* Classic themes with support for block-template-parts. We need to list only Template Parts in this case.
* The URL is accessible from the Appearance > Template Parts menu.
*
* This is temporary. We aim to consolidate to /patterns.
*/
return (
<SidebarNavigationScreen
isRoot={ ! isBlockBasedTheme }
Expand Down
4 changes: 1 addition & 3 deletions packages/edit-site/src/utils/get-is-list-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ export default function getIsListPage(
isMobileViewport
) {
return (
[ '/wp_template', '/wp_template_part/all', '/pages' ].includes(
path
) ||
[ '/wp_template', '/pages' ].includes( path ) ||
Copy link
Contributor Author

@t-hamano t-hamano May 7, 2024

Choose a reason for hiding this comment

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

The concern about deleting /wp_template_part/all from this array is discussed in this comment, but it should be possible to delete it with this PR.

( 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
6 changes: 5 additions & 1 deletion test/e2e/specs/site-editor/hybrid-theme.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test.describe( 'Hybrid theme', () => {
).toBeVisible();
} );

test( 'should show Patterns page when accessing template parts list page', async ( {
test( 'should redirect to Patterns page when accessing template parts list page', async ( {
admin,
page,
} ) => {
Expand All @@ -32,6 +32,10 @@ test.describe( 'Hybrid theme', () => {
'path=/wp_template_part/all'
);

await expect( page ).toHaveURL(
'/wp-admin/site-editor.php?path=%2Fpatterns'
);

await expect(
page.getByRole( 'heading', { level: 1, text: 'Patterns' } )
).toBeVisible();
Expand Down