Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Off Canvas Editor add submenu item option #46562

Merged
merged 2 commits into from
Dec 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
Copy link
Contributor

Choose a reason for hiding this comment

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

Aside: I added this line to #46166

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'
Comment on lines +372 to +373
Copy link
Contributor

Choose a reason for hiding this comment

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

I added this to #46166

) {
const updateSelectionOnInsert = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Given the API this is very helpful 🙇

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