Site Editor > Pages: move view config to the server#76573
Site Editor > Pages: move view config to the server#76573
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. |
| // TODO: this data will come from a registry of view configs per entity. | ||
| $default_view = array( | ||
| 'type' => 'table', | ||
| 'filters' => array(), | ||
| 'perPage' => 20, | ||
| 'sort' => array( | ||
| 'field' => 'title', | ||
| 'direction' => 'asc', | ||
| ), | ||
| 'titleField' => 'title', | ||
| 'fields' => array( 'author', 'status' ), | ||
| ); | ||
| $default_layouts = array( | ||
| 'table' => array(), | ||
| 'grid' => array(), | ||
| 'list' => array(), | ||
| ); | ||
| $all_items_title = __( 'All items', 'gutenberg' ); | ||
| if ( 'postType' === $kind ) { | ||
| $post_type_object = get_post_type_object( $name ); | ||
| if ( $post_type_object && ! empty( $post_type_object->labels->all_items ) ) { | ||
| $all_items_title = $post_type_object->labels->all_items; | ||
| } | ||
| } | ||
| $view_list = array( | ||
| array( | ||
| 'title' => $all_items_title, | ||
| 'slug' => 'all', | ||
| ), | ||
| ); | ||
| if ( 'postType' === $kind && 'page' === $name ) { | ||
| $default_view = array( | ||
| 'type' => 'list', | ||
| 'filters' => array(), | ||
| 'perPage' => 20, | ||
| 'sort' => array( | ||
| 'field' => 'title', | ||
| 'direction' => 'asc', | ||
| ), | ||
| 'showLevels' => true, | ||
| 'titleField' => 'title', | ||
| 'mediaField' => 'featured_media', | ||
| 'fields' => array( 'author', 'status' ), | ||
| ); | ||
| $default_layouts = array( | ||
| 'table' => array( | ||
| 'layout' => array( | ||
| 'styles' => array( | ||
| 'author' => array( | ||
| 'align' => 'start', | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| 'grid' => array(), | ||
| 'list' => array(), | ||
| ); | ||
| $view_list = array( | ||
| array( | ||
| 'title' => $all_items_title, | ||
| 'slug' => 'all', | ||
| ), | ||
| array( | ||
| 'title' => __( 'Published', 'gutenberg' ), | ||
| 'slug' => 'published', | ||
| 'view' => array( | ||
| 'filters' => array( | ||
| array( | ||
| 'field' => 'status', | ||
| 'operator' => 'isAny', | ||
| 'value' => 'publish', | ||
| 'isLocked' => true, | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| array( | ||
| 'title' => __( 'Scheduled', 'gutenberg' ), | ||
| 'slug' => 'future', | ||
| 'view' => array( | ||
| 'filters' => array( | ||
| array( | ||
| 'field' => 'status', | ||
| 'operator' => 'isAny', | ||
| 'value' => 'future', | ||
| 'isLocked' => true, | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| array( | ||
| 'title' => __( 'Drafts', 'gutenberg' ), | ||
| 'slug' => 'drafts', | ||
| 'view' => array( | ||
| 'filters' => array( | ||
| array( | ||
| 'field' => 'status', | ||
| 'operator' => 'isAny', | ||
| 'value' => 'draft', | ||
| 'isLocked' => true, | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| array( | ||
| 'title' => __( 'Pending', 'gutenberg' ), | ||
| 'slug' => 'pending', | ||
| 'view' => array( | ||
| 'filters' => array( | ||
| array( | ||
| 'field' => 'status', | ||
| 'operator' => 'isAny', | ||
| 'value' => 'pending', | ||
| 'isLocked' => true, | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| array( | ||
| 'title' => __( 'Private', 'gutenberg' ), | ||
| 'slug' => 'private', | ||
| 'view' => array( | ||
| 'filters' => array( | ||
| array( | ||
| 'field' => 'status', | ||
| 'operator' => 'isAny', | ||
| 'value' => 'private', | ||
| 'isLocked' => true, | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| array( | ||
| 'title' => __( 'Trash', 'gutenberg' ), | ||
| 'slug' => 'trash', | ||
| 'view' => array( | ||
| 'type' => 'table', | ||
| 'layout' => isset( $default_layouts['table']['layout'] ) ? $default_layouts['table']['layout'] : array(), | ||
| 'filters' => array( | ||
| array( | ||
| 'field' => 'status', | ||
| 'operator' => 'isAny', | ||
| 'value' => 'trash', | ||
| 'isLocked' => true, | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
| } |
There was a problem hiding this comment.
All this data will come from elsewhere. I want to ship things iteratively to maintain a steady velocity and don't overwhelm reviewers. This follow-up will be tracked at #76544
| key={ view.slug } | ||
| slug={ view.slug } | ||
| title={ view.title } | ||
| icon={ SLUG_TO_ICON[ view.slug ] } |
There was a problem hiding this comment.
The icon is not part of the view-config endpoint because I don't know that we'll need it: 1) there's a experiment (Gutenberg > Experiments > Site Editor extensibility) to update how the site editor looks that doesn't use icons, 2) if we wanted them for any entity, we'll need to figure it out how to use/register them from the server.
I'll get this listed at #76544 so it's tracked.
|
Size Change: +83 B (0%) Total Size: 8.75 MB
ℹ️ View Unchanged
|
71f3119 to
558598d
Compare
|
Flaky tests detected in 8fbafdd. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/23194907010
|
Part of #76544
What?
Move view configuration (
defaultView,defaultLayouts, andviewList) for the Site Editor > Pages screen to a server-side REST API endpoint, replacing client-side definitions.There should be no visual changes.
Why?
See #76544
How?
Server side:
Gutenberg_REST_View_Config_Controller_7_1REST controller underlib/compat/wordpress-7.1/that serves view configuration per entity type via GET/wp/v2/view-config?kind=<kind>&name=<name>.default_view,default_layouts, andview_list.@wordpress/core-data:viewConfigsreducer,receiveViewConfigaction,getEntityViewConfigprivate selector, and resolver that fetches from the new endpoint.@wordpress/views:useViewConfighook that returns the view config (prefered to using the core-data private selector).@wordpress/edit-site:post-list/index.js: UseuseViewConfighook instead of importing fromview-utils.js.sidebar-dataviews/index.js: UseuseViewConfighook instead of importing fromview-utils.js.site-editor-routes/pages.js: Read view config directly from the store instead of importing fromview-utils.js.post-list/view-utils.jsentirely — all its exports are now served by the REST API.Testing Instructions
Use of AI Tools
Claude Code (claude-opus-4-6) was used for code generation and refactoring assistance throughout this PR.