From 3dee12c795d4540d0b428d8742d645ad14b6caae Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 16 Jun 2023 09:53:01 +0100 Subject: [PATCH] Remove custom button and show single menu on Navigation route --- .../sidebar-navigation-screen-main/index.js | 9 ++-- .../index.js | 41 +++------------- .../single-navigation-menu.js | 39 +++++++++++++++ .../index.js | 12 +++++ .../navigator-button.js | 47 ------------------- 5 files changed, 62 insertions(+), 86 deletions(-) create mode 100644 packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js delete mode 100644 packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/navigator-button.js diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-main/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-main/index.js index 9df2e22b111d3..5c89c9f72a23b 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-main/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-main/index.js @@ -20,7 +20,6 @@ import SidebarNavigationItem from '../sidebar-navigation-item'; import { SidebarNavigationItemGlobalStyles } from '../sidebar-navigation-screen-global-styles'; import { unlock } from '../../lock-unlock'; import { store as editSiteStore } from '../../store'; -import SidebarNavigationScreenNavigationMenuButton from '../sidebar-navigation-screen-navigation-menus/navigator-button'; export default function SidebarNavigationScreenMain() { const { location } = useNavigator(); @@ -44,14 +43,14 @@ export default function SidebarNavigationScreenMain() { ) } content={ - { __( 'Navigation' ) } - - + - - - - } - title={ decodeEntities( menuTitle ) } - description={ - <> -

- { sprintf( - /* translators: %s: Navigation menu title */ - 'This is your "%s" navigation menu. ', - decodeEntities( menuTitle ) - ) } -

-

- { __( - 'You can edit this menu here, but be aware that visual styles might be applied separately in templates or template parts, so the preview shown here can be incomplete.' - ) } -

- - } - > - - + ); } diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js new file mode 100644 index 0000000000000..6351c83323f98 --- /dev/null +++ b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js @@ -0,0 +1,39 @@ +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; +import { decodeEntities } from '@wordpress/html-entities'; +/** + * Internal dependencies + */ +import { SidebarNavigationScreenWrapper } from '../sidebar-navigation-screen-navigation-menus'; +import ScreenNavigationMoreMenu from './more-menu'; +import NavigationMenuEditor from './navigation-menu-editor'; + +export default function SingleNavigationMenu( { + navigationMenu, + handleDelete, + handleDuplicate, + handleSave, +} ) { + const menuTitle = navigationMenu?.title?.rendered; + + return ( + + } + title={ decodeEntities( menuTitle ) } + description={ __( + 'Navigation menus are a curated collection of blocks that allow visitors to get around your site.' + ) } + > + + + ); +} 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 5706ff17bc038..8d3edad0de8d2 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 @@ -18,6 +18,7 @@ import SidebarNavigationScreen from '../sidebar-navigation-screen'; import SidebarNavigationItem from '../sidebar-navigation-item'; import { PRELOADED_NAVIGATION_MENUS_QUERY } from './constants'; import { useLink } from '../routes/link'; +import NavigationMenuEditor from '../sidebar-navigation-screen-navigation-menu/navigation-menu-editor'; export default function SidebarNavigationScreenNavigationMenus() { const { records: navigationMenus, isResolving: isLoading } = @@ -45,6 +46,17 @@ export default function SidebarNavigationScreenNavigationMenus() { ); } + // if single menu then render it + if ( navigationMenus?.length === 1 ) { + return ( + + + + ); + } + return ( diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/navigator-button.js b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/navigator-button.js deleted file mode 100644 index 7e75c544a0f16..0000000000000 --- a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/navigator-button.js +++ /dev/null @@ -1,47 +0,0 @@ -/** - * WordPress dependencies - */ - -import { __experimentalNavigatorButton as NavigatorButton } from '@wordpress/components'; -import { useEntityRecords } from '@wordpress/core-data'; - -/** - * Internal dependencies - */ -import { PRELOADED_NAVIGATION_MENUS_QUERY } from './constants'; - -export default function SidebarNavigationScreenNavigationMenuButton( { - children, - ...props -} ) { - const { records: navigationMenus, isResolving: isLoading } = - useEntityRecords( - 'postType', - `wp_navigation`, - PRELOADED_NAVIGATION_MENUS_QUERY - ); - - const hasNavigationMenus = !! navigationMenus?.length; - const hasSingleNavigationMenu = navigationMenus?.length === 1; - const firstNavigationMenu = navigationMenus?.[ 0 ]; - - const showNavigationScreen = process.env.IS_GUTENBERG_PLUGIN - ? hasNavigationMenus - : false; - - // If there is a single menu then we can go directly to that menu. - // Otherwise we go to the navigation listing screen. - const path = hasSingleNavigationMenu - ? `/navigation/wp_navigation/${ firstNavigationMenu?.id }` - : '/navigation'; - - if ( ! showNavigationScreen ) { - return null; - } - - return ( - - { children } - - ); -}