From 75b233b041b45a6b7464484f917f6544daeda3ef Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Wed, 1 May 2024 13:18:15 +0200 Subject: [PATCH 1/4] Site Editor sidebar: provide explicit backPaths, remove the getBackPath helper --- .../edit-site/src/components/layout/router.js | 1 + .../index.js | 1 + .../index.js | 6 ++++ .../single-navigation-menu.js | 2 ++ .../index.js | 10 ++++-- .../sidebar-navigation-screen-page/index.js | 4 +-- .../index.js | 1 + .../index.js | 1 + .../index.js | 1 + .../sidebar-navigation-screen/index.js | 32 ++----------------- 10 files changed, 25 insertions(+), 34 deletions(-) diff --git a/packages/edit-site/src/components/layout/router.js b/packages/edit-site/src/components/layout/router.js index fc19ca9242eace..5d3ae034f9f728 100644 --- a/packages/edit-site/src/components/layout/router.js +++ b/packages/edit-site/src/components/layout/router.js @@ -45,6 +45,7 @@ export default function useLayoutAreas() { sidebar: ( } /> ), diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js index f0585b410e40dc..b7215d5ecfeee3 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js @@ -179,6 +179,7 @@ export default function SidebarNavigationScreenGlobalStyles() { description={ __( 'Choose a different style combination for the theme styles.' ) } + backPath={ {} } content={ } footer={ shouldShowGlobalStylesFooter && ( diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js index 2fcac0250c2bf5..a94300fbc0084c 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js @@ -61,12 +61,15 @@ export default function SidebarNavigationScreenNavigationMenu() { const _handleSave = ( edits ) => handleSave( navigationMenu, edits ); const _handleDuplicate = () => handleDuplicate( navigationMenu ); + const backPath = { path: '/navigation', postId }; + if ( isLoading ) { return ( @@ -77,6 +80,7 @@ export default function SidebarNavigationScreenNavigationMenu() { return ( ); } @@ -93,6 +97,7 @@ export default function SidebarNavigationScreenNavigationMenu() { onDuplicate={ _handleDuplicate } /> } + backPath={ backPath } title={ buildNavigationLabel( navigationMenu?.title, navigationMenu?.id, @@ -106,6 +111,7 @@ export default function SidebarNavigationScreenNavigationMenu() { return ( } + backPath={ backPath } title={ buildNavigationLabel( navigationMenu?.title, navigationMenu?.id, diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/index.js index 65f80349ddaca2..53b5a6adc22189 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/index.js @@ -85,9 +85,11 @@ export default function SidebarNavigationScreenNavigationMenus() { const hasNavigationMenus = !! navigationMenus?.length; + const backPath = {}; + if ( isLoading ) { return ( - + ); @@ -97,6 +99,7 @@ export default function SidebarNavigationScreenNavigationMenus() { return ( ); } @@ -106,6 +109,7 @@ export default function SidebarNavigationScreenNavigationMenus() { return ( handleDelete( firstNavigationMenu ) } handleDuplicate={ () => handleDuplicate( firstNavigationMenu ) } handleSave={ ( edits ) => @@ -116,7 +120,7 @@ export default function SidebarNavigationScreenNavigationMenus() { } return ( - + { navigationMenus?.map( ( { id, title, status }, index ) => ( ); diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js index 51251dcf846e66..bfd5062145d738 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js @@ -32,7 +32,7 @@ import SidebarNavigationScreenDetailsFooter from '../sidebar-navigation-screen-d const { useLocation, useHistory } = unlock( routerPrivateApis ); const { PostActions } = unlock( editorPrivateApis ); -export default function SidebarNavigationScreenPage( { backPath } ) { +export default function SidebarNavigationScreenPage() { const { setCanvasMode } = unlock( useDispatch( editSiteStore ) ); const history = useHistory(); const { createSuccessNotice } = useDispatch( noticesStore ); @@ -140,7 +140,7 @@ export default function SidebarNavigationScreenPage( { backPath } ) { return record ? ( } content={ <> 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 ff12434b278952..ff5a8ca0ca749f 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 @@ -108,6 +108,7 @@ export default function SidebarNavigationScreenTemplate() { return ( { - const backPath = - backPathProp ?? - location.state?.backPath ?? - getBackPath( location.params ); history.push( backPath ); navigate( 'back' ); } } From 632ba2674a39b55626077d77066494bae2ea8e94 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Fri, 3 May 2024 09:58:27 +0200 Subject: [PATCH 2/4] Remove postId from backPaths that don't use it --- .../sidebar-navigation-screen-navigation-menu/index.js | 2 +- .../src/components/sidebar-navigation-screen-template/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js index a94300fbc0084c..5adb3d61ceb2ad 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js @@ -61,7 +61,7 @@ export default function SidebarNavigationScreenNavigationMenu() { const _handleSave = ( edits ) => handleSave( navigationMenu, edits ); const _handleDuplicate = () => handleDuplicate( navigationMenu ); - const backPath = { path: '/navigation', postId }; + const backPath = { path: '/navigation' }; if ( isLoading ) { return ( 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 ff5a8ca0ca749f..56d1ceee1b017e 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 @@ -108,7 +108,7 @@ export default function SidebarNavigationScreenTemplate() { return ( Date: Fri, 3 May 2024 10:42:54 +0200 Subject: [PATCH 3/4] Centralize backPaths in the router --- .../edit-site/src/components/layout/router.js | 44 +++++++++++++++---- .../index.js | 4 +- .../index.js | 4 +- .../index.js | 4 +- .../sidebar-navigation-screen-page/index.js | 4 +- .../index.js | 10 +---- .../index.js | 4 +- .../index.js | 4 +- .../index.js | 4 +- 9 files changed, 49 insertions(+), 33 deletions(-) diff --git a/packages/edit-site/src/components/layout/router.js b/packages/edit-site/src/components/layout/router.js index 5d3ae034f9f728..08ce4d11cd947c 100644 --- a/packages/edit-site/src/components/layout/router.js +++ b/packages/edit-site/src/components/layout/router.js @@ -31,7 +31,7 @@ export default function useLayoutAreas() { const isSiteEditorLoading = useIsSiteEditorLoading(); const history = useHistory(); const { params } = useLocation(); - const { postType, postId, path, layout, isCustom, canvas } = params ?? {}; + const { postType, postId, path, layout, isCustom, canvas } = params; // Note: Since "sidebar" is not yet supported here, // returning undefined from "mobile" means show the sidebar. @@ -79,13 +79,33 @@ export default function useLayoutAreas() { if ( postType && postId ) { let sidebar; if ( postType === 'wp_template_part' || postType === 'wp_block' ) { - sidebar = ; + sidebar = ( + + ); } else if ( postType === 'wp_template' ) { - sidebar = ; + sidebar = ( + + ); } else if ( postType === 'page' ) { - sidebar = ; + sidebar = ( + + ); } else { - sidebar = ; + sidebar = ( + + ); } return { key: 'page', @@ -105,7 +125,9 @@ export default function useLayoutAreas() { return { key: 'templates-list', areas: { - sidebar: , + sidebar: ( + + ), content: , preview: isListLayout && ( @@ -126,7 +148,7 @@ export default function useLayoutAreas() { return { key: 'patterns', areas: { - sidebar: , + sidebar: , content: , mobile: , }, @@ -138,7 +160,9 @@ export default function useLayoutAreas() { return { key: 'styles', areas: { - sidebar: , + sidebar: ( + + ), preview: , mobile: canvas === 'edit' && ( @@ -164,7 +188,9 @@ export default function useLayoutAreas() { return { key: 'navigation', areas: { - sidebar: , + sidebar: ( + + ), preview: , mobile: canvas === 'edit' && ( diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js index b7215d5ecfeee3..87a7b6d9d15f27 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js @@ -103,7 +103,7 @@ function SidebarNavigationScreenGlobalStylesContent() { ); } -export default function SidebarNavigationScreenGlobalStyles() { +export default function SidebarNavigationScreenGlobalStyles( { backPath } ) { const { revisions, isLoading: isLoadingRevisions } = useGlobalStylesRevisions(); const { openGeneralSidebar } = useDispatch( editSiteStore ); @@ -179,7 +179,7 @@ export default function SidebarNavigationScreenGlobalStyles() { description={ __( 'Choose a different style combination for the theme styles.' ) } - backPath={ {} } + backPath={ backPath } content={ } footer={ shouldShowGlobalStylesFooter && ( diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js index 5adb3d61ceb2ad..24fb9372b4fff0 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js @@ -22,7 +22,7 @@ const { useLocation } = unlock( routerPrivateApis ); export const postType = `wp_navigation`; -export default function SidebarNavigationScreenNavigationMenu() { +export default function SidebarNavigationScreenNavigationMenu( { backPath } ) { const { params: { postId }, } = useLocation(); @@ -61,8 +61,6 @@ export default function SidebarNavigationScreenNavigationMenu() { const _handleSave = ( edits ) => handleSave( navigationMenu, edits ); const _handleDuplicate = () => handleDuplicate( navigationMenu ); - const backPath = { path: '/navigation' }; - if ( isLoading ) { return ( diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js index bfd5062145d738..51251dcf846e66 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js @@ -32,7 +32,7 @@ import SidebarNavigationScreenDetailsFooter from '../sidebar-navigation-screen-d const { useLocation, useHistory } = unlock( routerPrivateApis ); const { PostActions } = unlock( editorPrivateApis ); -export default function SidebarNavigationScreenPage() { +export default function SidebarNavigationScreenPage( { backPath } ) { const { setCanvasMode } = unlock( useDispatch( editSiteStore ) ); const history = useHistory(); const { createSuccessNotice } = useDispatch( noticesStore ); @@ -140,7 +140,7 @@ export default function SidebarNavigationScreenPage() { return record ? ( } content={ <> 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 56d1ceee1b017e..76641f969fca79 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 @@ -94,7 +94,7 @@ function useTemplateDetails( postType, postId ) { return { title, description, content, footer }; } -export default function SidebarNavigationScreenTemplate() { +export default function SidebarNavigationScreenTemplate( { backPath } ) { const history = useHistory(); const { params: { postType, postId }, @@ -108,7 +108,7 @@ export default function SidebarNavigationScreenTemplate() { return ( Date: Tue, 7 May 2024 15:21:30 +0200 Subject: [PATCH 4/4] Add missing navigation menu backpath --- packages/edit-site/src/components/layout/router.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/edit-site/src/components/layout/router.js b/packages/edit-site/src/components/layout/router.js index 08ce4d11cd947c..20d5b463852ff3 100644 --- a/packages/edit-site/src/components/layout/router.js +++ b/packages/edit-site/src/components/layout/router.js @@ -177,7 +177,11 @@ export default function useLayoutAreas() { return { key: 'navigation', areas: { - sidebar: , + sidebar: ( + + ), preview: , mobile: canvas === 'edit' && (