Skip to content

Commit

Permalink
Add a new selector to check the status of all navigation menus
Browse files Browse the repository at this point in the history
  • Loading branch information
scruffian authored and getdave committed May 11, 2023
1 parent 9a3d4cc commit 277b515
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions packages/block-library/src/navigation/edit/unsaved-inner-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { useContext, useEffect, useRef, useMemo } from '@wordpress/element';
/**
* Internal dependencies
*/
import useNavigationMenu from '../use-navigation-menu';
import { areBlocksDirty } from './are-blocks-dirty';
import { DEFAULT_BLOCK, ALLOWED_BLOCKS } from '../constants';

Expand Down Expand Up @@ -70,23 +69,30 @@ export default function UnsavedInnerBlocks( {
}
);

const { isSaving } = useSelect(
const { isSaving, hasResolvedAllNavigationMenus } = useSelect(
( select ) => {
if ( isDisabled ) {
return EMPTY_OBJECT;
}

const { isSavingEntityRecord } = select( coreStore );
const { hasFinishedResolution, isSavingEntityRecord } =
select( coreStore );

return {
isSaving: isSavingEntityRecord( 'postType', 'wp_navigation' ),
hasResolvedAllNavigationMenus: hasFinishedResolution(
'getEntityRecords',
[
'postType',
'wp_navigation',
{ per_page: -1, status: [ 'publish', 'draft' ] },
]
),
};
},
[ isDisabled ]
);

const { hasResolvedNavigationMenus } = useNavigationMenu();

// Automatically save the uncontrolled blocks.
useEffect( () => {
// The block will be disabled when used in a BlockPreview.
Expand All @@ -104,7 +110,7 @@ export default function UnsavedInnerBlocks( {
if (
isDisabled ||
isSaving ||
! hasResolvedNavigationMenus ||
! hasResolvedAllNavigationMenus ||
! hasSelection ||
! innerBlocksAreDirty
) {
Expand All @@ -117,7 +123,7 @@ export default function UnsavedInnerBlocks( {
createNavigationMenu,
isDisabled,
isSaving,
hasResolvedNavigationMenus,
hasResolvedAllNavigationMenus,
innerBlocksAreDirty,
hasSelection,
] );
Expand Down

0 comments on commit 277b515

Please sign in to comment.