Skip to content

Commit

Permalink
Remove the check for draft navigation menus from the UnsavedInnerBloc…
Browse files Browse the repository at this point in the history
…ks component (#49161)

* Navigation: Remove the check for draft navigation menus from the UnsavedInnerBlocks component

* Add a new selector to check the status of all navigation menus
  • Loading branch information
scruffian authored May 11, 2023
1 parent 8346327 commit 2f77022
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions packages/block-library/src/navigation/edit/unsaved-inner-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,10 @@ 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';

const EMPTY_OBJECT = {};
const DRAFT_MENU_PARAMS = [
'postType',
'wp_navigation',
{ status: 'draft', per_page: -1 },
];

export default function UnsavedInnerBlocks( {
blocks,
Expand Down Expand Up @@ -75,35 +69,30 @@ export default function UnsavedInnerBlocks( {
}
);

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

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

return {
isSaving: isSavingEntityRecord( 'postType', 'wp_navigation' ),
draftNavigationMenus: getEntityRecords(
// This is needed so that hasResolvedDraftNavigationMenus gives the correct status.
...DRAFT_MENU_PARAMS
),
hasResolvedDraftNavigationMenus: hasFinishedResolution(
hasResolvedAllNavigationMenus: hasFinishedResolution(
'getEntityRecords',
DRAFT_MENU_PARAMS
[
'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 @@ -121,8 +110,7 @@ export default function UnsavedInnerBlocks( {
if (
isDisabled ||
isSaving ||
! hasResolvedDraftNavigationMenus ||
! hasResolvedNavigationMenus ||
! hasResolvedAllNavigationMenus ||
! hasSelection ||
! innerBlocksAreDirty
) {
Expand All @@ -135,8 +123,7 @@ export default function UnsavedInnerBlocks( {
createNavigationMenu,
isDisabled,
isSaving,
hasResolvedDraftNavigationMenus,
hasResolvedNavigationMenus,
hasResolvedAllNavigationMenus,
innerBlocksAreDirty,
hasSelection,
] );
Expand Down

0 comments on commit 2f77022

Please sign in to comment.