Skip to content

DataViews: Add parent relationship support - #83241

Closed
dinhtungdu wants to merge 8 commits into
WordPress:trunkfrom
dinhtungdu:fix/80360
Closed

dinhtungdu wants to merge 8 commits into
WordPress:trunkfrom
dinhtungdu:fix/80360

Conversation

@dinhtungdu

@dinhtungdu dinhtungdu commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

What?

Part of #80360.

Adds an optional getItemParentId callback to DataViews. When table levels are enabled, loaded items are ordered from their parent relationships and their indentation depth is calculated automatically.

Why?

getItemLevel can indent rows but cannot describe relationships between items. DataViews needs a generic parent contract before later changes can add expansion, lazy loading, and branch pagination.

How?

  • Builds a depth-first view of the currently loaded items while preserving sibling order.
  • Treats missing parents, self-parenting items, and cycles safely so no loaded item disappears.
  • Keeps getItemLevel as the fallback when no parent callback is provided and for grouped views.
  • Updates the hierarchy story and API documentation.

This PR does not add parent-based hierarchy to grouped views, expansion, fetching, persistence, or pagination.

Testing Instructions

Run:

npm run --workspace @wordpress/unit-tests test:unit:vitest -- packages/dataviews/src/components/dataviews-layouts/table/test/get-hierarchical-rows.ts packages/dataviews/src/dataviews/test/dataviews.jsdom.test.tsx --testNamePattern="getHierarchicalRows|parent ids|getItemLevel indentation"
npm exec --no -- tsc -p packages/dataviews/tsconfig.build.json --noEmit
npm exec --no -- tsc -p packages/dataviews/tsconfig.json --noEmit

In Storybook, open DataViews → Hierarchical Levels:

  1. Confirm children render directly below their loaded parent and are indented by depth.
  2. Disable showLevels and confirm items return to the normal sorted order.

Testing Instructions for Keyboard

No interactive behavior changed.

Screenshots or screencast

Not applicable; this changes row ordering and existing indentation behavior.

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 github-actions Bot added the [Package] DataViews /packages/dataviews label Sep 21, 2026
@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.

@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 #83315, 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