Skip to content

Commit

Permalink
Fix: Show creation popover on empty page links in the navigation side…
Browse files Browse the repository at this point in the history
…bar. (#48746)
  • Loading branch information
jorgefilipecosta authored Mar 6, 2023
1 parent 1095de0 commit 5673541
Showing 1 changed file with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import {
BlockList,
BlockTools,
} from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';
import { createBlock } from '@wordpress/blocks';
import { useCallback } from '@wordpress/element';

/**
* Internal dependencies
Expand All @@ -30,9 +32,29 @@ export default function NavigationMenuContent( { rootClientId, onSelect } ) {
},
[ rootClientId ]
);
const { replaceBlock, __unstableMarkNextChangeAsNotPersistent } =
useDispatch( blockEditorStore );

const { OffCanvasEditor, LeafMoreMenu } = unlock( blockEditorPrivateApis );

const offCanvasOnselect = useCallback(
( block ) => {
if (
block.name === 'core/navigation-link' &&
! block.attributes.url
) {
__unstableMarkNextChangeAsNotPersistent();
replaceBlock(
block.clientId,
createBlock( 'core/navigation-link', block.attributes )
);
} else {
onSelect( block );
}
},
[ onSelect, __unstableMarkNextChangeAsNotPersistent, replaceBlock ]
);

// The hidden block is needed because it makes block edit side effects trigger.
// For example a navigation page list load its items has an effect on edit to load its items.
return (
Expand All @@ -41,12 +63,12 @@ export default function NavigationMenuContent( { rootClientId, onSelect } ) {
{ ! isLoading && (
<OffCanvasEditor
blocks={ clientIdsTree }
onSelect={ onSelect }
onSelect={ offCanvasOnselect }
LeafMoreMenu={ LeafMoreMenu }
showAppender={ false }
/>
) }
<div style={ { display: 'none' } }>
<div style={ { visibility: 'hidden' } }>
<BlockTools>
<BlockList />
</BlockTools>
Expand Down

1 comment on commit 5673541

@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 5673541.
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/4342310080
📝 Reported issues:

Please sign in to comment.