Skip to content

DataViews: add controlled hierarchy expansion - #83311

Closed
dinhtungdu wants to merge 12 commits into
WordPress:trunkfrom
dinhtungdu:fix/80360-controlled-expansion
Closed

dinhtungdu wants to merge 12 commits into
WordPress:trunkfrom
dinhtungdu:fix/80360-controlled-expansion

Conversation

@dinhtungdu

@dinhtungdu dinhtungdu commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

What?

Part of #80360. Stacked on #83241.

Adds controlled expand/collapse controls to ungrouped hierarchical DataViews tables.

Why?

Consumers need to own expansion state so it can coordinate with lazy loading without persisting item IDs in view.

How?

  • Adds getItemHasChildren, expandedItemIds, and onChangeExpandedItemIds props.
  • Treats undefined child state as expandable so consumers can discover children lazily.
  • Hides loaded descendants of collapsed items.
  • Adds row and table-header disclosure controls.
  • Keeps grouped tables and the existing indented hierarchy unchanged.

Fetching, loading states, errors, and per-parent “load more” controls remain out of scope.

Testing Instructions

Run:

npm run --workspace @wordpress/unit-tests test:unit:vitest -- packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx packages/dataviews/src/components/dataviews-layouts/table/test/get-hierarchical-rows.ts
npm exec --no -- tsc -p packages/dataviews/tsconfig.build.json --noEmit
npm exec --no -- tsc -p packages/dataviews/tsconfig.json --noEmit
npm run lint:js -- packages/dataviews/src/types/dataviews.ts packages/dataviews/src/dataviews/index.tsx packages/dataviews/src/components/dataviews-context/index.ts packages/dataviews/src/components/dataviews-layout/index.tsx packages/dataviews/src/components/dataviews-layouts/table/index.tsx packages/dataviews/src/dataviews/stories/hierarchical-levels.tsx packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx
npm run lint:css -- packages/dataviews/src/components/dataviews-layouts/table/style.scss

In Storybook, open DataViews → Hierarchical Levels:

  1. Expand and collapse individual rows.
  2. Use the header disclosure to expand and collapse all loaded parent rows.
  3. Confirm nested rows remain ordered and indented.
  4. Disable showLevels and confirm the ordinary table returns.

Testing Instructions for Keyboard

  1. Tab to a row disclosure.
  2. Press Enter or Space and confirm its loaded descendants appear or disappear.
  3. Tab to the header disclosure and confirm Enter or Space expands or collapses all loaded parent rows.

Screenshots or screencast

A hierarchical DataViews table with Sun and Earth expanded

Use of AI Tools

OpenAI Codex through Pi was used to investigate the existing code, draft the implementation and tests, and run verification. The author remains responsible for the changes.

@github-actions

Copy link
Copy Markdown

🤖 PR meta 🤖

🏷️ Labels

This pull request needs exactly one label indicating its type, and has 0.

  • Required: any label starting with [Type].
  • Found: none.

Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you.

@github-actions github-actions Bot added the [Package] DataViews /packages/dataviews label Sep 22, 2026
@dinhtungdu
dinhtungdu force-pushed the fix/80360-controlled-expansion branch from d1684b5 to 2337baf Compare September 22, 2026 03:52
@dinhtungdu
dinhtungdu force-pushed the fix/80360-controlled-expansion branch from cbb6dc5 to c163fbf Compare September 22, 2026 04:13
@dinhtungdu

Copy link
Copy Markdown
Member Author

Recreating this draft from an upstream branch so GitHub can link it as a native stacked PR.

@dinhtungdu dinhtungdu closed this Sep 22, 2026
@dinhtungdu

Copy link
Copy Markdown
Member Author

Replaced by #83316, which uses GitHub’s native stacked PR support.

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

Labels

[Package] DataViews /packages/dataviews

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant