Skip to content

Commit

Permalink
Fix non existent menu handling in nav block (#36507)
Browse files Browse the repository at this point in the history
* Fix missing menu detection

* Remove warning state, just fall back to placeholder
  • Loading branch information
talldan authored and noisysocks committed Nov 28, 2021
1 parent 4191997 commit e634361
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
14 changes: 0 additions & 14 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,20 +306,6 @@ 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 (
<div { ...blockProps }>
<Warning>
{ __(
'Navigation menu has been deleted or is unavailable'
) }
</Warning>
</div>
);
}

if ( isEntityAvailable && hasAlreadyRendered ) {
return (
<div { ...blockProps }>
Expand Down
6 changes: 5 additions & 1 deletion packages/block-library/src/navigation/use-navigation-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default function useNavigationMenu( navigationMenuId ) {
return useSelect(
( select ) => {
const {
getEntityRecord,
getEditedEntityRecord,
getEntityRecords,
hasFinishedResolution,
Expand All @@ -18,6 +19,9 @@ export default function useNavigationMenu( navigationMenuId ) {
'wp_navigation',
navigationMenuId,
];
const rawNavigationMenu = navigationMenuId
? getEntityRecord( ...navigationMenuSingleArgs )
: null;
const navigationMenu = navigationMenuId
? getEditedEntityRecord( ...navigationMenuSingleArgs )
: null;
Expand Down Expand Up @@ -45,7 +49,7 @@ export default function useNavigationMenu( navigationMenuId ) {
isNavigationMenuResolved: hasResolvedNavigationMenu,
isNavigationMenuMissing:
! navigationMenuId ||
( hasResolvedNavigationMenu && ! navigationMenu ),
( hasResolvedNavigationMenu && ! rawNavigationMenu ),
canSwitchNavigationMenu,
hasResolvedNavigationMenus: hasFinishedResolution(
'getEntityRecords',
Expand Down

0 comments on commit e634361

Please sign in to comment.