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 1c4bce62fc1ed7..e3b8b2a85d6727 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 @@ -7,11 +7,7 @@ import { Spinner, } from '@wordpress/components'; import { __, sprintf } from '@wordpress/i18n'; -import { useCallback, useMemo } from '@wordpress/element'; import { useSelect, useDispatch } from '@wordpress/data'; -import { privateApis as routerPrivateApis } from '@wordpress/router'; -import { BlockEditorProvider } from '@wordpress/block-editor'; -import { createBlock } from '@wordpress/blocks'; import { decodeEntities } from '@wordpress/html-entities'; import { store as noticesStore } from '@wordpress/notices'; @@ -19,18 +15,11 @@ import { store as noticesStore } from '@wordpress/notices'; /** * Internal dependencies */ -import { unlock } from '../../lock-unlock'; -import { store as editSiteStore } from '../../store'; -import { - isPreviewingTheme, - currentlyPreviewingTheme, -} from '../../utils/is-previewing-theme'; import { SidebarNavigationScreenWrapper } from '../sidebar-navigation-screen-navigation-menus'; -import NavigationMenuContent from '../sidebar-navigation-screen-navigation-menus/navigation-menu-content'; import ScreenNavigationMoreMenu from './more-menu'; +import NavigationMenuEditor from './navigation-menu-editor'; -const { useHistory } = unlock( routerPrivateApis ); -const noop = () => {}; +export const noop = () => {}; export default function SidebarNavigationScreenNavigationMenu() { const { @@ -244,75 +233,3 @@ export default function SidebarNavigationScreenNavigationMenu() { ); } - -function NavigationMenuEditor( { navigationMenu } ) { - const history = useHistory(); - - const onSelect = useCallback( - ( selectedBlock ) => { - const { attributes, name } = selectedBlock; - if ( - attributes.kind === 'post-type' && - attributes.id && - attributes.type && - history - ) { - history.push( { - postType: attributes.type, - postId: attributes.id, - ...( isPreviewingTheme() && { - gutenberg_theme_preview: currentlyPreviewingTheme(), - } ), - } ); - } - if ( name === 'core/page-list-item' && attributes.id && history ) { - history.push( { - postType: 'page', - postId: attributes.id, - ...( isPreviewingTheme() && { - gutenberg_theme_preview: currentlyPreviewingTheme(), - } ), - } ); - } - }, - [ history ] - ); - - const { storedSettings } = useSelect( ( select ) => { - const { getSettings } = unlock( select( editSiteStore ) ); - - return { - storedSettings: getSettings( false ), - }; - }, [] ); - - const blocks = useMemo( () => { - if ( ! NavigationMenuEditor ) { - return []; - } - - return [ - createBlock( 'core/navigation', { ref: navigationMenu?.id } ), - ]; - }, [ navigationMenu ] ); - - if ( ! navigationMenu || ! blocks?.length ) { - return null; - } - - return ( - -
- -
-
- ); -} diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/navigation-menu-editor.js b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/navigation-menu-editor.js new file mode 100644 index 00000000000000..5e9c294ddd5054 --- /dev/null +++ b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/navigation-menu-editor.js @@ -0,0 +1,94 @@ +/** + * WordPress dependencies + */ +import { useCallback, useMemo } from '@wordpress/element'; +import { useSelect } from '@wordpress/data'; +import { BlockEditorProvider } from '@wordpress/block-editor'; +import { createBlock } from '@wordpress/blocks'; +import { privateApis as routerPrivateApis } from '@wordpress/router'; + +/** + * Internal dependencies + */ +import { unlock } from '../../lock-unlock'; +import { store as editSiteStore } from '../../store'; +import { + isPreviewingTheme, + currentlyPreviewingTheme, +} from '../../utils/is-previewing-theme'; +import NavigationMenuContent from '../sidebar-navigation-screen-navigation-menus/navigation-menu-content'; +import { noop } from '.'; + +const { useHistory } = unlock( routerPrivateApis ); + +export default function NavigationMenuEditor( { navigationMenu } ) { + const history = useHistory(); + + const onSelect = useCallback( + ( selectedBlock ) => { + const { attributes, name } = selectedBlock; + if ( + attributes.kind === 'post-type' && + attributes.id && + attributes.type && + history + ) { + history.push( { + postType: attributes.type, + postId: attributes.id, + ...( isPreviewingTheme() && { + gutenberg_theme_preview: currentlyPreviewingTheme(), + } ), + } ); + } + if ( name === 'core/page-list-item' && attributes.id && history ) { + history.push( { + postType: 'page', + postId: attributes.id, + ...( isPreviewingTheme() && { + gutenberg_theme_preview: currentlyPreviewingTheme(), + } ), + } ); + } + }, + [ history ] + ); + + const { storedSettings } = useSelect( ( select ) => { + const { getSettings } = unlock( select( editSiteStore ) ); + + return { + storedSettings: getSettings( false ), + }; + }, [] ); + + const blocks = useMemo( () => { + if ( ! navigationMenu ) { + return []; + } + + return [ + createBlock( 'core/navigation', { ref: navigationMenu?.id } ), + ]; + }, [ navigationMenu ] ); + + if ( ! navigationMenu || ! blocks?.length ) { + return null; + } + + return ( + +
+ +
+
+ ); +}