Repository navigation
Premium Analytics: hide commerce widget categories without their plugin - #50736
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 1 file.
|
Gate the WooCommerce widget categories (store, orders, coupons, bookings) at registry time: they are only registered while WooCommerce is active, read through the store section's availability signal so section and widgets cannot disagree. The bookings category additionally requires the WooCommerce Bookings extension, detected the same way as woocommerce-analytics' Bookings sync module. Recategorize top-performing-bookings from store to bookings — it renders bookings data, so it belongs behind the Bookings gate. Switch the developer-only gate from a name match to a category check, as its comment instructed now that the build manifest carries category. Refs WOOA7S-1775, WOOA7S-1722. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011Lm9n11NbC2AZVAgzoEywr
…checks Move `bookings` out of WOOCOMMERCE_WIDGET_CATEGORIES into its own WOOCOMMERCE_BOOKINGS_WIDGET_CATEGORIES constant and check each list independently — the Bookings extension cannot run without WooCommerce, so its presence implies both. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011Lm9n11NbC2AZVAgzoEywr
52c9f3f to
8ccb874
Compare
retrofox
left a comment
There was a problem hiding this comment.
Thanks, Lourens 🙇♂️
Approving this because it solves the immediate problem, is well tested, and the section/widget coupling via the availability signal is the right call within this pattern 🚀
But :-) I want to leave on record that I see this as transitional, not the model to build on.
The pattern this consolidates is PA bundling every widget and then subtracting, from a central policy file, those whose backing plugin is missing.
That forces PA to know every domain, which categories belong to which plugin, and how to detect each one (class_exists( 'WC_Bookings' )).
Every new integration grows that same file. It doesn't scale, and it inverts the extensibility model: the dashboard should be common ground where each plugin registers its own widgets and sections, the same way plugins register blocks or admin pages.
If the plugin isn't active, its widgets simply don't exist. Availability becomes a structural fact instead of an inference we reconstruct with detection code.
Ownership follows the domain: the commerce widgets should be registered by WooCommerce Analytics, WooCommerce core, or whatever owns that domain.
Same for the widgets that mirror what Jetpack Stats offers today: they belong to Stats. Instead of defining widgets inside PA, the plugin defines them.
Taken to its conclusion, PA stops being a widget owner and becomes the shell: registry, sections, layouts, REST. At that point, it could even live in Jetpack core as just another page, like Jetpack Forms.
Totally agree! I think this would be worth exploring more as we dive back into the Woo related work more. The slight question is, where will it live? In WooCommerce plugin it-self? In Jetpack as a composer package which Woo could in turn install? :) |
|
It's already a Jetpack package, consumed by the Premium Analytics plugin, right?. This means we could potentially
|
Yup, makes sense! We could use WooCommerce as the testing ground for this & Bookings of-course. It would mean we did have to move all our Woo related work out of the package atm. |
Fixes WOOA7S-1775
Proposed changes
filter_registrable_widget_types_by_plugin, hooked onREGISTRABLE_WIDGET_TYPES_FILTER(same pattern as the dev-only gate from Premium Analytics: add React Query Devtools dev-only widget #50002): the WooCommerce widget categories —store,orders,coupons, andbookings— are only registered while WooCommerce is active.is_woocommerce_dashboard_section_available(), including itsjetpack_premium_analytics_woocommerce_dashboard_section_availablefilter), so the store section and its widgets can't disagree — forcing the section available via the filter surfaces the widgets too.bookingscategory on the WooCommerce Bookings extension, mirroring the detection used by woocommerce-analytics' Bookings sync module (class_exists( 'WC_Bookings' ), with a guardedis_plugin_active()fallback).jpa/top-performing-bookingsfromstoretobookings— it renders bookings data, so it belongs behind the Bookings gate.category: developercheck, as its own comment instructed now that the wp-build manifest carriescategory.Out of scope, by design:
democategory (jpa/hello-world) and report-route gating.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 -- --filter Widget_Availability_Test(or the full suite)./wpcom/v2/dashboards/widget-modulesvia the dashboard, or observe the network tab on dashboard load) should contain no widgets from those categories.bookings-*,store-conversion-rate-bookings,top-performing-bookings) remain hidden.