DataViews: simplify defaultLayouts prop#77232
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
883daa3 to
4784831
Compare
There was a problem hiding this comment.
Pull request overview
This PR improves the defaultLayouts API for DataViews and DataViewsPicker by making it optional with sensible defaults, adding true as a shorthand to enable a layout, and normalizing true → {} at key entry points so downstream code only deals with objects.
Changes:
- Updated
SupportedLayoutsto allowtrueper layout key and addedNormalizedSupportedLayoutsfor object-only downstream usage. - Made
defaultLayoutsoptional inDataViews/DataViewsPicker, added internal defaults, and normalizedtrue→{}. - Updated internal consumers/stories/tests to drop redundant defaults and use the
trueshorthand where no config is needed.
Reviewed changes
Copilot reviewed 32 out of 32 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| routes/template-part-list/view-utils.ts | Removes redundant DEFAULT_LAYOUTS constant now that DataViews provides defaults. |
| routes/template-part-list/stage.tsx | Stops passing defaultLayouts explicitly (relies on DataViews defaults). |
| routes/post-list/view-utils.ts | Switches some layouts to true shorthand in exported defaults. |
| routes/pattern-list/view-utils.ts | Uses true shorthand for table layout in exported defaults. |
| routes/navigation-list/stage.tsx | Uses true shorthand for list layout. |
| routes/content-guidelines/components/revision-history.tsx | Uses true shorthand for table layout. |
| routes/content-guidelines/components/block-guidelines.tsx | Uses true shorthand for list layout. |
| packages/views/src/use-view.ts | Normalizes true/missing layout defaults to {} when merging overrides. |
| packages/views/src/load-view.ts | Normalizes true/missing layout defaults to {} in loader path. |
| packages/media-fields/src/stories/index.story.tsx | Removes redundant defaultLayouts prop usage (relies on defaults). |
| packages/fields/src/stories/index.story.tsx | Removes redundant defaultLayouts prop usage (relies on defaults). |
| packages/editor/src/components/post-revisions-panel/index.js | Uses true shorthand for activity layout. |
| packages/edit-site/src/components/post-list/index.js | Removes ?? {} fallback when passing defaultLayouts. |
| packages/edit-site/src/components/page-templates/index-legacy.js | Removes ?? {} fallback when passing defaultLayouts. |
| packages/edit-site/src/components/page-patterns/index.js | Removes ?? {} fallback when passing defaultLayouts. |
| packages/dataviews/src/types/dataviews.ts | Adds true shorthand support + introduces NormalizedSupportedLayouts. |
| packages/dataviews/src/field-types/stories/index.story.tsx | Uses true shorthand for table layout. |
| packages/dataviews/src/dataviews/test/dataviews.tsx | Updates tests to use SupportedLayouts + true shorthand. |
| packages/dataviews/src/dataviews/stories/with-card.tsx | Uses true shorthand for enabling layouts. |
| packages/dataviews/src/dataviews/stories/minimal-ui.tsx | Uses true shorthand for enabling a chosen layout. |
| packages/dataviews/src/dataviews/stories/layout-table.tsx | Uses true shorthand for table-only story. |
| packages/dataviews/src/dataviews/stories/layout-list.tsx | Uses true shorthand for list-only story. |
| packages/dataviews/src/dataviews/stories/layout-grid.tsx | Uses true shorthand for grid-only story. |
| packages/dataviews/src/dataviews/stories/layout-custom.tsx | Uses true shorthand for table layout. |
| packages/dataviews/src/dataviews/stories/infinite-scroll.tsx | Uses true shorthand for enabling layouts. |
| packages/dataviews/src/dataviews/stories/free-composition.tsx | Uses true shorthand for enabling layouts. |
| packages/dataviews/src/dataviews/stories/empty.tsx | Uses true shorthand for enabling layouts. |
| packages/dataviews/src/dataviews/index.tsx | Makes defaultLayouts optional; adds defaults; filters + normalizes true → {}. |
| packages/dataviews/src/dataviews-picker/test/dataviews-picker.tsx | Updates picker tests to use true shorthand. |
| packages/dataviews/src/dataviews-picker/stories/index.story.tsx | Removes redundant defaultLayouts prop usage (relies on picker defaults). |
| packages/dataviews/src/dataviews-picker/index.tsx | Makes defaultLayouts optional; adds picker defaults; filters + normalizes true → {}. |
| packages/dataviews/src/components/dataviews-context/index.ts | Switches context type to NormalizedSupportedLayouts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
defaultLayouts prop
|
Size Change: +190 B (0%) Total Size: 7.74 MB 📦 View Changed
ℹ️ View Unchanged
|
|
Flaky tests detected in 2a069e0. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/24334564809
|
What?
Improves the
defaultLayoutsprop onDataViewsandDataViewsPicker:table/grid/listforDataViews;pickerGrid/pickerTableforDataViewsPicker).trueas a shorthand to enable a layout without providing configuration.Why?
To improve developer experience with the current API:
{ table: {}, grid: {}, list: {} }.{ table: {} }obscures the intent ("just enable this layout").How?
Type layer:
SupportedLayoutsnow accepts| truefor each layout key.NormalizedSupportedLayoutstype (objects only, notrue) is used for the context and all downstream consumers.Component layer:
DataViewsandDataViewsPickeraccept an optionaldefaultLayoutswith built-in defaults.true→{}, so every internarl component (ViewTypeMenu,DataViewsLayout, etc.) only sees plain objects.@wordpress/viewspackage:useViewandloadVieware independent entry points that receive rawSupportedLayouts, so they normalizetrueat their own point of use.Consumer cleanup:
?? {}fallbacks in edit-site consumers (post-list, page-patterns, page-templates).defaultLayoutsprops where the new defaults are sufficient (fields/media-fields stories, template-part-list, picker stories).trueinstead of{}where no config is needed.Testing Instructions
trueshorthand render and switch layouts correctly.defaultLayoutsentirely (e.g. fields, media-fields previews) render with default layouts.Use of AI Tools
This PR was authored with assistance from Claude Code (Claude Opus 4.6). All changes were reviewed and validated by the author.