Skip to content

Premium Analytics: trim dashboard sections API to the server contract#50661

Open
louwie17 wants to merge 1 commit into
trunkfrom
update/premium-analytics-sections-server-contract
Open

Premium Analytics: trim dashboard sections API to the server contract#50661
louwie17 wants to merge 1 commit into
trunkfrom
update/premium-analytics-sections-server-contract

Conversation

@louwie17

@louwie17 louwie17 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #

Proposed changes

First of two PRs wiring the dashboard tab bar to the server-side section registry (see the linked plan discussion). This one lands the server contract only — there is no live JS consumer of these routes yet, so it is safe to reshape them. A follow-up PR will make the frontend consume GET /sections.

  • Add a slug to Dashboard_Section, derived from the section ID segment after the namespace (analytics/traffictraffic, woocommerce/storestore), and expose it in the REST representation. The frontend will use the slug for ?section= URLs and preference keys, so existing bookmarks and stored layouts keep working with zero migration.
  • Trim GET /wpcom/v2/dashboards/{name}/sections to return section definitions only — { id, slug, label, order } per section. The resolved layout and hasCustomLayout fields are gone: layout persistence stays entirely on core @wordpress/preferences (dashboardSectionLayouts key), which already covers reads and writes.
  • Retire the unused section-layout write surface and the per-user helpers that only served it:
    • PUT /dashboards/{name}/sections/{ns}/{slug}/layout
    • DELETE /dashboards/{name}/sections/{ns}/{slug}/layout
    • DELETE /dashboards/{name}/sections (reset-all)
    • get_dashboard_section_layouts_for_user(), update/delete_dashboard_section_layout_for_user(), delete_dashboard_section_layouts_for_user(), get_stored_persisted_preferences_for_user(), and the section-layout validators.
  • Keep GET /sections and GET .../default-layout (the reset path) unchanged, along with the inject-on-read default seeding in dashboard-layout.php.
  • Relabel the woocommerce/store section from "WooCommerce" to "Store", matching the label the static frontend tab uses today, so switching to server-driven labels causes no visible change.

Related product discussion/links

Does this pull request change what data or activity we track or use?

No.

Testing instructions

  • cd projects/packages/premium-analytics && composer phpunit — the suite covers the new slug field, the lean GET /sections response shape, WooCommerce availability filtering via the jetpack_premium_analytics_woocommerce_dashboard_section_available filter, the retired routes returning 404 rest_no_route, ordering, and the manage_options permission check.

In the browser with wp.apiFetch

On a Jetpack-connected test site with this branch built, log in as an admin, open the Premium Analytics dashboard (or the block editor — any admin screen that loads wp-api-fetch), and run in the browser console:

  1. The sections read returns definitions only:
    await wp.apiFetch( { path: '/wpcom/v2/dashboards/jetpack-premium-analytics_dashboard/sections' } );
    Expect an ordered array of { id, slug, label, order } objects only — no layout or hasCustomLayout keys. With WooCommerce active it ends with { id: 'woocommerce/store', slug: 'store', label: 'Store', order: 40 }; with WooCommerce deactivated that entry disappears.
  2. The default-layout read (reset path) still works:
    await wp.apiFetch( { path: '/wpcom/v2/dashboards/jetpack-premium-analytics_dashboard/sections/analytics/traffic/default-layout' } );
    Expect an array of widget instances.
  3. The retired write routes are gone — each of these must reject with rest_no_route (404):
    await wp.apiFetch( { path: '/wpcom/v2/dashboards/jetpack-premium-analytics_dashboard/sections/analytics/traffic/layout', method: 'PUT', data: { layout: [] } } );
    await wp.apiFetch( { path: '/wpcom/v2/dashboards/jetpack-premium-analytics_dashboard/sections/analytics/traffic/layout', method: 'DELETE' } );
    await wp.apiFetch( { path: '/wpcom/v2/dashboards/jetpack-premium-analytics_dashboard/sections', method: 'DELETE' } );

No user-facing change

The dashboard UI is unaffected: the tab bar still renders from the static frontend config (no JS consumer of these routes exists yet), and layout customization/reset still works through core preferences.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KKXV17Z2FVzrtTt8zK5RaF

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

Add a derived section slug to Dashboard_Section and its REST
representation, trim GET /sections to { id, slug, label, order },
retire the per-user section-layout write routes (PUT/DELETE layout,
DELETE sections) and the helpers that served them, and relabel the
woocommerce/store section to Store. Layout persistence stays on core
@wordpress/preferences.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KKXV17Z2FVzrtTt8zK5RaF
@louwie17
louwie17 force-pushed the update/premium-analytics-sections-server-contract branch from 9c9df41 to b0ef0a1 Compare July 20, 2026 13:38
@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (WordPress.com Site Helper), and enable the update/premium-analytics-sections-server-contract branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack-mu-wpcom-plugin update/premium-analytics-sections-server-contract

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@jp-launch-control

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 3 files.

File Coverage Δ% Δ Uncovered
projects/packages/premium-analytics/src/dashboard-layout.php 383/417 (91.85%) -6.00% 25 💔
projects/packages/premium-analytics/src/class-dashboard-section.php 30/30 (100.00%) 0.00% 0 💚
projects/packages/premium-analytics/src/dashboard-sections.php 101/107 (94.39%) 5.28% -26 💚

Full summary · PHP report · JS report

If appropriate, add one of these labels to override the failing coverage check: Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage.

@louwie17
louwie17 marked this pull request as ready for review July 20, 2026 13:49
@louwie17
louwie17 requested review from a team as code owners July 20, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant