-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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: Inserter on the navigation sidebar. (#48049 #48049
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -80,9 +80,10 @@ function OffCanvasEditor( | |||
const { clientIdsTree, draggedClientIds, selectedClientIds } = | ||||
useListViewClientIds( blocks ); | ||||
|
||||
const { visibleBlockCount, shouldShowInnerBlocks } = useSelect( | ||||
const { visibleBlockCount, shouldShowInnerBlocks, parentId } = useSelect( | ||||
( select ) => { | ||||
const { | ||||
getBlockRootClientId, | ||||
getGlobalBlockCount, | ||||
getClientIdsOfDescendants, | ||||
__unstableGetEditorMode, | ||||
|
@@ -94,9 +95,13 @@ function OffCanvasEditor( | |||
return { | ||||
visibleBlockCount: getGlobalBlockCount() - draggedBlockCount, | ||||
shouldShowInnerBlocks: __unstableGetEditorMode() !== 'zoom-out', | ||||
parentId: | ||||
blocks.length > 0 | ||||
? getBlockRootClientId( blocks[ 0 ].clientId ) | ||||
: undefined, | ||||
}; | ||||
}, | ||||
[ draggedClientIds ] | ||||
[ draggedClientIds, blocks ] | ||||
); | ||||
|
||||
const { updateBlockSelection } = useBlockSelection(); | ||||
|
@@ -227,6 +232,7 @@ function OffCanvasEditor( | |||
> | ||||
<ListViewContext.Provider value={ contextValue }> | ||||
<ListViewBranch | ||||
parentId={ parentId } | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is a better name for this rootBlockId or something as the list view is not really a child of a block? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The component ListViewBranch already had the parentId property, I'm just passing the property in a case where we were not passing it before, but the prop already existed.
I can change it to rootBlockId on the offsite canvas editor and the list view if you prefer. I don't have a specific preference. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I lost this fact in reviewing the code, thought we just added |
||||
blocks={ clientIdsTree } | ||||
selectBlock={ selectEditorBlock } | ||||
showBlockMovers={ showBlockMovers } | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this addition do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is no parentId, we don't show the appender. The case where we may not have a parentId is if for example, we don't have navigation menus on the page the sidebar shows the offsite navigation editor which says correctly navigation is empty but without this change shows an appender that adds things to the root which is unexpected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand. Ok it's a good guard, but we should never be in this situation:
I think the navigation is not empty just because the current page is not showing it. This is tricky and outside the scope of this PR but, what if the page with no navigation block is linked in the navigation, clicking on it in the sidebar would then hide the navigation from the sidebar - quite unexpected.