From bf2ec562e4fbf2548568b331bacf2404af9766b8 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Mon, 15 May 2023 17:59:00 +1000 Subject: [PATCH 01/15] Try adding dynamic page templates to pages section --- .../sidebar-navigation-screen-pages/index.js | 89 +++++++++++++++---- 1 file changed, 74 insertions(+), 15 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js index ebb38d9478fc4..a355499ffe9e6 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js @@ -7,8 +7,10 @@ import { __experimentalTruncate as Truncate, } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; -import { useEntityRecords } from '@wordpress/core-data'; +import { useEntityRecords, store as coreStore } from '@wordpress/core-data'; import { decodeEntities } from '@wordpress/html-entities'; +import { layout, page } from '@wordpress/icons'; +import { useSelect } from '@wordpress/data'; /** * Internal dependencies @@ -18,52 +20,109 @@ import { useLink } from '../routes/link'; import SidebarNavigationItem from '../sidebar-navigation-item'; import SidebarNavigationSubtitle from '../sidebar-navigation-subtitle'; -const PageItem = ( { postId, ...props } ) => { +const PageItem = ( { postType = 'page', postId, ...props } ) => { const linkInfo = useLink( { - postType: 'page', + postType, postId, } ); return ; }; export default function SidebarNavigationScreenPages() { - const { records: pages, isResolving: isLoading } = useEntityRecords( + const { records: pages, isResolving: isLoadingPages } = useEntityRecords( 'postType', 'page', { status: 'any' } ); + const { records: templates, isResolving: isLoadingTemplates } = + useEntityRecords( 'postType', 'wp_template', { + per_page: -1, + } ); + + const dynamicPageTemplates = + templates && + templates.filter( ( template ) => { + return template.slug === '404' || template.slug === 'search'; + } ); + + const homeTemplate = + templates?.find( ( template ) => template.slug === 'front-page' ) || + templates?.find( ( template ) => template.slug === 'home' ) || + templates?.find( ( template ) => template.slug === 'index' ); + + const pagesAndTemplates = pages?.concat( dynamicPageTemplates, [ + homeTemplate, + ] ); + + const { frontPage, postsPage } = useSelect( ( select ) => { + const { getEntityRecord } = select( coreStore ); + + const siteSettings = getEntityRecord( 'root', 'site' ); + return { + frontPage: siteSettings?.page_on_front, + postsPage: siteSettings?.page_for_posts, + }; + }, [] ); + + const isHomePageBlog = frontPage === postsPage; + return ( - { isLoading && ( + { ( isLoadingPages || isLoadingTemplates ) && ( { __( 'Loading pages' ) } ) } - { ! isLoading && ( + { ! ( isLoadingPages || isLoadingTemplates ) && ( <> { __( 'Recent' ) } - { ! pages?.length && ( + { ! pagesAndTemplates?.length && ( { __( 'No page found' ) } ) } - { pages?.map( ( page ) => ( + { isHomePageBlog && homeTemplate && ( + + { decodeEntities( + homeTemplate.title?.rendered + ) ?? __( '(no title)' ) } + + ) } + { pages?.map( ( item ) => ( + + { decodeEntities( + item.title?.rendered + ) ?? __( '(no title)' ) } + + ) ) } + { dynamicPageTemplates?.map( ( item ) => ( - - { decodeEntities( - page.title?.rendered - ) ?? __( 'Untitled' ) } - + { decodeEntities( + item.title?.rendered + ) ?? __( '(no title)' ) } ) ) } Date: Tue, 16 May 2023 09:58:14 +1000 Subject: [PATCH 02/15] remove recent heading in pages --- .../sidebar-navigation-screen-pages/index.js | 110 ++++++++---------- 1 file changed, 51 insertions(+), 59 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js index a355499ffe9e6..5259c3329bcd4 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js @@ -9,7 +9,7 @@ import { import { __ } from '@wordpress/i18n'; import { useEntityRecords, store as coreStore } from '@wordpress/core-data'; import { decodeEntities } from '@wordpress/html-entities'; -import { layout, page } from '@wordpress/icons'; +import { layout, page, home } from '@wordpress/icons'; import { useSelect } from '@wordpress/data'; /** @@ -18,7 +18,6 @@ import { useSelect } from '@wordpress/data'; import SidebarNavigationScreen from '../sidebar-navigation-screen'; import { useLink } from '../routes/link'; import SidebarNavigationItem from '../sidebar-navigation-item'; -import SidebarNavigationSubtitle from '../sidebar-navigation-subtitle'; const PageItem = ( { postType = 'page', postId, ...props } ) => { const linkInfo = useLink( { @@ -79,64 +78,57 @@ export default function SidebarNavigationScreenPages() { ) } { ! ( isLoadingPages || isLoadingTemplates ) && ( - <> - - { __( 'Recent' ) } - - - { ! pagesAndTemplates?.length && ( - { __( 'No page found' ) } - ) } - { isHomePageBlog && homeTemplate && ( - - { decodeEntities( - homeTemplate.title?.rendered - ) ?? __( '(no title)' ) } - - ) } - { pages?.map( ( item ) => ( - - { decodeEntities( - item.title?.rendered - ) ?? __( '(no title)' ) } - - ) ) } - { dynamicPageTemplates?.map( ( item ) => ( - - { decodeEntities( - item.title?.rendered - ) ?? __( '(no title)' ) } - - ) ) } - { - document.location = - 'edit.php?post_type=page'; - } } + + { ! pagesAndTemplates?.length && ( + { __( 'No page found' ) } + ) } + { isHomePageBlog && homeTemplate && ( + + { decodeEntities( + homeTemplate.title?.rendered + ) ?? __( '(no title)' ) } + + ) } + { pages?.map( ( item ) => ( + - { __( 'Manage all pages' ) } - - - + { decodeEntities( item.title?.rendered ) ?? + __( '(no title)' ) } + + ) ) } + { dynamicPageTemplates?.map( ( item ) => ( + + { decodeEntities( item.title?.rendered ) ?? + __( '(no title)' ) } + + ) ) } + { + document.location = + 'edit.php?post_type=page'; + } } + > + { __( 'Manage all pages' ) } + + ) } } From 02ebcbef7d3f4965bd0e7dbf8b119be53e21c545 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Tue, 16 May 2023 11:16:16 +1000 Subject: [PATCH 03/15] Static homepage case --- .../sidebar-navigation-screen-pages/index.js | 52 ++++++++++++++----- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js index 5259c3329bcd4..7c63fca6c2ff3 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js @@ -9,7 +9,7 @@ import { import { __ } from '@wordpress/i18n'; import { useEntityRecords, store as coreStore } from '@wordpress/core-data'; import { decodeEntities } from '@wordpress/html-entities'; -import { layout, page, home } from '@wordpress/icons'; +import { layout, page, home, loop } from '@wordpress/icons'; import { useSelect } from '@wordpress/data'; /** @@ -66,6 +66,14 @@ export default function SidebarNavigationScreenPages() { const isHomePageBlog = frontPage === postsPage; + if ( ! isHomePageBlog ) { + const homePageIndex = pagesAndTemplates?.findIndex( + ( item ) => item.id === frontPage + ); + const homePage = pages?.splice( homePageIndex, 1 ); + pages?.splice( 0, 0, ...homePage ); + } + return ( ) } - { pages?.map( ( item ) => ( - - { decodeEntities( item.title?.rendered ) ?? - __( '(no title)' ) } - - ) ) } + { pages?.map( ( item ) => { + const pageIsFrontPage = item.id === frontPage; + const pageIsPostsPage = item.id === postsPage; + let itemIcon; + switch ( item.id ) { + case frontPage: + itemIcon = home; + break; + case postsPage: + itemIcon = loop; + break; + default: + itemIcon = page; + } + return ( + + { decodeEntities( + item.title?.rendered + ) ?? __( '(no title)' ) } + { pageIsFrontPage && + __( ' (Front Page)' ) } + { pageIsPostsPage && + __( ' (Posts Page)' ) } + + ); + } ) } { dynamicPageTemplates?.map( ( item ) => ( Date: Tue, 16 May 2023 14:49:09 +1000 Subject: [PATCH 04/15] Back button should go back to Pages --- packages/components/src/navigator/context.ts | 1 + .../src/navigator/navigator-provider/component.tsx | 11 +++++++++-- packages/components/src/navigator/types.ts | 8 ++++++++ packages/components/src/navigator/use-navigator.ts | 4 ++-- .../sidebar-navigation-screen-pages/index.js | 1 + .../sidebar-navigation-screen-template/index.js | 3 ++- .../src/components/sidebar-navigation-screen/index.js | 8 ++++++-- packages/edit-site/src/components/sidebar/index.js | 3 ++- 8 files changed, 31 insertions(+), 8 deletions(-) diff --git a/packages/components/src/navigator/context.ts b/packages/components/src/navigator/context.ts index e195621b03d20..a8ff9d392ff05 100644 --- a/packages/components/src/navigator/context.ts +++ b/packages/components/src/navigator/context.ts @@ -16,5 +16,6 @@ const initialContextValue: NavigatorContextType = { addScreen: () => {}, removeScreen: () => {}, params: {}, + backToPreviousScreen: false, }; export const NavigatorContext = createContext( initialContextValue ); diff --git a/packages/components/src/navigator/navigator-provider/component.tsx b/packages/components/src/navigator/navigator-provider/component.tsx index 4c98db5b1a4d1..224c963dd0d11 100644 --- a/packages/components/src/navigator/navigator-provider/component.tsx +++ b/packages/components/src/navigator/navigator-provider/component.tsx @@ -59,8 +59,13 @@ function UnconnectedNavigatorProvider( props: WordPressComponentProps< NavigatorProviderProps, 'div' >, forwardedRef: ForwardedRef< any > ) { - const { initialPath, children, className, ...otherProps } = - useContextSystem( props, 'NavigatorProvider' ); + const { + initialPath, + children, + className, + backToPreviousScreen, + ...otherProps + } = useContextSystem( props, 'NavigatorProvider' ); const [ locationHistory, setLocationHistory ] = useState< NavigatorLocation[] @@ -230,6 +235,7 @@ function UnconnectedNavigatorProvider( goToParent, addScreen, removeScreen, + backToPreviousScreen, } ), [ locationHistory, @@ -239,6 +245,7 @@ function UnconnectedNavigatorProvider( goToParent, addScreen, removeScreen, + backToPreviousScreen, ] ); diff --git a/packages/components/src/navigator/types.ts b/packages/components/src/navigator/types.ts index e638084e8376d..1dfa33af042a3 100644 --- a/packages/components/src/navigator/types.ts +++ b/packages/components/src/navigator/types.ts @@ -29,6 +29,7 @@ export type Navigator = { goTo: ( path: string, options?: NavigateOptions ) => void; goBack: () => void; goToParent: () => void; + backToPreviousScreen?: boolean; }; export type NavigatorContext = Navigator & { @@ -46,6 +47,13 @@ export type NavigatorProviderProps = { * The children elements. */ children: ReactNode; + /** + * Whether the navigator should restore focus to the previous screen when + * navigating back. + * + * @default false + */ + backToPreviousScreen?: boolean; }; export type NavigatorScreenProps = { diff --git a/packages/components/src/navigator/use-navigator.ts b/packages/components/src/navigator/use-navigator.ts index 4d917649374d5..9939bc520ffc0 100644 --- a/packages/components/src/navigator/use-navigator.ts +++ b/packages/components/src/navigator/use-navigator.ts @@ -13,15 +13,15 @@ import type { Navigator } from './types'; * Retrieves a `navigator` instance. */ function useNavigator(): Navigator { - const { location, params, goTo, goBack, goToParent } = + const { location, params, goTo, goBack, goToParent, backToPreviousScreen } = useContext( NavigatorContext ); - return { location, goTo, goBack, goToParent, params, + backToPreviousScreen, }; } diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js index 7c63fca6c2ff3..b22f02079a8a3 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js @@ -23,6 +23,7 @@ const PageItem = ( { postType = 'page', postId, ...props } ) => { const linkInfo = useLink( { postType, postId, + backToPreviousScreen: true, } ); 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 99139b55d87a5..4a88e6ef60024 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 @@ -87,7 +87,7 @@ function useTemplateTitleAndDescription( postType, postId ) { } export default function SidebarNavigationScreenTemplate() { - const { params } = useNavigator(); + const { params, backToPreviousScreen } = useNavigator(); const { postType, postId } = params; const { setCanvasMode } = unlock( useDispatch( editSiteStore ) ); const { title, description } = useTemplateTitleAndDescription( @@ -106,6 +106,7 @@ export default function SidebarNavigationScreenTemplate() { /> } description={ description } + backToPreviousScreen={ backToPreviousScreen } /> ); } diff --git a/packages/edit-site/src/components/sidebar-navigation-screen/index.js b/packages/edit-site/src/components/sidebar-navigation-screen/index.js index 0baac6278c430..bae77f3c1c88c 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen/index.js @@ -5,6 +5,7 @@ import { __experimentalHStack as HStack, __experimentalVStack as VStack, __experimentalNavigatorToParentButton as NavigatorToParentButton, + __experimentalNavigatorBackButton as NavigatorBackButton, __experimentalHeading as Heading, } from '@wordpress/components'; import { isRTL, __, sprintf } from '@wordpress/i18n'; @@ -31,6 +32,7 @@ export default function SidebarNavigationScreen( { content, footer, description, + backToPreviousScreen = false, } ) { const { dashboardLink } = useSelect( ( select ) => { const { getSettings } = unlock( select( editSiteStore ) ); @@ -40,7 +42,9 @@ export default function SidebarNavigationScreen( { }, [] ); const { getTheme } = useSelect( coreStore ); const theme = getTheme( currentlyPreviewingTheme() ); - + const NavigatorReturnButton = backToPreviousScreen + ? NavigatorBackButton + : NavigatorToParentButton; return ( { ! isRoot ? ( - From 1add381cf93239ce57f8e17dc24e5ca8f883b4c6 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Tue, 16 May 2023 16:31:57 +1000 Subject: [PATCH 05/15] Fix order of home and blog pages --- .../sidebar-navigation-screen-pages/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js index b22f02079a8a3..8774e3dca0ef3 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js @@ -68,11 +68,19 @@ export default function SidebarNavigationScreenPages() { const isHomePageBlog = frontPage === postsPage; if ( ! isHomePageBlog ) { - const homePageIndex = pagesAndTemplates?.findIndex( + const homePageIndex = pages?.findIndex( ( item ) => item.id === frontPage ); const homePage = pages?.splice( homePageIndex, 1 ); pages?.splice( 0, 0, ...homePage ); + + const postsPageIndex = pages?.findIndex( + ( item ) => item.id === postsPage + ); + + const blogPage = pages?.splice( postsPageIndex, 1 ); + + pages?.splice( 1, 0, ...blogPage ); } return ( From 75e287fe27759b1a2490c7f1b2fadb22c7916637 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Wed, 17 May 2023 15:15:08 +1000 Subject: [PATCH 06/15] Try fetching all the pages --- .../src/components/sidebar-navigation-screen-pages/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js index 8774e3dca0ef3..6e75d7967f931 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js @@ -32,9 +32,11 @@ export default function SidebarNavigationScreenPages() { const { records: pages, isResolving: isLoadingPages } = useEntityRecords( 'postType', 'page', - { status: 'any' } + { + status: 'any', + per_page: -1, + } ); - const { records: templates, isResolving: isLoadingTemplates } = useEntityRecords( 'postType', 'wp_template', { per_page: -1, From e8c6695c9cbd3e53f05d3667b0158847fac01587 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Wed, 17 May 2023 15:38:10 +1000 Subject: [PATCH 07/15] Stick templates to bottom --- .../sidebar-navigation-screen-pages/index.js | 28 +++++++++++-------- .../style.scss | 6 ++++ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js index 6e75d7967f931..d1ca9beddd9cc 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js @@ -5,6 +5,7 @@ import { __experimentalItemGroup as ItemGroup, __experimentalItem as Item, __experimentalTruncate as Truncate, + __experimentalVStack as VStack, } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { useEntityRecords, store as coreStore } from '@wordpress/core-data'; @@ -145,18 +146,21 @@ export default function SidebarNavigationScreenPages() { ); } ) } - { dynamicPageTemplates?.map( ( item ) => ( - - { decodeEntities( item.title?.rendered ) ?? - __( '(no title)' ) } - - ) ) } + + { dynamicPageTemplates?.map( ( item ) => ( + + { decodeEntities( + item.title?.rendered + ) ?? __( '(no title)' ) } + + ) ) } + Date: Wed, 17 May 2023 11:39:37 +0100 Subject: [PATCH 08/15] Stick item positioning --- .../src/components/sidebar-navigation-screen-pages/style.scss | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pages/style.scss b/packages/edit-site/src/components/sidebar-navigation-screen-pages/style.scss index 504471fb92ea8..ec7796568408d 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-pages/style.scss +++ b/packages/edit-site/src/components/sidebar-navigation-screen-pages/style.scss @@ -7,4 +7,7 @@ bottom: 0; background-color: $gray-900; gap: 0; + padding: $grid-unit-20 0; + margin: $grid-unit-20 0 #{- $grid-unit-20} 0; + border-top: 1px solid $gray-800; } From a107162929cacdd984617b7fd7b0ae3a5949c830 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Wed, 24 May 2023 14:54:47 +1000 Subject: [PATCH 09/15] Revert custom back button behaviour --- packages/components/src/navigator/context.ts | 1 - .../src/navigator/navigator-provider/component.tsx | 11 ++--------- packages/components/src/navigator/types.ts | 8 -------- packages/components/src/navigator/use-navigator.ts | 4 ++-- .../sidebar-navigation-screen-pages/index.js | 1 - .../sidebar-navigation-screen-template/index.js | 3 +-- .../src/components/sidebar-navigation-screen/index.js | 8 ++------ packages/edit-site/src/components/sidebar/index.js | 3 +-- 8 files changed, 8 insertions(+), 31 deletions(-) diff --git a/packages/components/src/navigator/context.ts b/packages/components/src/navigator/context.ts index a8ff9d392ff05..e195621b03d20 100644 --- a/packages/components/src/navigator/context.ts +++ b/packages/components/src/navigator/context.ts @@ -16,6 +16,5 @@ const initialContextValue: NavigatorContextType = { addScreen: () => {}, removeScreen: () => {}, params: {}, - backToPreviousScreen: false, }; export const NavigatorContext = createContext( initialContextValue ); diff --git a/packages/components/src/navigator/navigator-provider/component.tsx b/packages/components/src/navigator/navigator-provider/component.tsx index 224c963dd0d11..4c98db5b1a4d1 100644 --- a/packages/components/src/navigator/navigator-provider/component.tsx +++ b/packages/components/src/navigator/navigator-provider/component.tsx @@ -59,13 +59,8 @@ function UnconnectedNavigatorProvider( props: WordPressComponentProps< NavigatorProviderProps, 'div' >, forwardedRef: ForwardedRef< any > ) { - const { - initialPath, - children, - className, - backToPreviousScreen, - ...otherProps - } = useContextSystem( props, 'NavigatorProvider' ); + const { initialPath, children, className, ...otherProps } = + useContextSystem( props, 'NavigatorProvider' ); const [ locationHistory, setLocationHistory ] = useState< NavigatorLocation[] @@ -235,7 +230,6 @@ function UnconnectedNavigatorProvider( goToParent, addScreen, removeScreen, - backToPreviousScreen, } ), [ locationHistory, @@ -245,7 +239,6 @@ function UnconnectedNavigatorProvider( goToParent, addScreen, removeScreen, - backToPreviousScreen, ] ); diff --git a/packages/components/src/navigator/types.ts b/packages/components/src/navigator/types.ts index 1dfa33af042a3..e638084e8376d 100644 --- a/packages/components/src/navigator/types.ts +++ b/packages/components/src/navigator/types.ts @@ -29,7 +29,6 @@ export type Navigator = { goTo: ( path: string, options?: NavigateOptions ) => void; goBack: () => void; goToParent: () => void; - backToPreviousScreen?: boolean; }; export type NavigatorContext = Navigator & { @@ -47,13 +46,6 @@ export type NavigatorProviderProps = { * The children elements. */ children: ReactNode; - /** - * Whether the navigator should restore focus to the previous screen when - * navigating back. - * - * @default false - */ - backToPreviousScreen?: boolean; }; export type NavigatorScreenProps = { diff --git a/packages/components/src/navigator/use-navigator.ts b/packages/components/src/navigator/use-navigator.ts index 9939bc520ffc0..4d917649374d5 100644 --- a/packages/components/src/navigator/use-navigator.ts +++ b/packages/components/src/navigator/use-navigator.ts @@ -13,15 +13,15 @@ import type { Navigator } from './types'; * Retrieves a `navigator` instance. */ function useNavigator(): Navigator { - const { location, params, goTo, goBack, goToParent, backToPreviousScreen } = + const { location, params, goTo, goBack, goToParent } = useContext( NavigatorContext ); + return { location, goTo, goBack, goToParent, params, - backToPreviousScreen, }; } diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js index d1ca9beddd9cc..b12ce9a8341f3 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js @@ -24,7 +24,6 @@ const PageItem = ( { postType = 'page', postId, ...props } ) => { const linkInfo = useLink( { postType, postId, - backToPreviousScreen: true, } ); 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 4a88e6ef60024..99139b55d87a5 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 @@ -87,7 +87,7 @@ function useTemplateTitleAndDescription( postType, postId ) { } export default function SidebarNavigationScreenTemplate() { - const { params, backToPreviousScreen } = useNavigator(); + const { params } = useNavigator(); const { postType, postId } = params; const { setCanvasMode } = unlock( useDispatch( editSiteStore ) ); const { title, description } = useTemplateTitleAndDescription( @@ -106,7 +106,6 @@ export default function SidebarNavigationScreenTemplate() { /> } description={ description } - backToPreviousScreen={ backToPreviousScreen } /> ); } diff --git a/packages/edit-site/src/components/sidebar-navigation-screen/index.js b/packages/edit-site/src/components/sidebar-navigation-screen/index.js index bae77f3c1c88c..0baac6278c430 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen/index.js @@ -5,7 +5,6 @@ import { __experimentalHStack as HStack, __experimentalVStack as VStack, __experimentalNavigatorToParentButton as NavigatorToParentButton, - __experimentalNavigatorBackButton as NavigatorBackButton, __experimentalHeading as Heading, } from '@wordpress/components'; import { isRTL, __, sprintf } from '@wordpress/i18n'; @@ -32,7 +31,6 @@ export default function SidebarNavigationScreen( { content, footer, description, - backToPreviousScreen = false, } ) { const { dashboardLink } = useSelect( ( select ) => { const { getSettings } = unlock( select( editSiteStore ) ); @@ -42,9 +40,7 @@ export default function SidebarNavigationScreen( { }, [] ); const { getTheme } = useSelect( coreStore ); const theme = getTheme( currentlyPreviewingTheme() ); - const NavigatorReturnButton = backToPreviousScreen - ? NavigatorBackButton - : NavigatorToParentButton; + return ( { ! isRoot ? ( - From 92ee8abef109a73efaf7372435f5f59f1ed70cf2 Mon Sep 17 00:00:00 2001 From: James Koster Date: Wed, 24 May 2023 10:39:26 +0100 Subject: [PATCH 10/15] Move manage link to dynamic pages group --- .../sidebar-navigation-screen-pages/index.js | 20 +++++++++---------- .../style.scss | 4 ---- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js index b12ce9a8341f3..c5736a052367d 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js @@ -159,17 +159,17 @@ export default function SidebarNavigationScreenPages() { ) ?? __( '(no title)' ) } ) ) } + { + document.location = + 'edit.php?post_type=page'; + } } + > + { __( 'Manage all pages' ) } + - { - document.location = - 'edit.php?post_type=page'; - } } - > - { __( 'Manage all pages' ) } - ) } diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pages/style.scss b/packages/edit-site/src/components/sidebar-navigation-screen-pages/style.scss index ec7796568408d..b8963e5916937 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-pages/style.scss +++ b/packages/edit-site/src/components/sidebar-navigation-screen-pages/style.scss @@ -1,7 +1,3 @@ -.edit-site-sidebar-navigation-screen-pages__see-all { - /* Overrides the margin that comes from the Item component */ - margin-top: $grid-unit-20 !important; -} .edit-site-sidebar-navigation-screen__sticky-section.edit-site-sidebar-navigation-screen__sticky-section { position: sticky; bottom: 0; From db069157b9048e57468efdd46efcb05c8eb51543 Mon Sep 17 00:00:00 2001 From: James Koster Date: Wed, 24 May 2023 10:40:35 +0100 Subject: [PATCH 11/15] Remove home/posts page suffixes --- .../src/components/sidebar-navigation-screen-pages/index.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js index c5736a052367d..b7d122234147a 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js @@ -115,8 +115,6 @@ export default function SidebarNavigationScreenPages() { ) } { pages?.map( ( item ) => { - const pageIsFrontPage = item.id === frontPage; - const pageIsPostsPage = item.id === postsPage; let itemIcon; switch ( item.id ) { case frontPage: @@ -138,10 +136,6 @@ export default function SidebarNavigationScreenPages() { { decodeEntities( item.title?.rendered ) ?? __( '(no title)' ) } - { pageIsFrontPage && - __( ' (Front Page)' ) } - { pageIsPostsPage && - __( ' (Posts Page)' ) } ); } ) } From bb94a2235741a73ffabc48990da0bb08ef13d95c Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Fri, 26 May 2023 13:23:23 +1000 Subject: [PATCH 12/15] Address feedback --- .../sidebar-navigation-screen-pages/index.js | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js index b7d122234147a..20f07f498a711 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js @@ -42,11 +42,9 @@ export default function SidebarNavigationScreenPages() { per_page: -1, } ); - const dynamicPageTemplates = - templates && - templates.filter( ( template ) => { - return template.slug === '404' || template.slug === 'search'; - } ); + const dynamicPageTemplates = templates?.filter( ( { slug } ) => + [ '404', 'search' ].includes( slug ) + ); const homeTemplate = templates?.find( ( template ) => template.slug === 'front-page' ) || @@ -69,20 +67,20 @@ export default function SidebarNavigationScreenPages() { const isHomePageBlog = frontPage === postsPage; - if ( ! isHomePageBlog ) { - const homePageIndex = pages?.findIndex( + if ( ! isHomePageBlog && pages?.length ) { + const homePageIndex = pages.findIndex( ( item ) => item.id === frontPage ); - const homePage = pages?.splice( homePageIndex, 1 ); + const homePage = pages.splice( homePageIndex, 1 ); pages?.splice( 0, 0, ...homePage ); - const postsPageIndex = pages?.findIndex( + const postsPageIndex = pages.findIndex( ( item ) => item.id === postsPage ); - const blogPage = pages?.splice( postsPageIndex, 1 ); + const blogPage = pages.splice( postsPageIndex, 1 ); - pages?.splice( 1, 0, ...blogPage ); + pages.splice( 1, 0, ...blogPage ); } return ( From 2ba722b0f76b8c890af98727159ee1374c16633a Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Mon, 29 May 2023 11:05:59 +1000 Subject: [PATCH 13/15] Add back truncation --- .../sidebar-navigation-screen-pages/index.js | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js index 20f07f498a711..617180d69cbed 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js @@ -107,9 +107,11 @@ export default function SidebarNavigationScreenPages() { icon={ home } withChevron > - { decodeEntities( - homeTemplate.title?.rendered - ) ?? __( '(no title)' ) } + + { decodeEntities( + homeTemplate.title?.rendered + ) ?? __( '(no title)' ) } + ) } { pages?.map( ( item ) => { @@ -131,9 +133,11 @@ export default function SidebarNavigationScreenPages() { icon={ itemIcon } withChevron > - { decodeEntities( - item.title?.rendered - ) ?? __( '(no title)' ) } + + { decodeEntities( + item.title?.rendered + ) ?? __( '(no title)' ) } + ); } ) } @@ -146,9 +150,11 @@ export default function SidebarNavigationScreenPages() { icon={ layout } withChevron > - { decodeEntities( - item.title?.rendered - ) ?? __( '(no title)' ) } + + { decodeEntities( + item.title?.rendered + ) ?? __( '(no title)' ) } + ) ) } Date: Mon, 29 May 2023 11:41:09 +1000 Subject: [PATCH 14/15] Copy array for reorder --- .../sidebar-navigation-screen-pages/index.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js index 617180d69cbed..6a3e02c64825f 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js @@ -67,20 +67,22 @@ export default function SidebarNavigationScreenPages() { const isHomePageBlog = frontPage === postsPage; - if ( ! isHomePageBlog && pages?.length ) { - const homePageIndex = pages.findIndex( + const reorderedPages = pages && [ ...pages ]; + + if ( ! isHomePageBlog && reorderedPages?.length ) { + const homePageIndex = reorderedPages.findIndex( ( item ) => item.id === frontPage ); - const homePage = pages.splice( homePageIndex, 1 ); - pages?.splice( 0, 0, ...homePage ); + const homePage = reorderedPages.splice( homePageIndex, 1 ); + reorderedPages?.splice( 0, 0, ...homePage ); - const postsPageIndex = pages.findIndex( + const postsPageIndex = reorderedPages.findIndex( ( item ) => item.id === postsPage ); - const blogPage = pages.splice( postsPageIndex, 1 ); + const blogPage = reorderedPages.splice( postsPageIndex, 1 ); - pages.splice( 1, 0, ...blogPage ); + reorderedPages.splice( 1, 0, ...blogPage ); } return ( @@ -114,7 +116,7 @@ export default function SidebarNavigationScreenPages() { ) } - { pages?.map( ( item ) => { + { reorderedPages?.map( ( item ) => { let itemIcon; switch ( item.id ) { case frontPage: From 9c218f6961e0842f84026659cfd1f35ecf099ce6 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Mon, 29 May 2023 12:00:43 +1000 Subject: [PATCH 15/15] Consolidate sticky styles --- .../components/sidebar-navigation-screen-page/style.scss | 5 ----- .../sidebar-navigation-screen-pages/style.scss | 9 --------- .../src/components/sidebar-navigation-screen/style.scss | 6 +++--- packages/edit-site/src/style.scss | 1 - 4 files changed, 3 insertions(+), 18 deletions(-) delete mode 100644 packages/edit-site/src/components/sidebar-navigation-screen-pages/style.scss diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-page/style.scss b/packages/edit-site/src/components/sidebar-navigation-screen-page/style.scss index 94dd7aa67096b..7f7e6d79b5029 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-page/style.scss +++ b/packages/edit-site/src/components/sidebar-navigation-screen-page/style.scss @@ -1,8 +1,3 @@ -.edit-site-sidebar-navigation-screen__sticky-section { - padding: $grid-unit-40 0; - margin: $grid-unit-40 $grid-unit-20; -} - .edit-site-sidebar-navigation-screen-page__featured-image-wrapper { background-color: $gray-800; margin-bottom: $grid-unit-20; diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pages/style.scss b/packages/edit-site/src/components/sidebar-navigation-screen-pages/style.scss deleted file mode 100644 index b8963e5916937..0000000000000 --- a/packages/edit-site/src/components/sidebar-navigation-screen-pages/style.scss +++ /dev/null @@ -1,9 +0,0 @@ -.edit-site-sidebar-navigation-screen__sticky-section.edit-site-sidebar-navigation-screen__sticky-section { - position: sticky; - bottom: 0; - background-color: $gray-900; - gap: 0; - padding: $grid-unit-20 0; - margin: $grid-unit-20 0 #{- $grid-unit-20} 0; - border-top: 1px solid $gray-800; -} diff --git a/packages/edit-site/src/components/sidebar-navigation-screen/style.scss b/packages/edit-site/src/components/sidebar-navigation-screen/style.scss index f4b284ec92b58..81508a7709d94 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen/style.scss +++ b/packages/edit-site/src/components/sidebar-navigation-screen/style.scss @@ -73,12 +73,12 @@ } } -.edit-site-sidebar-navigation-screen__sticky-section { +.edit-site-sidebar-navigation-screen__sticky-section.edit-site-sidebar-navigation-screen__sticky-section { position: sticky; bottom: 0; background-color: $gray-900; gap: 0; - padding: $grid-unit-20 0; - margin: $grid-unit-20 0 #{- $grid-unit-20} 0; + padding: $grid-unit-40 0; + margin: $grid-unit-40 $grid-unit-20; border-top: 1px solid $gray-800; } diff --git a/packages/edit-site/src/style.scss b/packages/edit-site/src/style.scss index 8eff0fe22e038..3aebc258cd510 100644 --- a/packages/edit-site/src/style.scss +++ b/packages/edit-site/src/style.scss @@ -25,7 +25,6 @@ @import "./components/sidebar-button/style.scss"; @import "./components/sidebar-navigation-item/style.scss"; @import "./components/sidebar-navigation-screen/style.scss"; -@import "./components/sidebar-navigation-screen-pages/style.scss"; @import "./components/sidebar-navigation-screen-page/style.scss"; @import "./components/sidebar-navigation-screen-template/style.scss"; @import "./components/sidebar-navigation-screen-templates/style.scss";