My Jetpack: hide large Stats card when the Stats module is disabled#50464
My Jetpack: hide large Stats card when the Stats module is disabled#50464jeherve wants to merge 3 commits into
Conversation
The large "Views in the last 7 days" card was gated only on Stats ownership and a flag that is effectively always on, never on whether the Stats module is active. Since #43870 switched the card to the "slim" variant (which drops the status label and activation button), a disabled module produced a bare, empty graph linking to an inaccessible admin page. Gate the large card on the Stats product status via a new shouldShowFullStatsCard() helper. When Stats is not active, fall back to the compact grid card, which offers a proper activation CTA.
|
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 39 files. Only the first 5 are listed here.
Full summary · PHP report · JS report If appropriate, add one of these labels to override the failing coverage check:
Covered by non-unit tests
|
A disabled Stats module is reported as "unowned", so it leaves the owned-products grid entirely — the previous approach (a compact card gated on the owned list) only rendered transiently while the ownership data settled, producing a one-second flash then nothing. Drive both cards off the Stats product status instead: - shouldShowFullStatsCard(): large card only for active/can_upgrade. - shouldShowCompactStatsCard(): compact "Activate Stats" card for any non-active status, gated on a defined status so it doesn't flicker while loading. Stats is always rendered explicitly (large card above the grid, or compact card prepended into it) and removed from the owned-products loop, so it renders exactly once. Both cards also require the user to be able to view stats.
There was a problem hiding this comment.
Pull request overview
This PR fixes a regression in the My Jetpack “Products” view where the large Stats (“Views in the last 7 days”) card could render as an empty, non-actionable graph when the Stats module is disabled, by gating the full card on the Stats product’s module status and falling back to the compact activation card.
Changes:
- Add explicit show/hide logic for the full vs. compact Stats card based on Stats product status, user capability, and the existing full-card flag.
- Add unit tests for the new
shouldShowFullStatsCard/shouldShowCompactStatsCardgating behavior. - Add a My Jetpack changelog entry for the fix.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| projects/packages/my-jetpack/changelog/fix-my-jetpack-stats-card-module-disabled | Adds changelog entry for the Stats card visibility fix. |
| projects/packages/my-jetpack/_inc/components/product-cards-section/test/index.test.ts | Adds coverage for the new Stats card gating helpers. |
| projects/packages/my-jetpack/_inc/components/product-cards-section/stats-card.jsx | Updates inline documentation for the compact Stats card fallback. |
| projects/packages/my-jetpack/_inc/components/product-cards-section/index.tsx | Implements the full/compact Stats card gating and explicit rendering behavior. |
- Only remove Stats from the owned-products grid loop when we actually render it explicitly (showFullStatsCard || showCompactStatsCard). Previously it was always removed, so when showFullJetpackStatsCard is false (a standalone plugin without the main Jetpack plugin) the Stats card could no longer render at all. - Move the changelog description into the entry body; a 'Comment:'-only entry with an empty body is treated as an internal/skipped entry and produces no user-facing changelog line. - Clarify the stats-card.jsx and item-map comments re: the full-stats -card flag gating.
Fixes JETPACK-1902
Proposed changes
On the My Jetpack screen, the large "Views in the last 7 days" Stats card was displayed even when the Stats module is disabled on the site. In that state it rendered as a bare, empty graph ("No data available"), and clicking it navigated to
admin.php?page=stats, a page that isn't accessible when the module is off.This PR fixes this: when Stats is not active, we fall back to the existing compact grid card, which offers a proper "Activate" CTA instead of the empty graph.
Why now
This is a regression from #43870 (June 30, 2025), which switched the card to
variant="slim". The slim variant drops the status label and activation button that previously made the disabled state graceful, leaving only the empty chart. The visibility gate itself never checked module status.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
jetpack module deactivate statsin CLI).