Skip to content

View Config: Serve supported action IDs from the REST controller#77343

Draft
oandregal wants to merge 2 commits intotrunkfrom
claude/summarize-view-config-YWckJ
Draft

View Config: Serve supported action IDs from the REST controller#77343
oandregal wants to merge 2 commits intotrunkfrom
claude/summarize-view-config-YWckJ

Conversation

@oandregal
Copy link
Copy Markdown
Member

@oandregal oandregal commented Apr 14, 2026

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 registerPostTypeSchema thunk to the PHP view config REST controller.

Why?

Currently, registerPostTypeSchema makes 3 separate async resolveSelect calls (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):

  • New get_actions( $kind, $name ) method returns an array of action ID strings based on post type capabilities, supports, slug, and theme context.
  • The get_items() response now includes an actions key, wrapped in apply_filters for extensibility.
  • Schema updated with the actions property (array of strings, readonly).

Client-side (packages/editor/src/dataviews/store/private-actions.ts):

  • New ACTION_MAP constant maps 13 action IDs (e.g. 'view-post', 'duplicate-post', 'move-to-trash') to their JS implementations.
  • registerPostTypeSchema now fetches viewConfig.actions from the server and maps IDs to implementations, replacing the ~50-line conditional action-building block.
  • The canUser('create') async call is removed (no longer needed for action resolution).
  • IS_GUTENBERG_PLUGIN and __experimentalTemplateActivate client-side gates for duplicate-post are preserved.
  • Fields logic is unchanged.

Supporting changes:

  • core-data selector default updated to include actions: undefined.
  • useViewConfig return type updated to include actions: string[] | undefined.

Testing Instructions

  1. Start wp-env (npm run wp-env start).
  2. Navigate to the Site Editor → Pages list.
  3. Verify all context menu actions appear (View, Rename, Duplicate, Move to Trash, etc.).
  4. Check other DataViews screens: Posts, Patterns (wp_block), Template Parts, Templates.
  5. Verify that the REST response at /wp/v2/view-config?kind=postType&name=page includes an actions array with the expected IDs.
  6. Test with a user without create_posts capability — duplication actions should not appear.

Testing Instructions for Keyboard

  1. Navigate to Pages list using keyboard.
  2. Tab to a page row and use the actions menu (three-dot button or keyboard shortcut).
  3. Verify all expected actions are present and navigable via arrow keys.

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.

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
@github-actions github-actions Bot added [Package] Core data /packages/core-data [Package] Editor /packages/editor labels Apr 14, 2026
@oandregal oandregal added [Status] In Progress Tracking issues with work in progress [Type] Experimental Experimental feature or API. labels Apr 14, 2026
@github-actions
Copy link
Copy Markdown

Flaky tests detected in ac70034.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/24411148300
📝 Reported issues:

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

Labels

[Package] Core data /packages/core-data [Package] Editor /packages/editor [Status] In Progress Tracking issues with work in progress [Type] Experimental Experimental feature or API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants