View Config: Serve supported action IDs from the REST controller#77343
Draft
View Config: Serve supported action IDs from the REST controller#77343
Conversation
Move the "which DataViews actions are supported" decision from the
client-side registerPostTypeSchema thunk to the PHP view config
controller. The server now returns an `actions` array of action ID
strings based on post type capabilities, supports, and theme context.
The client maps those IDs to their JS implementations via a static
ACTION_MAP, eliminating the need for the separate canUser('create')
round-trip that was previously required.
https://claude.ai/code/session_01NLwxkXNQswYm8n9ZpmkfmJ
|
Flaky tests detected in ac70034. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/24411148300
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #76544
Status
THIS IS AN EXPERIMENT NOT READY TO REVIEW/LAND.
What?
Move the "which DataViews actions are supported" decision from the client-side
registerPostTypeSchemathunk to the PHP view config REST controller.Why?
Currently,
registerPostTypeSchemamakes 3 separate asyncresolveSelectcalls (getPostType,canUser('create'),getCurrentTheme) to derive the list of supported actions — information the server already has access to. This duplicates server-side knowledge in the client and adds unnecessary round-trips. By having the server return the action list, the client becomes a simple consumer that maps IDs to implementations.This also opens up PHP extensibility: plugins can now filter the action list via
apply_filters( 'gutenberg_view_config_actions', ... )without requiring JS.How?
PHP controller (
class-gutenberg-rest-view-config-controller-7-1.php):get_actions( $kind, $name )method returns an array of action ID strings based on post type capabilities, supports, slug, and theme context.get_items()response now includes anactionskey, wrapped inapply_filtersfor extensibility.actionsproperty (array of strings, readonly).Client-side (
packages/editor/src/dataviews/store/private-actions.ts):ACTION_MAPconstant maps 13 action IDs (e.g.'view-post','duplicate-post','move-to-trash') to their JS implementations.registerPostTypeSchemanow fetchesviewConfig.actionsfrom the server and maps IDs to implementations, replacing the ~50-line conditional action-building block.canUser('create')async call is removed (no longer needed for action resolution).IS_GUTENBERG_PLUGINand__experimentalTemplateActivateclient-side gates forduplicate-postare preserved.Supporting changes:
core-dataselector default updated to includeactions: undefined.useViewConfigreturn type updated to includeactions: string[] | undefined.Testing Instructions
npm run wp-env start)./wp/v2/view-config?kind=postType&name=pageincludes anactionsarray with the expected IDs.create_postscapability — duplication actions should not appear.Testing Instructions for Keyboard
Screenshots or screencast
N/A — no visual changes; this is a data-flow refactor.
Use of AI Tools
This PR was authored with the assistance of Claude Code (claude-opus-4-6). All changes were reviewed for correctness.