-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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: Make navigation page list load its items on navigation sidebar. #47853
Changes from all commits
f10f121
85749c0
148b2c1
f3f7766
8c2f80d
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 |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
import { | ||
privateApis as blockEditorPrivateApis, | ||
store as blockEditorStore, | ||
BlockList, | ||
BlockTools, | ||
} from '@wordpress/block-editor'; | ||
import { useEffect } from '@wordpress/element'; | ||
import { useDispatch } from '@wordpress/data'; | ||
|
@@ -34,6 +36,7 @@ const ALLOWED_BLOCKS = { | |
'core/navigation-link', | ||
'core/navigation-submenu', | ||
], | ||
'core/page-list': [ 'core/page-list-item' ], | ||
}; | ||
|
||
export default function NavigationMenu( { innerBlocks, onSelect } ) { | ||
|
@@ -56,11 +59,20 @@ export default function NavigationMenu( { innerBlocks, onSelect } ) { | |
} ); | ||
}, [ updateBlockListSettings, innerBlocks ] ); | ||
|
||
// 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. | ||
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. This is unexpected for me and also raises some fundamental questions :) It seems the page list block is using "InnerBlocks" in a very unexpected way 🤔
Anyway, it doesn't seem like something that needs solving immediately, but it's an interesting question to raise. 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. Yeah, it's an interesting one. I don't think the way you describe it as working is quite right though, instead it generates 'parsed' block data using the pages that exist on a site. I don't think this is a misuse in terms of inner blocks being used as a controlled component, it makes sense in a way that it's synced to an external data source, the same way as reusable blocks or template parts are. The way list view is evolving though is as a a separate view on a block tree that can now exist without a canvas, and we do have an issue around the block's
Is the idea of a loader a bit like hydration of a block, so that page list data would be present at load rather than at the block's runtime? |
||
return ( | ||
<OffCanvasEditor | ||
blocks={ innerBlocks } | ||
onSelect={ onSelect } | ||
LeafMoreMenu={ LeafMoreMenu } | ||
/> | ||
<> | ||
<OffCanvasEditor | ||
blocks={ innerBlocks } | ||
onSelect={ onSelect } | ||
LeafMoreMenu={ LeafMoreMenu } | ||
/> | ||
<div style={ { display: 'none' } }> | ||
<BlockTools> | ||
<BlockList /> | ||
</BlockTools> | ||
</div> | ||
</> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ export default function SidebarNavigationScreenNavigationMenus() { | |
const history = useHistory(); | ||
const onSelect = useCallback( | ||
( selectedBlock ) => { | ||
const { attributes } = selectedBlock; | ||
const { attributes, name } = selectedBlock; | ||
if ( | ||
attributes.kind === 'post-type' && | ||
attributes.id && | ||
|
@@ -27,6 +27,12 @@ export default function SidebarNavigationScreenNavigationMenus() { | |
postId: attributes.id, | ||
} ); | ||
} | ||
if ( name === 'core/page-list-item' && attributes.id && history ) { | ||
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. Should we be adding a "name" check to the first case as well (check that we're clicking on navigation items) for safeties or not? 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. I don't think we need a check if an item is selected and has a post type and id it is safe to assume we should move there. In the future we may have more types of items or even third parties I think just relying on kind and id should be enough. |
||
history.push( { | ||
postType: 'page', | ||
postId: attributes.id, | ||
} ); | ||
} | ||
}, | ||
[ history ] | ||
); | ||
|
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 a block list is now being rendered, you may not need the allowedBlocks hack, as the block edit functions will naturally set that.
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.
yes, I'm getting rid of that in #48689