Skip to content

Commit

Permalink
Enable undo after creating a new menu (#47683)
Browse files Browse the repository at this point in the history
* removes the publish status effect from navigation edit componet and adds it to the create menu hook

* Only edit in memory for Drafts

Co-authored-by: Daniel Richards <677833+talldan@users.noreply.github.com>

---------

Co-authored-by: Daniel Richards <677833+talldan@users.noreply.github.com>
  • Loading branch information
draganescu and talldan authored Feb 7, 2023
1 parent 2ce5507 commit b61d0c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 29 deletions.
29 changes: 1 addition & 28 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
__experimentalUseBlockOverlayActive as useBlockOverlayActive,
__experimentalUseMultipleOriginColorsAndGradients as useMultipleOriginColorsAndGradients,
} from '@wordpress/block-editor';
import { EntityProvider, store as coreStore } from '@wordpress/core-data';
import { EntityProvider } from '@wordpress/core-data';

import { useDispatch } from '@wordpress/data';
import {
Expand Down Expand Up @@ -112,7 +112,6 @@ function Navigation( {

const recursionId = `navigationMenu/${ ref }`;
const hasAlreadyRendered = useHasRecursion( recursionId );
const { editEntityRecord } = useDispatch( coreStore );

// Preload classic menus, so that they don't suddenly pop-in when viewing
// the Select Menu dropdown.
Expand All @@ -128,11 +127,6 @@ function Navigation( {
name: 'block-library/core/navigation/classic-menu-conversion',
} );

const [ showMenuAutoPublishDraftNotice, hideMenuAutoPublishDraftNotice ] =
useNavigationNotice( {
name: 'block-library/core/navigation/auto-publish-draft',
} );

const [
showNavigationMenuPermissionsNotice,
hideNavigationMenuPermissionsNotice,
Expand Down Expand Up @@ -209,7 +203,6 @@ function Navigation( {
isNavigationMenuResolved,
isNavigationMenuMissing,
navigationMenus,
navigationMenu,
canUserUpdateNavigationMenu,
hasResolvedCanUserUpdateNavigationMenu,
canUserDeleteNavigationMenu,
Expand Down Expand Up @@ -536,26 +529,6 @@ function Navigation( {
{ open: overlayMenuPreview }
);

// Prompt the user to publish the menu they have set as a draft
const isDraftNavigationMenu = navigationMenu?.status === 'draft';
useEffect( () => {
hideMenuAutoPublishDraftNotice();
if ( ! isDraftNavigationMenu ) {
return;
}
editEntityRecord(
'postType',
'wp_navigation',
navigationMenu?.id,
{ status: 'publish' },
{ throwOnError: true }
).catch( () => {
showMenuAutoPublishDraftNotice(
__( 'Error occurred while publishing the navigation menu.' )
);
} );
}, [ isDraftNavigationMenu, navigationMenu ] );

const colorGradientSettings = useMultipleOriginColorsAndGradients();
const stylingInspectorControls = (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function useCreateNavigationMenu( clientId ) {
const [ value, setValue ] = useState( null );
const [ error, setError ] = useState( null );

const { saveEntityRecord } = useDispatch( coreStore );
const { saveEntityRecord, editEntityRecord } = useDispatch( coreStore );
const generateDefaultTitle = useGenerateDefaultNavigationTitle( clientId );

// This callback uses data from the two placeholder steps and only creates
Expand Down Expand Up @@ -68,6 +68,18 @@ export default function useCreateNavigationMenu( clientId ) {
.then( ( response ) => {
setValue( response );
setStatus( CREATE_NAVIGATION_MENU_SUCCESS );

// Set the status to publish so that the Navigation block
// shows up in the multi entity save flow.
if ( postStatus !== 'publish' ) {
editEntityRecord(
'postType',
'wp_navigation',
response.id,
{ status: 'publish' }
);
}

return response;
} )
.catch( ( err ) => {
Expand Down

1 comment on commit b61d0c9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in b61d0c9.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4114499749
📝 Reported issues:

Please sign in to comment.