diff --git a/packages/block-library/src/navigation/edit/index.js b/packages/block-library/src/navigation/edit/index.js index 2249089f09952..1a79084e0b441 100644 --- a/packages/block-library/src/navigation/edit/index.js +++ b/packages/block-library/src/navigation/edit/index.js @@ -34,6 +34,7 @@ import { __experimentalToggleGroupControlOption as ToggleGroupControlOption, ToolbarGroup, ToolbarDropdownMenu, + Button, } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; @@ -280,6 +281,17 @@ function Navigation( { setIsPlaceholderShown( ! isEntityAvailable ); }, [ isEntityAvailable ] ); + function createNewMenu() { + replaceInnerBlocks( clientId, [] ); + if ( navigationArea ) { + setAreaMenu( 0 ); + } + setAttributes( { + navigationMenuId: undefined, + } ); + setIsPlaceholderShown( true ); + } + // If the block has inner blocks, but no menu id, this was an older // navigation block added before the block used a wp_navigation entity. // Either this block was saved in the content or inserted by a pattern. @@ -305,6 +317,23 @@ function Navigation( { ); } + // Show a warning if the selected menu is no longer available. + // TODO - the user should be able to select a new one? + if ( navigationMenuId && isNavigationMenuMissing ) { + return ( +
+ + { __( + 'Navigation menu has been deleted or is unavailable. ' + ) } + + +
+ ); + } + if ( isEntityAvailable && hasAlreadyRendered ) { return (
@@ -340,16 +369,7 @@ function Navigation( { setNavigationMenuId( id ); onClose(); } } - onCreateNew={ () => { - replaceInnerBlocks( clientId, [] ); - if ( navigationArea ) { - setAreaMenu( 0 ); - } - setAttributes( { - navigationMenuId: undefined, - } ); - setIsPlaceholderShown( true ); - } } + onCreateNew={ createNewMenu } /> ) }