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

Page List: Add ability to only show child pages #31471

Closed
wants to merge 6 commits into from

Conversation

mkaz
Copy link
Member

@mkaz mkaz commented May 4, 2021

Description

This scratches my own itch, I have a set of tutorial pages that has a single parent page, and then children pages off that parent. I want to build a table of contents that just include a listing of all the child pages.

Example in old theme here if curious the way it was built in the old theme is in this template page.

So for a block theme, I want to use the Pages List to do the same, but need to be able to filter that block and only show the children of the current page.

Fixes #31063

Implementation ? This uses global $post to get the $parent_id which may not be ideal, but post-comments and latest-posts both use the same. Open to suggestions on a better way to fetch parent id.

How has this been tested?

  1. Create new page and a child of that page
  2. Add Navigation block to the parent page
  3. Add Page List to the page
  4. Confirm that all pages show (default behavior)
  5. Toggle Show children only
  6. Confirm that only the child page shows

Types of changes

  • Adds new childrenOnly attribute to PageList block
  • Updates server-side render to use attribute and filter pages

@mkaz mkaz requested a review from ajitbohra as a code owner May 4, 2021 17:46
@mkaz mkaz added the [Block] Page List Affects the Page List Block label May 4, 2021
@github-actions
Copy link

github-actions bot commented May 4, 2021

Size Change: +134 B (0%)

Total Size: 1.08 MB

Filename Size Change
build/block-library/index.min.js 155 kB +134 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 931 B
build/admin-manifest/index.min.js 1.09 kB
build/annotations/index.min.js 2.7 kB
build/api-fetch/index.min.js 2.21 kB
build/autop/index.min.js 2.08 kB
build/blob/index.min.js 459 B
build/block-directory/index.min.js 6.2 kB
build/block-directory/style-rtl.css 1.01 kB
build/block-directory/style.css 1.01 kB
build/block-editor/default-editor-styles-rtl.css 378 B
build/block-editor/default-editor-styles.css 378 B
build/block-editor/index.min.js 135 kB
build/block-editor/style-rtl.css 14.1 kB
build/block-editor/style.css 14 kB
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 65 B
build/block-library/blocks/archives/style.css 65 B
build/block-library/blocks/audio/editor-rtl.css 58 B
build/block-library/blocks/audio/editor.css 58 B
build/block-library/blocks/audio/style-rtl.css 111 B
build/block-library/blocks/audio/style.css 111 B
build/block-library/blocks/audio/theme-rtl.css 125 B
build/block-library/blocks/audio/theme.css 125 B
build/block-library/blocks/block/editor-rtl.css 161 B
build/block-library/blocks/block/editor.css 161 B
build/block-library/blocks/button/editor-rtl.css 470 B
build/block-library/blocks/button/editor.css 470 B
build/block-library/blocks/button/style-rtl.css 560 B
build/block-library/blocks/button/style.css 560 B
build/block-library/blocks/buttons/editor-rtl.css 309 B
build/block-library/blocks/buttons/editor.css 309 B
build/block-library/blocks/buttons/style-rtl.css 317 B
build/block-library/blocks/buttons/style.css 317 B
build/block-library/blocks/calendar/style-rtl.css 207 B
build/block-library/blocks/calendar/style.css 207 B
build/block-library/blocks/categories/editor-rtl.css 84 B
build/block-library/blocks/categories/editor.css 83 B
build/block-library/blocks/categories/style-rtl.css 79 B
build/block-library/blocks/categories/style.css 79 B
build/block-library/blocks/code/style-rtl.css 90 B
build/block-library/blocks/code/style.css 90 B
build/block-library/blocks/code/theme-rtl.css 131 B
build/block-library/blocks/code/theme.css 131 B
build/block-library/blocks/columns/editor-rtl.css 206 B
build/block-library/blocks/columns/editor.css 205 B
build/block-library/blocks/columns/style-rtl.css 497 B
build/block-library/blocks/columns/style.css 496 B
build/block-library/blocks/cover/editor-rtl.css 546 B
build/block-library/blocks/cover/editor.css 547 B
build/block-library/blocks/cover/style-rtl.css 1.17 kB
build/block-library/blocks/cover/style.css 1.17 kB
build/block-library/blocks/embed/editor-rtl.css 488 B
build/block-library/blocks/embed/editor.css 488 B
build/block-library/blocks/embed/style-rtl.css 417 B
build/block-library/blocks/embed/style.css 417 B
build/block-library/blocks/embed/theme-rtl.css 124 B
build/block-library/blocks/embed/theme.css 124 B
build/block-library/blocks/file/editor-rtl.css 300 B
build/block-library/blocks/file/editor.css 300 B
build/block-library/blocks/file/style-rtl.css 255 B
build/block-library/blocks/file/style.css 255 B
build/block-library/blocks/file/view.min.js 322 B
build/block-library/blocks/freeform/editor-rtl.css 2.44 kB
build/block-library/blocks/freeform/editor.css 2.44 kB
build/block-library/blocks/gallery/editor-rtl.css 977 B
build/block-library/blocks/gallery/editor.css 982 B
build/block-library/blocks/gallery/style-rtl.css 1.6 kB
build/block-library/blocks/gallery/style.css 1.59 kB
build/block-library/blocks/gallery/theme-rtl.css 122 B
build/block-library/blocks/gallery/theme.css 122 B
build/block-library/blocks/group/editor-rtl.css 159 B
build/block-library/blocks/group/editor.css 159 B
build/block-library/blocks/group/style-rtl.css 57 B
build/block-library/blocks/group/style.css 57 B
build/block-library/blocks/group/theme-rtl.css 78 B
build/block-library/blocks/group/theme.css 78 B
build/block-library/blocks/heading/style-rtl.css 114 B
build/block-library/blocks/heading/style.css 114 B
build/block-library/blocks/home-link/style-rtl.css 247 B
build/block-library/blocks/home-link/style.css 247 B
build/block-library/blocks/html/editor-rtl.css 332 B
build/block-library/blocks/html/editor.css 333 B
build/block-library/blocks/image/editor-rtl.css 731 B
build/block-library/blocks/image/editor.css 730 B
build/block-library/blocks/image/style-rtl.css 502 B
build/block-library/blocks/image/style.css 505 B
build/block-library/blocks/image/theme-rtl.css 124 B
build/block-library/blocks/image/theme.css 124 B
build/block-library/blocks/latest-comments/style-rtl.css 284 B
build/block-library/blocks/latest-comments/style.css 284 B
build/block-library/blocks/latest-posts/editor-rtl.css 137 B
build/block-library/blocks/latest-posts/editor.css 137 B
build/block-library/blocks/latest-posts/style-rtl.css 528 B
build/block-library/blocks/latest-posts/style.css 527 B
build/block-library/blocks/list/style-rtl.css 94 B
build/block-library/blocks/list/style.css 94 B
build/block-library/blocks/media-text/editor-rtl.css 266 B
build/block-library/blocks/media-text/editor.css 263 B
build/block-library/blocks/media-text/style-rtl.css 493 B
build/block-library/blocks/media-text/style.css 490 B
build/block-library/blocks/more/editor-rtl.css 431 B
build/block-library/blocks/more/editor.css 431 B
build/block-library/blocks/navigation-link/editor-rtl.css 642 B
build/block-library/blocks/navigation-link/editor.css 642 B
build/block-library/blocks/navigation-link/style-rtl.css 94 B
build/block-library/blocks/navigation-link/style.css 94 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 299 B
build/block-library/blocks/navigation-submenu/editor.css 299 B
build/block-library/blocks/navigation-submenu/style-rtl.css 195 B
build/block-library/blocks/navigation-submenu/style.css 195 B
build/block-library/blocks/navigation-submenu/view.min.js 343 B
build/block-library/blocks/navigation/editor-rtl.css 1.81 kB
build/block-library/blocks/navigation/editor.css 1.81 kB
build/block-library/blocks/navigation/style-rtl.css 1.71 kB
build/block-library/blocks/navigation/style.css 1.7 kB
build/block-library/blocks/navigation/view.min.js 2.74 kB
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 377 B
build/block-library/blocks/page-list/editor.css 377 B
build/block-library/blocks/page-list/style-rtl.css 198 B
build/block-library/blocks/page-list/style.css 198 B
build/block-library/blocks/paragraph/editor-rtl.css 157 B
build/block-library/blocks/paragraph/editor.css 157 B
build/block-library/blocks/paragraph/style-rtl.css 273 B
build/block-library/blocks/paragraph/style.css 273 B
build/block-library/blocks/post-author/style-rtl.css 175 B
build/block-library/blocks/post-author/style.css 176 B
build/block-library/blocks/post-comments-form/style-rtl.css 347 B
build/block-library/blocks/post-comments-form/style.css 347 B
build/block-library/blocks/post-comments/style-rtl.css 492 B
build/block-library/blocks/post-comments/style.css 493 B
build/block-library/blocks/post-content/style-rtl.css 56 B
build/block-library/blocks/post-content/style.css 56 B
build/block-library/blocks/post-excerpt/editor-rtl.css 73 B
build/block-library/blocks/post-excerpt/editor.css 73 B
build/block-library/blocks/post-excerpt/style-rtl.css 69 B
build/block-library/blocks/post-excerpt/style.css 69 B
build/block-library/blocks/post-featured-image/editor-rtl.css 396 B
build/block-library/blocks/post-featured-image/editor.css 397 B
build/block-library/blocks/post-featured-image/style-rtl.css 156 B
build/block-library/blocks/post-featured-image/style.css 156 B
build/block-library/blocks/post-template/editor-rtl.css 99 B
build/block-library/blocks/post-template/editor.css 98 B
build/block-library/blocks/post-template/style-rtl.css 391 B
build/block-library/blocks/post-template/style.css 392 B
build/block-library/blocks/post-terms/style-rtl.css 73 B
build/block-library/blocks/post-terms/style.css 73 B
build/block-library/blocks/post-title/style-rtl.css 60 B
build/block-library/blocks/post-title/style.css 60 B
build/block-library/blocks/preformatted/style-rtl.css 103 B
build/block-library/blocks/preformatted/style.css 103 B
build/block-library/blocks/pullquote/editor-rtl.css 198 B
build/block-library/blocks/pullquote/editor.css 198 B
build/block-library/blocks/pullquote/style-rtl.css 378 B
build/block-library/blocks/pullquote/style.css 378 B
build/block-library/blocks/pullquote/theme-rtl.css 167 B
build/block-library/blocks/pullquote/theme.css 167 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B
build/block-library/blocks/query-pagination/editor-rtl.css 262 B
build/block-library/blocks/query-pagination/editor.css 255 B
build/block-library/blocks/query-pagination/style-rtl.css 234 B
build/block-library/blocks/query-pagination/style.css 231 B
build/block-library/blocks/query/editor-rtl.css 131 B
build/block-library/blocks/query/editor.css 132 B
build/block-library/blocks/quote/style-rtl.css 187 B
build/block-library/blocks/quote/style.css 187 B
build/block-library/blocks/quote/theme-rtl.css 223 B
build/block-library/blocks/quote/theme.css 226 B
build/block-library/blocks/rss/editor-rtl.css 202 B
build/block-library/blocks/rss/editor.css 204 B
build/block-library/blocks/rss/style-rtl.css 289 B
build/block-library/blocks/rss/style.css 288 B
build/block-library/blocks/search/editor-rtl.css 165 B
build/block-library/blocks/search/editor.css 165 B
build/block-library/blocks/search/style-rtl.css 397 B
build/block-library/blocks/search/style.css 398 B
build/block-library/blocks/search/theme-rtl.css 64 B
build/block-library/blocks/search/theme.css 64 B
build/block-library/blocks/separator/editor-rtl.css 99 B
build/block-library/blocks/separator/editor.css 99 B
build/block-library/blocks/separator/style-rtl.css 250 B
build/block-library/blocks/separator/style.css 250 B
build/block-library/blocks/separator/theme-rtl.css 172 B
build/block-library/blocks/separator/theme.css 172 B
build/block-library/blocks/shortcode/editor-rtl.css 474 B
build/block-library/blocks/shortcode/editor.css 474 B
build/block-library/blocks/site-logo/editor-rtl.css 770 B
build/block-library/blocks/site-logo/editor.css 770 B
build/block-library/blocks/site-logo/style-rtl.css 165 B
build/block-library/blocks/site-logo/style.css 165 B
build/block-library/blocks/site-tagline/editor-rtl.css 86 B
build/block-library/blocks/site-tagline/editor.css 86 B
build/block-library/blocks/site-title/editor-rtl.css 84 B
build/block-library/blocks/site-title/editor.css 84 B
build/block-library/blocks/social-link/editor-rtl.css 177 B
build/block-library/blocks/social-link/editor.css 177 B
build/block-library/blocks/social-links/editor-rtl.css 824 B
build/block-library/blocks/social-links/editor.css 823 B
build/block-library/blocks/social-links/style-rtl.css 1.32 kB
build/block-library/blocks/social-links/style.css 1.32 kB
build/block-library/blocks/spacer/editor-rtl.css 307 B
build/block-library/blocks/spacer/editor.css 307 B
build/block-library/blocks/spacer/style-rtl.css 48 B
build/block-library/blocks/spacer/style.css 48 B
build/block-library/blocks/table/editor-rtl.css 471 B
build/block-library/blocks/table/editor.css 472 B
build/block-library/blocks/table/style-rtl.css 481 B
build/block-library/blocks/table/style.css 481 B
build/block-library/blocks/table/theme-rtl.css 188 B
build/block-library/blocks/table/theme.css 188 B
build/block-library/blocks/tag-cloud/style-rtl.css 146 B
build/block-library/blocks/tag-cloud/style.css 146 B
build/block-library/blocks/template-part/editor-rtl.css 560 B
build/block-library/blocks/template-part/editor.css 559 B
build/block-library/blocks/template-part/theme-rtl.css 101 B
build/block-library/blocks/template-part/theme.css 101 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B
build/block-library/blocks/text-columns/editor.css 95 B
build/block-library/blocks/text-columns/style-rtl.css 166 B
build/block-library/blocks/text-columns/style.css 166 B
build/block-library/blocks/verse/style-rtl.css 87 B
build/block-library/blocks/verse/style.css 87 B
build/block-library/blocks/video/editor-rtl.css 571 B
build/block-library/blocks/video/editor.css 572 B
build/block-library/blocks/video/style-rtl.css 173 B
build/block-library/blocks/video/style.css 173 B
build/block-library/blocks/video/theme-rtl.css 124 B
build/block-library/blocks/video/theme.css 124 B
build/block-library/common-rtl.css 815 B
build/block-library/common.css 812 B
build/block-library/editor-rtl.css 9.78 kB
build/block-library/editor.css 9.78 kB
build/block-library/reset-rtl.css 474 B
build/block-library/reset.css 474 B
build/block-library/style-rtl.css 10.5 kB
build/block-library/style.css 10.6 kB
build/block-library/theme-rtl.css 668 B
build/block-library/theme.css 673 B
build/block-serialization-default-parser/index.min.js 1.09 kB
build/block-serialization-spec-parser/index.min.js 2.79 kB
build/blocks/index.min.js 46 kB
build/components/index.min.js 212 kB
build/components/style-rtl.css 15.4 kB
build/components/style.css 15.4 kB
build/compose/index.min.js 10.9 kB
build/core-data/index.min.js 12.6 kB
build/customize-widgets/index.min.js 11.2 kB
build/customize-widgets/style-rtl.css 1.5 kB
build/customize-widgets/style.css 1.49 kB
build/data-controls/index.min.js 614 B
build/data/index.min.js 7.1 kB
build/date/index.min.js 31.5 kB
build/deprecated/index.min.js 428 B
build/dom-ready/index.min.js 304 B
build/dom/index.min.js 4.44 kB
build/edit-navigation/index.min.js 15.8 kB
build/edit-navigation/style-rtl.css 3.76 kB
build/edit-navigation/style.css 3.76 kB
build/edit-post/classic-rtl.css 492 B
build/edit-post/classic.css 494 B
build/edit-post/index.min.js 29.4 kB
build/edit-post/style-rtl.css 7.12 kB
build/edit-post/style.css 7.12 kB
build/edit-site/index.min.js 30.7 kB
build/edit-site/style-rtl.css 5.79 kB
build/edit-site/style.css 5.79 kB
build/edit-widgets/index.min.js 16.3 kB
build/edit-widgets/style-rtl.css 4.17 kB
build/edit-widgets/style.css 4.18 kB
build/editor/index.min.js 37.8 kB
build/editor/style-rtl.css 3.78 kB
build/editor/style.css 3.77 kB
build/element/index.min.js 3.21 kB
build/escape-html/index.min.js 517 B
build/format-library/index.min.js 6.34 kB
build/format-library/style-rtl.css 571 B
build/format-library/style.css 571 B
build/hooks/index.min.js 1.55 kB
build/html-entities/index.min.js 424 B
build/i18n/index.min.js 3.6 kB
build/is-shallow-equal/index.min.js 501 B
build/keyboard-shortcuts/index.min.js 1.72 kB
build/keycodes/index.min.js 1.3 kB
build/list-reusable-blocks/index.min.js 1.85 kB
build/list-reusable-blocks/style-rtl.css 838 B
build/list-reusable-blocks/style.css 838 B
build/media-utils/index.min.js 2.92 kB
build/notices/index.min.js 845 B
build/nux/index.min.js 2.03 kB
build/nux/style-rtl.css 747 B
build/nux/style.css 743 B
build/plugins/index.min.js 1.83 kB
build/primitives/index.min.js 921 B
build/priority-queue/index.min.js 582 B
build/react-i18n/index.min.js 671 B
build/redux-routine/index.min.js 2.63 kB
build/reusable-blocks/index.min.js 2.19 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 10.7 kB
build/server-side-render/index.min.js 1.52 kB
build/shortcode/index.min.js 1.48 kB
build/token-list/index.min.js 562 B
build/url/index.min.js 1.74 kB
build/viewport/index.min.js 1.02 kB
build/warning/index.min.js 248 B
build/widgets/index.min.js 7.11 kB
build/widgets/style-rtl.css 1.16 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.04 kB

compressed-size-action

static $block_id = 0;
$block_id++;

$children_only = ( isset( $attributes['childrenOnly'] ) && $attributes['childrenOnly'] );
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mind also adding support for this option in the PageList -> NavigationLinks conversion? This was added in #30390

Copy link
Member Author

Choose a reason for hiding this comment

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

🤔 Looking at the convert to links, it is only allowed if the parent block is a navigation block - it took me a bit to figure this out because my test case is using the PageList in a widget in a sidebar, I didn't wrap it in a Navigation block.

Copy link
Member Author

Choose a reason for hiding this comment

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

The way the Site Editor work now, I don't think we can do this. When in the editor and you click convert to links it will not have the context of what page you are in - so it will hard code the links in the template, but we want it to use the parent of the page you are browsing.

I created a short video that hopefully explains (with audio)

gutenberg-pr31471.mp4

@gwwar
Copy link
Contributor

gwwar commented May 18, 2021

Oh gotcha, this is filtering relative to the current page 👍

So taking a step back a bit, my question then is PageList a good fit, or would we like to add this elsewhere? It could make sense to add this feature in the block, but we'd also need to test this nested in the navigation block, and in various editors (widget, navigation, site, post ). cc @tellthemachines @jasmussen @talldan @getdave

Would it more sense to extend capabilities in the Query component and loop to support this? I tested this out with the site editor and there are a few missing pieces to make this possible:

  • Add an advanced filter to filter by the children of the current page in Query component. (This might still need to use global $post)
  • Maybe a better loop component for these links. Internally these pieces have access to postIds in the loop with "usesContext": [ "postId" ].

See example in:

"usesContext": [ "postId", "postType" ],

Screen Shot 2021-05-18 at 12 13 19 PM

cc @ntsekouras

@jasmussen
Copy link
Contributor

I can't fully figure out why you'd show only subpages inside the navigation block. But I also can't rule out that you might want to do this in exotic situations, so I'm not fundamentally opposed. But I can't think up how to make an intuitive UI for it; what would happen with a page list inside a navigation block that sits in a header template part but is set to show only subpages? It would likely show nothing, right? For that reason it might be best to not show the option when inside the navigation block.

I want to also bring the attention briefly to #31879, and an adjacent conversation that spawned from the navigation overlay color property, on whether it might make sense to rewrite the Page List as a client block. I'm not making any value judgemnets on which approach is feasible or best here, I'll leave that to you — merely bring it up in case we're optimizing in either direction.

@talldan
Copy link
Contributor

talldan commented May 19, 2021

I created a couple of issues that I thought would be useful for filtering Page List as well (#29584, #31063). I agree it all seems a bit like the query block. A suggestion I had in the past was to look into using Query to implement Page List.

I want to also bring the attention briefly to #31879, and an adjacent conversation that spawned from the navigation overlay color property, on whether it might make sense to rewrite the Page List as a client block.

As in a static block? The array of blocks can change length, so I think it'd always need a dynamic wrapper block, but I guess the items could be static blocks?

@jasmussen
Copy link
Contributor

To my understanding: still a dynamic block as the point is to keep it in sync with new or deleted pages on the site. CC @georgeh as he had looked into it for the overlay color.

@ntsekouras
Copy link
Contributor

TBH I got a bit confused with the output in editor vs front-end in my testing, but I have also not experimented much with Navigation block and more 'complex' scenarios like lot's of parent/children relationships, deeply nested etc...

Having said that an alternative for sure could be extra controls in Query and maybe another one could be having a block variation for Page List to show just the children of current page?

@mkaz
Copy link
Member Author

mkaz commented May 19, 2021

TBH I got a bit confused with the output in editor vs front-end in my testing, but I have also not experimented much with Navigation block and more 'complex' scenarios like lot's of parent/children relationships, deeply nested etc...

Agree, I see this in the other template editing with dynamic content tii. I'm not sure if we have a way to set context for it or not.

Overall, I think people will want to use the child page feature to generate links, likewise for the additional filters that @talldan mentions in #29584 I'm not sure if it fits in Query Block or not, quite similar but my mindset was that I wanted a list of pages for navigation, so Page List was what first came to mind.

@mkaz
Copy link
Member Author

mkaz commented Sep 27, 2021

The video below shows some additional controls that will be required — not necessarily in the form you see, but stubbing them out to illustrate. The PageList block can be used in multiple contexts, for example in a Post, on a Page, or in a Widget area.

page-list-children-only2.mp4

The video above shows an example on a post so the context toggle is disabled by default, when inserted in a Page it could be toggled and disable the Page search control.

The goal of the "children only" toggle is to allow specifying a parent page, and then the Page List will only include the children of the page specified.

The context control is to show the children of the page being viewed without having to specify the page. This is looking forward to block themes that may want to create a single template for pages that show sub menus for children pages.

I welcome thoughts on this approach and suggestions on a UX for setting and explaining. Additionally, keeping in mind filters for categories and tags?

@jasmussen
Copy link
Contributor

Looks like it could work.

We need a better label than "Show only children". Nothing great comes to mind, perhaps "Limit to showing subpages"?

The second half, "Use current page as parent" is where much of the complexity comes in. Would it be at all possible to only surface the "show only child pages" of the current page, and then explore separately whether we need additional controls at all?

@mkaz
Copy link
Member Author

mkaz commented Sep 28, 2021

@jasmussen @gwwar I've updated the behavior and I think it is close to where we want it. We may want to edit the wording on the toggle and help, open to suggestions.

The video shows the Page List under three scenarios

  1. On a Post - the toggle does not show. 👍
  2. On a Page - the toggle shows, and updates the list based on child pages. What do we show when no child pages? ❓
  3. On a template - the toggle shows, but has no context on what to show in page ❓
page-list-post-page-template.mp4

I want to update the unit tests with these scenarios, but technically it should be ready for review?

@jasmussen
Copy link
Contributor

Nice. I think we can tweak the verbiage in the inspector a bit, and if feasible without too many big changes, can you make the controls a part of the main inspector card? I.e. no separator between description and content? Do this only if it doesn't require hacky CSS:
page list

@mkaz
Copy link
Member Author

mkaz commented Sep 29, 2021

1. About the underline in panel

If I remove the <PanelBody/> wrapper around the toggle it removes the line but I also lose all the padding. See:

image

2. About verbiage

I updated the text using your verbiage but keeping "child" instead of "sub". I like keeping it because Parent is the name used in the editor, in various functions (example), and in external documentation (one example)

@jasmussen
Copy link
Contributor

Cool, to keep things simple let's just keep the panelbody for now and the project will circle back as part of #27331.

@gwwar
Copy link
Contributor

gwwar commented Sep 29, 2021

This looks promising @mkaz I did find a few corner cases while manually testing:

  • Toggling List Child Pages when a page has no children will make the block unselectable (since it has no height).
CleanShot.2021-09-29.at.10.13.26.mp4
  • Convert logic in Navigation Block doesn't have awareness of this filtering:
CleanShot.2021-09-29.at.10.15.55.mp4

On a template - the toggle shows, but has no context on what to show in page ❓

Should we be able to see the option in a template? I didn't spot it while testing.

@mkaz
Copy link
Member Author

mkaz commented Oct 8, 2021

Fixed issue with empty block (no child pages) in #35441

Copy link
Contributor

@tellthemachines tellthemachines left a comment

Choose a reason for hiding this comment

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

Thanks for working on this! Testing the changes, there are a couple of unexpected things happening when "Limit to child pages" is set:

  • On top-level pages only children of the current page appear, but on child pages we can see both children and siblings, plus the siblings' whole descendant tree. This is confusing, especially because the description states "When enabled, the block lists only child pages of the current page."

  • Children are rendered as a flat list, even when there are multiple descendant levels. I'd expect hierarchy to be reflected in the list markup, as it is when Page List renders all pages.

@mkaz
Copy link
Member Author

mkaz commented Oct 11, 2021

Thanks @tellthemachines for reviewing, I'll look at further nesting of pages.

With regards to the first behavior, that is what is desired, so maybe needs better explanatory labels. The idea is to enable creating a menu based on the parent-child relationship, so an entire section can be browsed. For example, if you navigate into one of the children, you should be able to navigate to other siblings. This is particularly useful for documentation sites.

@mkaz
Copy link
Member Author

mkaz commented Oct 12, 2021

I fixed the nesting, so if there are "grand child" pages then they will show nested with the toggle flipped.

I'm open to suggestions on naming the toggle, maybe @jasmussen and "Limit to sub-pages" is more accurate since it's not just children. The description could be: "When enabled, the block will list the sub-pages of the top most parent" 🤷‍♂️

@tellthemachines
Copy link
Contributor

With regards to the first behavior, that is what is desired, so maybe needs better explanatory labels. The idea is to enable creating a menu based on the parent-child relationship, so an entire section can be browsed

It feels a bit random though, because siblings at any nesting level may or may not be part of a section. E.g. if I have:

  • top level
    • child 1
      • grandchild 1 1
      • grandchild 1 2
    • child 2
      • grandchild 2 1
      • grandchild 2 2

it's not clear that "child 1" tree is relevant when we're browsing "child 2"; that depends fully on how your site is structured.

We could make "also show sibling pages" an optional toggle when "show only child pages" is enabled. What feels odd is the unexplained discrepancy in behaviour between a top level and a child page. Hierarchies can have many levels, and the point at which it makes sense to show sibling pages will vary from site to site.

The description could be: "When enabled, the block will list the sub-pages of the top most parent"

This is not quite accurate either. In the example above, if I set a page list to only show child pages in "grandchild 1 1", it'll show only itself and "grandchild 1 2", not any of its ancestors.

@jasmussen
Copy link
Contributor

Good points all around. Just to zoom out a bit and ponder a different approach, could the toggle be inverted and say "Omit top level pages"? It would start off by default, and we'd need a good paragraph of helptext explaining the use case.

This is also a case where it's okay to be fairly verbose with the description. Site Logo already spends quite a few lines of text on its own:
Screenshot 2021-10-12 at 09 31 14

- Adds a showOnlyChildPages attribute to Edit
- Update render to use attribute and only pull in children
- Do not show on post pages which will not have a parent
- Allow showing on wp_template pages

Fixes #31063
The toggle was set to show explictly on certain posts types but it is
easier to hide on post types so it will show on others such was
templates, template parts, or menus.
Moves check for top level and child checks to its own function so it
came be a little more clear what it is doing and why.

When the only_child_pages flag is set, we need to treat direct
child pages to the parent as top level so they show. And treat grand
children pages as child pages so they nest.
@scruffian
Copy link
Contributor

This has now been achieved in #45861

@scruffian scruffian closed this Dec 6, 2022
@scruffian scruffian deleted the add/page-list-children branch December 6, 2022 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Page List Affects the Page List Block
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Page List: Add parent parameter to show all child pages of current page
7 participants