WOOA7S-2210: Premium Analytics: Handle zero-data periods in charts and highlights - #52795
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! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. Premium Analytics plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 11 files. Only the first 5 are listed here.
|
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Posting activity can suppress request errors when stale placeholder data is present; current-range error handling should be restored.
Review effort: Lite
Findings: None
What changed in this PR
Updates Premium Analytics widgets to correctly handle zero/null Stats API data.
Changes:
- Adds chart-level empty states while preserving tabs and zero values.
- Updates highlights and Insights widgets to display appropriate zeros/placeholders.
- Adds tests, stories, toolkit support, and changelog entries.
| File | Reviewed change |
|---|---|
projects/plugins/wpcomsh/changelog/update-pa-zero-data-charts-highlights |
Changelog entry. |
projects/plugins/premium-analytics/changelog/update-pa-zero-data-charts-highlights |
Changelog entry. |
projects/plugins/jetpack/changelog/update-pa-zero-data-charts-highlights |
Changelog entry. |
projects/packages/premium-analytics/widgets/wordads-chart-tabs/use-wordads-chart.ts |
Removes widget-level empty-state handling. |
projects/packages/premium-analytics/widgets/wordads-chart-tabs/render.tsx |
Adds chart-level empty state. |
projects/packages/premium-analytics/widgets/wordads-chart-tabs/__tests__/wordads-chart-tabs.test.tsx |
Updates WordAds coverage. |
projects/packages/premium-analytics/widgets/views-over-years/use-views-over-years.ts |
Handles no-view responses. |
projects/packages/premium-analytics/widgets/views-over-years/stories/views-over-years-widget.stories.tsx |
Updates story coverage. |
projects/packages/premium-analytics/widgets/views-over-years/render.tsx |
Renders zero-view data. |
projects/packages/premium-analytics/widgets/views-over-years/build-views-over-years.ts |
Builds a zero-valued current month. |
projects/packages/premium-analytics/widgets/views-over-years/__tests__/views-over-years.test.tsx |
Tests zero-view rendering. |
projects/packages/premium-analytics/widgets/views-over-years/__tests__/use-views-over-years.test.tsx |
Tests hook states. |
projects/packages/premium-analytics/widgets/views-over-years/__tests__/build-views-over-years.test.ts |
Tests zero-row construction. |
projects/packages/premium-analytics/widgets/traffic-chart/stories/traffic-chart-widget.stories.tsx |
Updates empty-period story. |
projects/packages/premium-analytics/widgets/traffic-chart/render.tsx |
Moves empty state into the chart. |
projects/packages/premium-analytics/widgets/traffic-chart/__tests__/render.test.tsx |
Tests zero-filled charts. |
projects/packages/premium-analytics/widgets/total-visitors/render.tsx |
Detects zero visitor data. |
projects/packages/premium-analytics/widgets/total-visitors/__tests__/total-visitors.test.tsx |
Tests zero visitor ranges. |
projects/packages/premium-analytics/widgets/total-views/render.tsx |
Detects zero view data. |
projects/packages/premium-analytics/widgets/total-views/__tests__/total-views.test.tsx |
Tests zero view ranges. |
projects/packages/premium-analytics/widgets/subscribers-chart/render.tsx |
Handles null subscriber data in-chart. |
projects/packages/premium-analytics/widgets/subscribers-chart/__tests__/subscribers-chart.test.tsx |
Tests null subscriber periods. |
projects/packages/premium-analytics/widgets/subscriber-highlights/stories/subscriber-highlights-widget.stories.tsx |
Updates highlights story. |
projects/packages/premium-analytics/widgets/subscriber-highlights/render.tsx |
Shows zero counts and placeholders. |
projects/packages/premium-analytics/widgets/subscriber-highlights/__tests__/subscriber-highlights.test.tsx |
Tests zero and placeholder values. |
projects/packages/premium-analytics/widgets/site-overview/stories/site-overview-widget.stories.tsx |
Updates zero-metric story. |
projects/packages/premium-analytics/widgets/site-overview/render.tsx |
Shows zero-valued metrics. |
projects/packages/premium-analytics/widgets/site-overview/__tests__/site-overview.test.tsx |
Tests zero metrics. |
projects/packages/premium-analytics/widgets/posting-activity/stories/posting-activity-widget.stories.tsx |
Updates empty-calendar story. |
projects/packages/premium-analytics/widgets/posting-activity/render.tsx |
Renders empty calendars; stale responses can suppress errors. |
projects/packages/premium-analytics/widgets/posting-activity/__tests__/posting-activity.test.tsx |
Tests empty calendars and refetches. |
projects/packages/premium-analytics/widgets/email-time-series/render.tsx |
Adds chart-level empty handling. |
projects/packages/premium-analytics/widgets/email-time-series/__tests__/email-time-series.test.tsx |
Tests empty and zero timelines. |
projects/packages/premium-analytics/widgets/annual-highlights/stories/annual-highlights-widget.stories.tsx |
Updates zero-year story. |
projects/packages/premium-analytics/widgets/annual-highlights/render.tsx |
Shows zero-valued missing-year tiles. |
projects/packages/premium-analytics/widgets/annual-highlights/__tests__/annual-highlights.test.tsx |
Tests missing-year zeros. |
projects/packages/premium-analytics/widgets/all-time-stats/stories/all-time-stats-widget.stories.tsx |
Updates missing-summary story. |
projects/packages/premium-analytics/widgets/all-time-stats/render.tsx |
Shows zero-valued missing totals. |
projects/packages/premium-analytics/widgets/all-time-stats/__tests__/all-time-stats.test.tsx |
Tests missing-summary zeros. |
projects/packages/premium-analytics/packages/widgets-toolkit/src/index.ts |
Exports shared empty-data support. |
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/metric-tabs-chart/stories/metric-tabs-chart.stories.tsx |
Adds zero-data chart story. |
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/metric-tabs-chart/metric-tabs-chart.tsx |
Supports per-metric chart empty content. |
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/metric-tabs-chart/__tests__/metric-tabs-chart.test.tsx |
Tests empty and comparison behavior. |
projects/packages/premium-analytics/changelog/update-pa-zero-data-charts-highlights |
Package changelog entry. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
louwie17
left a comment
There was a problem hiding this comment.
Thanks @Nikschavan, this tested well on a local Docker site! For a period with no data the Traffic tab keeps the four tabs at 0 with the magnifier in the chart, a period with data draws again, and comparing a period with no data against one with views still draws both series. Year in review, All-time stats and the posting calendar all render with numbers, no empty state.
I did leave two inline comments. The main thing to fix is the new isEmptyChartData export from the widgets toolkit, which isn't used outside the toolkit, so we should drop that. The other one is smaller, around the empty state being decided per tab, which on WordAds hides the hover readout of the other metrics even when those have data. Maybe that's fine, but wanted to flag it.
Also a heads up, as you mentioned #52794 touches the same five render files. The new total views/visitors tests here assert the old "No views in this period." copy, so whichever lands second will need those tests updated too, not only the render hunks.
Let me know what you think.
37ba365 to
e1a6aee
Compare
louwie17
left a comment
There was a problem hiding this comment.
Thanks for the updates @Nikschavan, and for dropping the export and keeping the WordAds readout! This tested well again on a local Docker site. I left one small nit, happy if it's a follow up. Good to ship 🚢
The Stats API answers an empty period with zero-filled days, so total views, total visitors, the subscribers chart and the email timeline drew a flat line and never reached their empty state. They now count all-zero or null data as empty. Traffic summary keeps its tabs at zero and shows the no-results message inside the chart, per metric, through a new empty prop on MetricTabsChart. Highlights and Insights components no longer show an empty state: site overview, Year in review and All-time stats show zeros, the posting activity calendar and Views over years draw empty, and Subscriber highlights shows zero for current counts and a placeholder for past counts it has no data for. Part of WOOA7S-2210.
Site owners read the plugin changelogs, not the package one, so the entry also goes to each plugin that ships Premium Analytics.
…harts The subscribers chart, the email timeline and the WordAds chart render MetricTabsChart but replaced the whole widget when a period had no data, while Traffic summary kept its tabs at zero and showed the message in the plot. They now pass the same empty content to MetricTabsChart, so an idle period looks the same in every tab chart. The email timeline keeps a widget-level state only for its missing-email prompt. MetricTabsChart checks for data with the shared isEmptyChartData helper, now exported from the toolkit root, instead of its own zero check, and the widgets drop theirs. The WordAds hook no longer returns an isEmpty nothing reads. Part of WOOA7S-2210.
Since #52717, wpcomsh no longer ships the Premium Analytics package; the Jetpack entry covers WoA sites.
… data A chart that reads every metric out on hover, like WordAds, now shows the no-results message only when those other metrics are empty too, so an all-zero Revenue tab still offers the Ads Served readout. isEmptyChartData stays internal to the widgets toolkit.
…mpty check The MetricTabsChart mocks always render the empty prop, so these widget tests prove only that the prop is passed; the emptiness check is covered in MetricTabsChart.
…isitors tests Trunk replaced the per-widget empty copy with the shared "We couldn’t find results for this time period." message in #52794, so the zero-filled range tests now look for that text.
ChartEmptyState already defaults to the search icon and the no-results copy, so the tab charts no longer repeat them.
e1a6aee to
29fb5d1
Compare
Fixes WOOA7S-2210
Proposed changes
stats/visits, the email opens timeline) or anullfor every bucket (stats/subscribers), not an empty list. Total views, total visitors, the subscribers chart and the email timeline only checked for an empty list, so they never reached their empty state and drew a flat line at zero instead. They now treat all-zero or all-null data as empty.MetricTabsChart(Traffic summary, the subscribers chart, the email timeline and the WordAds chart) keeps its tabs at zero and shows the no-results message inside the chart area, instead of replacing the whole widget.MetricTabsChartgets an optionalemptyprop for this, rendered in the same slot it already uses for a metric that is unavailable, and it decides emptiness with the sharedisEmptyChartDatahelper. The check runs per metric: a tab whose metric is all zero shows the message even when another tab has data, unless the chart reads every metric out on hover (WordAds), where the graph stays while any metric has data, and with Compare on, a zero period against a previous period with data still draws both lines. The email timeline keeps a widget-level state only for its prompt to open an email report.Related product discussion/links
ChartEmptyStatedefault. The tab charts pass them explicitly here so this PR does not depend on it; the props can go once WOOA7S-2209: Premium Analytics: Show one generic empty state in list widgets #52791 is in.Does this pull request change what data or activity we track or use?
No.
Testing instructions
update/pa-zero-data-charts-highlights.I checked Traffic summary on my local site with an empty period and with data. The highlight widgets only reach their no-value case on a site the API has nothing for, which my site does not reproduce; unit tests cover those cases with the empty responses the API returns.