Skip to content

Commit

Permalink
Site Editor: Redirect /wp_template_part/all to /patterns (#61446)
Browse files Browse the repository at this point in the history
* Site Editor: Redirect `/wp_template_part/all to `/patterns`

* Fix e2e test

* Move redirect rule to edit-site package

* Remove dependencies

* Change useLayutEffect to useEffect

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: oandregal <oandregal@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>
  • Loading branch information
5 people committed May 14, 2024
1 parent c70ea83 commit 7e2302c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
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' ) {
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 ) ||
( 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

0 comments on commit 7e2302c

Please sign in to comment.