From cd580e738ebfcc263afbaa385e13f2ecec3c5fea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Thu, 11 Apr 2024 13:34:50 +0200 Subject: [PATCH 1/7] Go back to patterns when deleting a part from the editor sidebar --- .../src/components/sidebar-edit-mode/template-panel/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/edit-site/src/components/sidebar-edit-mode/template-panel/index.js b/packages/edit-site/src/components/sidebar-edit-mode/template-panel/index.js index be747956a5c7d..f656858e11fa2 100644 --- a/packages/edit-site/src/components/sidebar-edit-mode/template-panel/index.js +++ b/packages/edit-site/src/components/sidebar-edit-mode/template-panel/index.js @@ -52,7 +52,7 @@ function TemplatesList( { availableTemplates, onSelect } ) { const POST_TYPE_PATH = { wp_template: '/wp_template', - wp_template_part: '/wp_template_part/all', + wp_template_part: '/patterns', }; export default function TemplatePanel() { From c66a62efa99013d1ddf92fd5ea3bf039b43f59f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:05:06 +0200 Subject: [PATCH 2/7] Details page for parts: always go back to patterns --- .../sidebar-navigation-screen-pattern/index.js | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pattern/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-pattern/index.js index 693d16914869a..7669e0575427f 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-pattern/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-pattern/index.js @@ -5,7 +5,6 @@ import { __experimentalUseNavigator as useNavigator } from '@wordpress/component import { useDispatch } from '@wordpress/data'; import { __ } from '@wordpress/i18n'; import { pencil } from '@wordpress/icons'; -import { getQueryArgs } from '@wordpress/url'; /** * Internal dependencies @@ -17,27 +16,18 @@ import usePatternDetails from './use-pattern-details'; import { store as editSiteStore } from '../../store'; import { unlock } from '../../lock-unlock'; import TemplateActions from '../template-actions'; -import { TEMPLATE_PART_POST_TYPE } from '../../utils/constants'; export default function SidebarNavigationScreenPattern() { const navigator = useNavigator(); const { params: { postType, postId }, } = navigator; - const { categoryType } = getQueryArgs( window.location.href ); const { setCanvasMode } = unlock( useDispatch( editSiteStore ) ); useInitEditedEntityFromURL(); const patternDetails = usePatternDetails( postType, postId ); - - // The absence of a category type in the query params for template parts - // indicates the user has arrived at the template part via the "manage all" - // page and the back button should return them to that list page. - const backPath = - ! categoryType && postType === TEMPLATE_PART_POST_TYPE - ? '/wp_template_part/all' - : '/patterns'; + const backPath = '/patterns'; return ( Date: Thu, 11 Apr 2024 14:11:54 +0200 Subject: [PATCH 3/7] Remove unnecessary backPath: it is managed by the details page --- .../src/components/page-templates-template-parts/index.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/edit-site/src/components/page-templates-template-parts/index.js b/packages/edit-site/src/components/page-templates-template-parts/index.js index f12306f6727ce..3bfc1ecb08a35 100644 --- a/packages/edit-site/src/components/page-templates-template-parts/index.js +++ b/packages/edit-site/src/components/page-templates-template-parts/index.js @@ -35,7 +35,6 @@ import AddNewTemplate from '../add-new-template'; import { useAddedBy } from './hooks'; import { TEMPLATE_POST_TYPE, - TEMPLATE_PART_POST_TYPE, ENUMERATION_TYPE, OPERATOR_IS_ANY, LAYOUT_GRID, @@ -102,11 +101,6 @@ function Title( { item, viewType } ) { canvas: 'edit', }, }; - if ( item.type === TEMPLATE_PART_POST_TYPE ) { - linkProps.state = { - backPath: '/wp_template_part/all', - }; - } return ( { decodeEntities( item.title?.rendered ) || __( '(no title)' ) } From 3084583dec6a147a8a517a27db67e7406d514db6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:13:56 +0200 Subject: [PATCH 4/7] Remove logic for template part: it is never used --- .../components/sidebar-navigation-screen-template/index.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-template/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-template/index.js index fef2a1c546b3d..cc35404f5e0a2 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-template/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-template/index.js @@ -93,11 +93,6 @@ function useTemplateDetails( postType, postId ) { return { title, description, content, footer }; } -const POST_TYPE_PATH = { - wp_template: '/wp_template', - wp_template_part: '/wp_template_part/all', -}; - export default function SidebarNavigationScreenTemplate() { const navigator = useNavigator(); const { @@ -119,7 +114,7 @@ export default function SidebarNavigationScreenTemplate() { postId={ postId } toggleProps={ { as: SidebarButton } } onRemove={ () => { - navigator.goTo( POST_TYPE_PATH[ postType ] ); + navigator.goTo( postType ); } } /> Date: Thu, 11 Apr 2024 14:17:25 +0200 Subject: [PATCH 5/7] On removing the template part from the command bar, go back to patterns --- .../edit-site/src/hooks/commands/use-edit-mode-commands.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/edit-site/src/hooks/commands/use-edit-mode-commands.js b/packages/edit-site/src/hooks/commands/use-edit-mode-commands.js index a6ab867d043ec..0550a0d597891 100644 --- a/packages/edit-site/src/hooks/commands/use-edit-mode-commands.js +++ b/packages/edit-site/src/hooks/commands/use-edit-mode-commands.js @@ -154,9 +154,7 @@ function useManipulateDocumentCommands() { decodeEntities( template.title ) ); const path = - template.type === TEMPLATE_POST_TYPE - ? '/wp_template' - : '/wp_template_part/all'; + template.type === TEMPLATE_POST_TYPE ? '/wp_template' : '/patterns'; commands.push( { name: 'core/remove-template', label, From 0054ab40041cb7c4ba645ae782a65ed768738962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Thu, 11 Apr 2024 19:56:11 +0200 Subject: [PATCH 6/7] Fix backPath after removing template in the details view --- .../src/components/sidebar-navigation-screen-template/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-template/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-template/index.js index cc35404f5e0a2..8e6698d887efe 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-template/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-template/index.js @@ -114,7 +114,7 @@ export default function SidebarNavigationScreenTemplate() { postId={ postId } toggleProps={ { as: SidebarButton } } onRemove={ () => { - navigator.goTo( postType ); + navigator.goTo( '/' + postType ); } } /> Date: Thu, 11 Apr 2024 20:05:51 +0200 Subject: [PATCH 7/7] Revert "Details page for parts: always go back to patterns" This reverts commit c66a62efa99013d1ddf92fd5ea3bf039b43f59f4. --- .../sidebar-navigation-screen-pattern/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pattern/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-pattern/index.js index 7669e0575427f..693d16914869a 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-pattern/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-pattern/index.js @@ -5,6 +5,7 @@ import { __experimentalUseNavigator as useNavigator } from '@wordpress/component import { useDispatch } from '@wordpress/data'; import { __ } from '@wordpress/i18n'; import { pencil } from '@wordpress/icons'; +import { getQueryArgs } from '@wordpress/url'; /** * Internal dependencies @@ -16,18 +17,27 @@ import usePatternDetails from './use-pattern-details'; import { store as editSiteStore } from '../../store'; import { unlock } from '../../lock-unlock'; import TemplateActions from '../template-actions'; +import { TEMPLATE_PART_POST_TYPE } from '../../utils/constants'; export default function SidebarNavigationScreenPattern() { const navigator = useNavigator(); const { params: { postType, postId }, } = navigator; + const { categoryType } = getQueryArgs( window.location.href ); const { setCanvasMode } = unlock( useDispatch( editSiteStore ) ); useInitEditedEntityFromURL(); const patternDetails = usePatternDetails( postType, postId ); - const backPath = '/patterns'; + + // The absence of a category type in the query params for template parts + // indicates the user has arrived at the template part via the "manage all" + // page and the back button should return them to that list page. + const backPath = + ! categoryType && postType === TEMPLATE_PART_POST_TYPE + ? '/wp_template_part/all' + : '/patterns'; return (