Skip to content

My Jetpack: hide large Stats card when the Stats module is disabled#50464

Open
jeherve wants to merge 3 commits into
trunkfrom
fix/my-jetpack-stats-card-module-disabled
Open

My Jetpack: hide large Stats card when the Stats module is disabled#50464
jeherve wants to merge 3 commits into
trunkfrom
fix/my-jetpack-stats-card-module-disabled

Conversation

@jeherve

@jeherve jeherve commented Jul 13, 2026

Copy link
Copy Markdown
Member

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.

Before After
Screenshot 2026-07-13 at 18 14 55 Screenshot 2026-07-13 at 20 38 14

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

  • JETPACK-1902
  • Same class of bug as MYJP-273 ("Despite Modules being Disabled, Protect Card Shows in My Jetpack"), already fixed.

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

No.

Testing instructions

  • On a site with Jetpack connected, disable the Stats module (Jetpack → My Jetpack → Modules → toggle off "Jetpack Stats", or jetpack module deactivate stats in CLI).
  • Go to Jetpack → My Jetpack.
  • Before: a large "Views in the last 7 days" card renders an empty "No data available" graph; clicking it lands on an inaccessible Stats page.
  • After: the large graph is gone; a compact Stats card appears in the grid alongside the other products, with an Activate CTA.
  • Re-enable the Stats module and reload → the large "Views in the last 7 days" card returns as before.

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.
@jeherve jeherve self-assigned this Jul 13, 2026
@github-actions

github-actions Bot commented Jul 13, 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 (Jetpack), and enable the fix/my-jetpack-stats-card-module-disabled branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/my-jetpack-stats-card-module-disabled

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

@github-actions

github-actions Bot commented Jul 13, 2026

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!

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jul 13, 2026
@jeherve jeherve added Bug When a feature is broken and / or not performing as intended [Feature] Stats Data Feature that enables users to track their site's traffic and gain insights on popular content. [Status] In Progress [Pri] Low and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Jul 13, 2026
@jp-launch-control

jp-launch-control Bot commented Jul 13, 2026

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 39 files. Only the first 5 are listed here.

File Coverage Δ% Δ Uncovered
projects/packages/my-jetpack/_inc/components/product-cards-section/index.tsx 6/28 (21.43%) 21.43% 4 💔
projects/packages/my-jetpack/_inc/components/connected-product-card/index.tsx 1/11 (9.09%) 9.09% -1 💚
projects/packages/my-jetpack/_inc/components/product-cards-section/ai-card.jsx 1/2 (50.00%) 50.00% -1 💚
projects/packages/my-jetpack/_inc/components/product-cards-section/boost-card/index.tsx 1/3 (33.33%) 33.33% -1 💚
projects/packages/my-jetpack/_inc/components/product-cards-section/protect-card/index.tsx 1/2 (50.00%) 50.00% -1 💚

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.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 / shouldShowCompactStatsCard gating 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.

Comment thread projects/packages/my-jetpack/changelog/fix-my-jetpack-stats-card-module-disabled Outdated
Comment thread projects/packages/my-jetpack/_inc/components/product-cards-section/index.tsx Outdated
Comment thread projects/packages/my-jetpack/_inc/components/product-cards-section/stats-card.jsx Outdated
- 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.
@jeherve jeherve requested a review from a team July 13, 2026 19:07
@jeherve jeherve added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug When a feature is broken and / or not performing as intended [Feature] Stats Data Feature that enables users to track their site's traffic and gain insights on popular content. [Package] My Jetpack [Pri] Low [Status] Needs Review This PR is ready for review. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants