Skip to content

DataViews: add per-level hierarchy pagination - #83320

Open
dinhtungdu wants to merge 1 commit into
fix/80360-controlled-expansionfrom
fix/80360-hierarchy-pagination
Open

dinhtungdu wants to merge 1 commit into
fix/80360-controlled-expansionfrom
fix/80360-hierarchy-pagination

Conversation

@dinhtungdu

@dinhtungdu dinhtungdu commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

What?

Part of #80360. Stacked on #83316.

Lets a hierarchical DataViews table load each level in batches, with Load more buttons.

Why?

A parent can have hundreds of children, and a site can have thousands of top-level pages. DataViews cannot load all of them at once. Page numbers do not work in a tree either, because each parent's children are their own list. So each level needs its own way to load more.

How?

  • The new hierarchyPagination prop has two functions. getPaginationInfo( parentId ) tells DataViews whether a level has more items, and onLoadMore( parentId ) asks the consumer for the next batch. parentId is null for the top level. The consumer fetches and passes every loaded item in data.
  • After the last loaded child of a parent, a row shows Show N more, or Load more when the count is not known. It shows a loading state, and an error with Retry.
  • It applies while view.infiniteScrollEnabled is off. With infinite scroll on, the table keeps loading as one flat list, as it does today. Infinite scroll per level can come later.
  • The table stays usable while a level loads, even when the consumer passes isLoading, so focus is not lost.

Testing Instructions

  1. Run npm run test:unit:vitest -- packages/dataviews.
  2. In Storybook, open DataViews → Hierarchical Levels. Sun shows 4 children, then Show 8 more. The last row is Show 1 more, for the top level.
  3. Click Show 8 more. It reads Loading…, then 4 more children appear and the button reads Show 4 more.
  4. Expand Jupiter, then click Show 2 more under its children. The load fails on purpose, and an error and Retry appear. Click Retry. The last 2 children load.
  5. Turn off the showLevels control. The flat table comes back, with no Load more rows, and View options shows Items per page again.

Testing Instructions for Keyboard

  1. Tab to Show 8 more and press Enter until the button goes away. While more children remain, focus stays on the button. After the last batch, focus moves to the first new child.

Screenshots or screencast

Captured before the rebase, in compact density. The Show 4 more row for Sun indents with its children and comes before the next top-level item.

Compact hierarchical table showing Show 4 more beneath Sun's children and before the next sibling

Use of AI Tools

OpenAI Codex through Pi drafted the first implementation and tests. Amp reviewed and simplified the stack, rebased it on trunk, and checked it in a browser.

@dinhtungdu
dinhtungdu added this pull request to stack #83317 September 22, 2026 05:41
@github-actions github-actions Bot added the [Package] DataViews /packages/dataviews label Sep 22, 2026
@dinhtungdu dinhtungdu changed the title feat: support per-level DataViews pagination DataViews: add per-level hierarchy pagination Sep 22, 2026
@dinhtungdu dinhtungdu added the [Type] New API New API to be used by plugin developers or package users. label Sep 22, 2026
@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

🎉 Props

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @ampagent.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: ampagent.

Co-authored-by: dinhtungdu <dinhtungdu@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: +6.16 kB (+0.07%)

Total Size: 8.72 MB

📦 View Changed
Filename Size Change
build/scripts/block-editor/index.min.js 560 kB +1.09 kB (+0.19%)
build/scripts/edit-site/index.min.js 386 kB +1.3 kB (+0.34%)
build/scripts/editor/index.min.js 576 kB +1.01 kB (+0.17%)
build/scripts/media-utils/index.min.js 240 kB +959 B (+0.4%)
build/styles/edit-site/style-rtl.css 21.6 kB +190 B (+0.89%)
build/styles/edit-site/style-rtl.min.css 17.6 kB +262 B (+1.51%)
build/styles/edit-site/style.css 21.6 kB +192 B (+0.9%)
build/styles/edit-site/style.min.css 17.6 kB +261 B (+1.5%)
build/styles/editor/style-rtl.css 32.5 kB +190 B (+0.59%)
build/styles/editor/style-rtl.min.css 28.3 kB +261 B (+0.93%)
build/styles/editor/style.css 32.6 kB +190 B (+0.59%)
build/styles/editor/style.min.css 28.2 kB +261 B (+0.93%)

c26d419 Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

should select synced pattern in /test/e2e/specs/editor/various/writing-flow.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator:  locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]')
Expected: focused
Received: inactive
Timeout:  5000ms

Call log:
  - Expect "toBeFocused" locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]') with timeout 5000ms
  - waiting for locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]')
    14 × locator resolved to <div tabindex="0" role="document" draggable="true" data-title="Pattern" data-type="core/block" data-is-drop-zone="true" aria-label="Block: Pattern" id="block-042b28a2-f948-4f48-bce2-4e4654449a35" data-block="042b28a2-f948-4f48-bce2-4e4654449a35" class="block-editor-block-list__block wp-block is-selected is-reusable block-library-block__reusable-block-container wp-block-block block-editor-block-list__layout">…</div>
       - unexpected value "inactive"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/writing-flow.spec.js:1464:5
should undo without broken temporary state in /test/e2e/specs/editor/blocks/image.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 2
+ Received  + 2

- <!-- wp:image -->
- <figure class="wp-block-image"><img alt=""/></figure>
+ <!-- wp:image {"id":21,"sizeSlug":"full","linkDestination":"none"} -->
+ <figure class="wp-block-image size-full"><img src="http://localhost:8889/wp-content/uploads/2026/11/322980e1-1095-4654-b76e-ea940eb8748c.png" alt="" class="wp-image-21"/></figure>
  <!-- /wp:image -->
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/image.spec.js:432:49

c26d419 Run

@dinhtungdu
dinhtungdu removed this pull request from stack #83317 October 6, 2026 12:26
@dinhtungdu
dinhtungdu added this pull request to stack #84117 October 6, 2026 12:27
@dinhtungdu
dinhtungdu force-pushed the fix/80360-hierarchy-pagination branch from b6bd5de to dbb968e Compare October 12, 2026 03:42
@dinhtungdu
dinhtungdu removed this pull request from stack #84117 October 12, 2026 14:21
@dinhtungdu
dinhtungdu added this pull request to stack #84566 October 12, 2026 14:21
@dinhtungdu
dinhtungdu force-pushed the fix/80360-hierarchy-pagination branch from dbb968e to bf835c8 Compare October 15, 2026 08:12
@dinhtungdu
dinhtungdu force-pushed the fix/80360-hierarchy-pagination branch from fdb9c1f to 1d0294a Compare November 19, 2026 05:56
@dinhtungdu
dinhtungdu force-pushed the fix/80360-hierarchy-pagination branch from 1d0294a to 4575fa2 Compare November 19, 2026 09:32
@dinhtungdu
dinhtungdu force-pushed the fix/80360-hierarchy-pagination branch 2 times, most recently from fa584f3 to 10efb68 Compare November 19, 2026 16:58
@dinhtungdu
dinhtungdu force-pushed the fix/80360-hierarchy-pagination branch 4 times, most recently from dfb4a65 to 0033493 Compare November 23, 2026 10:30
@dinhtungdu
dinhtungdu force-pushed the fix/80360-hierarchy-pagination branch 2 times, most recently from 8ef382a to 5cb0af3 Compare November 23, 2026 13:19
A hierarchical table can now load each level in batches with the new
hierarchyPagination prop. getPaginationInfo( parentId ) says whether a
level has more, how many remain, and whether it is loading or failed.
onLoadMore( parentId ) asks the consumer for the next batch.

Each level ends with a Load more row, or "Show N more" when the count
is known. After an error, the row shows Retry.

It applies while view.infiniteScrollEnabled is off. Then page numbers
and the items-per-page control are hidden, and the table stays usable
while a level loads, so focus moves to the first new row. The saved
view does not change.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1a42f-8223-7623-a09b-7f8342758e3e
@dinhtungdu
dinhtungdu force-pushed the fix/80360-hierarchy-pagination branch from 5cb0af3 to c26d419 Compare November 24, 2026 03:57
@dinhtungdu
dinhtungdu marked this pull request as ready for review November 24, 2026 04:21

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] DataViews /packages/dataviews [Type] New API New API to be used by plugin developers or package users.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant