-
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
Page List: Respect the selected parent page when converting to a list of navigation links #47651
Conversation
Size Change: +88 B (0%) Total Size: 1.31 MB
ℹ️ View Unchanged
|
Flaky tests detected in d669a97. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4115677675
|
@@ -30,11 +37,57 @@ export function convertToNavigationLinks( pages = [] ) { | |||
// Use a placeholder if the child appears before parent in list. | |||
linkMap[ parent ] = { innerBlocks: [] }; | |||
} | |||
// Although these variables are not referenced, they are needed to store the innerBlocks in memory. |
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 don't understand: how are they useful if nobody reads them?
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 don't 100% get it either. I think it means they are stored in memory, so that they don't get lost when a mutation happens. This is old code that might be possible to write in a clearer way, but I think that's outside of the scope of this PR.
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 you remove these lines it breaks :)
* | ||
* @return {Object} The navigation link block with the given id. | ||
*/ | ||
function findById( navigationLinks, id ) { |
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.
Since it's not generic the name should reflect that findNavigationLinkById
packages/block-library/src/page-list/use-convert-to-navigation-links.js
Outdated
Show resolved
Hide resolved
let navigationLinks = createNavigationLinks( pages ); | ||
|
||
// If a parent page ID is provided, only return the children of that page. | ||
if ( parentPageID ) { |
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.
Nit: I wonder if we should not instead filter pages
and use createNavigationLinks
on the filtered pages?
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 thought about that, but it's technically more complex as pages
isn't a nested array, so we'd have to filter on a parent id, and then all the parents of that id, and then all the parents of that one etc. I think this approach is simpler.
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.
This works great! Left a couple nits but otherwise the code looks good too.
What?
When converting a Page List block to a list of links we should respect the selected parent, rather than using all pages.
Why?
This is the expected behaviour.
How?
We need to do some quite complex recursion over the innerBlocks to ensure that we find the right block to use as a parent. The
findById
function could be made more general.Testing Instructions
Testing Instructions for Keyboard
As above
Screenshots or screencast
Screen.Recording.2023-02-01.at.15.42.01.mov