Skip to content

Commit 801681b

Browse files
authored
Remove all edit functionality from Navigation in Browse Mode (#50788)
* Remove Add Submenu option * Remove Link UI entirely
1 parent 8b12c1c commit 801681b

File tree

2 files changed

+4
-141
lines changed

2 files changed

+4
-141
lines changed

packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js

Lines changed: 2 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
/**
22
* WordPress dependencies
33
*/
4-
import { createBlock } from '@wordpress/blocks';
5-
import {
6-
addSubmenu,
7-
chevronUp,
8-
chevronDown,
9-
moreVertical,
10-
} from '@wordpress/icons';
4+
5+
import { chevronUp, chevronDown, moreVertical } from '@wordpress/icons';
116
import { DropdownMenu, MenuItem, MenuGroup } from '@wordpress/components';
127
import { useDispatch, useSelect } from '@wordpress/data';
138
import { __, sprintf } from '@wordpress/i18n';
@@ -19,67 +14,6 @@ const POPOVER_PROPS = {
1914
variant: 'toolbar',
2015
};
2116

22-
const BLOCKS_THAT_CAN_BE_CONVERTED_TO_SUBMENU = [
23-
'core/navigation-link',
24-
'core/navigation-submenu',
25-
];
26-
27-
function AddSubmenuItem( { block, onClose, expandedState, expand } ) {
28-
const { insertBlock, replaceBlock, replaceInnerBlocks } =
29-
useDispatch( blockEditorStore );
30-
31-
const clientId = block.clientId;
32-
const isDisabled = ! BLOCKS_THAT_CAN_BE_CONVERTED_TO_SUBMENU.includes(
33-
block.name
34-
);
35-
return (
36-
<MenuItem
37-
icon={ addSubmenu }
38-
disabled={ isDisabled }
39-
onClick={ () => {
40-
const updateSelectionOnInsert = false;
41-
const newLink = createBlock( 'core/navigation-link' );
42-
43-
if ( block.name === 'core/navigation-submenu' ) {
44-
insertBlock(
45-
newLink,
46-
block.innerBlocks.length,
47-
clientId,
48-
updateSelectionOnInsert
49-
);
50-
} else {
51-
// Convert to a submenu if the block currently isn't one.
52-
const newSubmenu = createBlock(
53-
'core/navigation-submenu',
54-
block.attributes,
55-
block.innerBlocks
56-
);
57-
58-
// The following must happen as two independent actions.
59-
// Why? Because the offcanvas editor relies on the getLastInsertedBlocksClientIds
60-
// selector to determine which block is "active". As the UX needs the newLink to be
61-
// the "active" block it must be the last block to be inserted.
62-
// Therefore the Submenu is first created and **then** the newLink is inserted
63-
// thus ensuring it is the last inserted block.
64-
replaceBlock( clientId, newSubmenu );
65-
66-
replaceInnerBlocks(
67-
newSubmenu.clientId,
68-
[ newLink ],
69-
updateSelectionOnInsert
70-
);
71-
}
72-
if ( ! expandedState[ block.clientId ] ) {
73-
expand( block.clientId );
74-
}
75-
onClose();
76-
} }
77-
>
78-
{ __( 'Add submenu link' ) }
79-
</MenuItem>
80-
);
81-
}
82-
8317
export default function LeafMoreMenu( props ) {
8418
const { block } = props;
8519
const { clientId } = block;
@@ -131,13 +65,6 @@ export default function LeafMoreMenu( props ) {
13165
>
13266
{ __( 'Move down' ) }
13367
</MenuItem>
134-
<AddSubmenuItem
135-
block={ block }
136-
onClose={ onClose }
137-
expanded
138-
expandedState={ props.expandedState }
139-
expand={ props.expand }
140-
/>
14168
</MenuGroup>
14269
<MenuGroup>
14370
<MenuItem

packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js

Lines changed: 2 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ import {
66
store as blockEditorStore,
77
BlockList,
88
BlockTools,
9-
__experimentalLinkControl as LinkControl,
109
} from '@wordpress/block-editor';
1110
import { useDispatch, useSelect } from '@wordpress/data';
1211
import { createBlock } from '@wordpress/blocks';
13-
import { Popover, VisuallyHidden } from '@wordpress/components';
14-
import { __unstableStripHTML as stripHTML } from '@wordpress/dom';
12+
import { VisuallyHidden } from '@wordpress/components';
1513
import { useCallback, useEffect, useState } from '@wordpress/element';
1614
import { store as coreStore } from '@wordpress/core-data';
1715

@@ -21,33 +19,6 @@ import { store as coreStore } from '@wordpress/core-data';
2119
import { unlock } from '../../private-apis';
2220
import LeafMoreMenu from './leaf-more-menu';
2321

24-
function CustomLinkAdditionalBlockUI( { block, onClose } ) {
25-
const { updateBlockAttributes } = useDispatch( blockEditorStore );
26-
const { label, url, opensInNewTab } = block.attributes;
27-
const link = {
28-
url,
29-
opensInNewTab,
30-
title: label && stripHTML( label ),
31-
};
32-
return (
33-
<Popover placement="bottom" shift onClose={ onClose }>
34-
<LinkControl
35-
hasTextControl
36-
hasRichPreviews
37-
value={ link }
38-
onChange={ ( updatedValue ) => {
39-
updateBlockAttributes( block.clientId, {
40-
label: updatedValue.title,
41-
url: updatedValue.url,
42-
opensInNewTab: updatedValue.opensInNewTab,
43-
} );
44-
onClose();
45-
} }
46-
onCancel={ onClose }
47-
/>
48-
</Popover>
49-
);
50-
}
5122
// Needs to be kept in sync with the query used at packages/block-library/src/page-list/edit.js.
5223
const MAX_PAGE_COUNT = 100;
5324
const PAGES_QUERY = [
@@ -102,29 +73,6 @@ export default function NavigationMenuContent( { rootClientId, onSelect } ) {
10273
const { replaceBlock, __unstableMarkNextChangeAsNotPersistent } =
10374
useDispatch( blockEditorStore );
10475

105-
const [ customLinkEditPopoverOpenId, setIsCustomLinkEditPopoverOpenId ] =
106-
useState( false );
107-
108-
const renderAdditionalBlockUICallback = useCallback(
109-
( block ) => {
110-
if (
111-
customLinkEditPopoverOpenId &&
112-
block.clientId === customLinkEditPopoverOpenId
113-
) {
114-
return (
115-
<CustomLinkAdditionalBlockUI
116-
block={ block }
117-
onClose={ () => {
118-
setIsCustomLinkEditPopoverOpenId( false );
119-
} }
120-
/>
121-
);
122-
}
123-
return null;
124-
},
125-
[ customLinkEditPopoverOpenId, setIsCustomLinkEditPopoverOpenId ]
126-
);
127-
12876
// Delay loading stop by 50ms to avoid flickering.
12977
useEffect( () => {
13078
let timeoutId;
@@ -156,22 +104,11 @@ export default function NavigationMenuContent( { rootClientId, onSelect } ) {
156104
block.clientId,
157105
createBlock( 'core/navigation-link', block.attributes )
158106
);
159-
} else if (
160-
block.name === 'core/navigation-link' &&
161-
block.attributes.kind === 'custom' &&
162-
block.attributes.url
163-
) {
164-
setIsCustomLinkEditPopoverOpenId( block.clientId );
165107
} else {
166108
onSelect( block );
167109
}
168110
},
169-
[
170-
onSelect,
171-
__unstableMarkNextChangeAsNotPersistent,
172-
replaceBlock,
173-
setIsCustomLinkEditPopoverOpenId,
174-
]
111+
[ onSelect, __unstableMarkNextChangeAsNotPersistent, replaceBlock ]
175112
);
176113

177114
// The hidden block is needed because it makes block edit side effects trigger.
@@ -188,7 +125,6 @@ export default function NavigationMenuContent( { rootClientId, onSelect } ) {
188125
onSelect={ offCanvasOnselect }
189126
blockSettingsMenu={ LeafMoreMenu }
190127
showAppender={ false }
191-
renderAdditionalBlockUI={ renderAdditionalBlockUICallback }
192128
/>
193129
) }
194130
<VisuallyHidden aria-hidden="true">

0 commit comments

Comments
 (0)