Skip to content

Commit

Permalink
Fix Off Canvas Editor add submenu item option (#46562)
Browse files Browse the repository at this point in the history
* Fix Off Canvas Editor add submenu item option

* Fix comment
  • Loading branch information
talldan authored Dec 15, 2022
1 parent 3f14cbb commit 5475424
Showing 1 changed file with 34 additions and 21 deletions.
55 changes: 34 additions & 21 deletions packages/block-editor/src/components/off-canvas-editor/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import useBlockDisplayInformation from '../use-block-display-information';
import { useBlockLock } from '../block-lock';

function ListViewBlock( {
block,
block: { clientId },
isDragged,
isSelected,
isBranchSelected,
Expand All @@ -60,7 +60,6 @@ function ListViewBlock( {
} ) {
const cellRef = useRef( null );
const [ isHovered, setIsHovered ] = useState( false );
const { clientId, attributes } = block;

const { isLocked, isContentLocked } = useBlockLock( clientId );
const forceSelectionContentLock = useSelect(
Expand All @@ -87,20 +86,20 @@ function ListViewBlock( {
( isSelected &&
selectedClientIds[ selectedClientIds.length - 1 ] === clientId );

const { replaceBlock, toggleBlockHighlight } =
const { insertBlock, replaceBlock, toggleBlockHighlight } =
useDispatch( blockEditorStore );

const blockInformation = useBlockDisplayInformation( clientId );
const blockName = useSelect(
( select ) => select( blockEditorStore ).getBlockName( clientId ),
const block = useSelect(
( select ) => select( blockEditorStore ).getBlock( clientId ),
[ clientId ]
);

// When a block hides its toolbar it also hides the block settings menu,
// since that menu is part of the toolbar in the editor canvas.
// List View respects this by also hiding the block settings menu.
const showBlockActions = hasBlockSupport(
blockName,
block.name,
'__experimentalToolbar',
true
);
Expand Down Expand Up @@ -145,7 +144,7 @@ function ListViewBlock( {

const { isTreeGridMounted, expand, collapse } = useListViewContext();

const isEditable = blockName !== 'core/page-list-item';
const isEditable = block.name !== 'core/page-list-item';
const hasSiblings = siblingBlockCount > 0;
const hasRenderedMovers = showBlockMovers && hasSiblings;
const moverCellClassName = classnames(
Expand Down Expand Up @@ -369,20 +368,34 @@ function ListViewBlock( {
const newLink = createBlock(
'core/navigation-link'
);
const newSubmenu = createBlock(
'core/navigation-submenu',
attributes,
block.innerBlocks
? [
...block.innerBlocks,
newLink,
]
: [ newLink ]
);
replaceBlock(
clientId,
newSubmenu
);
if (
block.name ===
'core/navigation-submenu'
) {
const updateSelectionOnInsert = false;
insertBlock(
newLink,
block.innerBlocks.length,
clientId,
updateSelectionOnInsert
);
} else {
// Convert to a submenu if the block currently isn't one.
const newSubmenu = createBlock(
'core/navigation-submenu',
block.attributes,
block.innerBlocks
? [
...block.innerBlocks,
newLink,
]
: [ newLink ]
);
replaceBlock(
clientId,
newSubmenu
);
}
onClose();
} }
>
Expand Down

0 comments on commit 5475424

Please sign in to comment.