Skip to content

Improve new stats error states: centering and unavailable sites - #23081

Merged
adalpari merged 5 commits into
trunkfrom
fix/stats-error-message-and-unavailable
Jul 9, 2026
Merged

Improve new stats error states: centering and unavailable sites#23081
adalpari merged 5 commits into
trunkfrom
fix/stats-error-message-and-unavailable

Conversation

@adalpari

@adalpari adalpari commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Description

Follow-up from #23077.

Improves error handling and presentation across the new stats screens. Three related changes:

  1. Center error messages in detail screens — the error Text in the Authors, Emails, Subscribers list, UTM, Year in review, and Most viewed detail screens (and the stats card) had no textAlign, so a message that wraps to multiple lines left-aligned instead of centering. Added textAlign = TextAlign.Center, matching the existing NoConnectionContent/TagsAndCategories convention.

  2. Surface a clear message when stats are unavailable for the site — the WordPress.com stats API returns an invalid_blog error (e.g. file download stats on a Jetpack site) as a WpRequestResult.UnknownError with a 404. This was unhandled and fell through to the generic "An unexpected error occurred", discarding the API's reason. Added a lightweight, dependency-free parser for the API error code, a new StatsErrorType.NOT_AVAILABLE mapped to a meaningful string ("These stats aren't available for this site"), and classification of the invalid_blog code in both the UnknownError and WpError branches.

  3. Hide the Retry button for unavailable stats — retrying a NOT_AVAILABLE error never succeeds, so an isNotAvailable flag is threaded through the card error chain (repository results, card ViewModels, StatsCardFetchResult, and the card/detail UI states). When set, only the message is shown — no Retry or WP Admin button — on both the stats card and the detail screen.

Unit tests added for the error-code parser and the NOT_AVAILABLE mapping.

Testing instructions

stats_detail_screenshot Screenshot 2026-07-09 at 12 49 08

Error message centering:

  1. Open Stats on any site and open a detail screen (e.g. Authors) while offline so the error state shows.
  • Verify the (wrapping) error message is horizontally centered, not left-aligned.

Unavailable stats message + no Retry (requires a Jetpack/self-hosted site):

  1. Log in to a Jetpack site where file download stats are unavailable.
  2. Open Stats → Traffic and scroll to the File downloads card.
  • Verify it shows "These stats aren't available for this site" (centered).

  • Verify there is no Retry button on the card.

  • Verify other stats work as expected

adalpari and others added 3 commits July 9, 2026 11:45
Add textAlign = TextAlign.Center to the error Text in the Authors,
Emails, Subscribers list, UTM and Year in review detail screens so a
wrapping message stays centered instead of left-aligning, matching the
existing NoConnectionContent/TagsAndCategories convention.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The WordPress.com stats API returns an 'invalid_blog' error (e.g. file
download stats on a Jetpack site) as a WpRequestResult.UnknownError with
a 404, which fell through to the generic 'An unexpected error occurred'
message and left the API's reason unread.

Add a lightweight, dependency-free parser for the API error code, a new
StatsErrorType.NOT_AVAILABLE mapped to a meaningful string, and classify
the 'invalid_blog' code (in both the UnknownError and WpError branches)
as NOT_AVAILABLE.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Retrying a NOT_AVAILABLE error never succeeds, so thread an
isNotAvailable flag through the card error chain (repository results,
card ViewModels, StatsCardFetchResult, card/detail UI states) and, when
set, render only the message with no Retry or WP Admin button on both
the stats card and the detail screen.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dangermattic

dangermattic commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator
1 Warning
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

@wpmobilebot

wpmobilebot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

App Icon📲 You can test the changes from this Pull Request in WordPress Android by scanning the QR code below to install the corresponding build.

App NameWordPress Android
Build TypeDebug
Versionpr23081-6a34720
Build Number1498
Application IDorg.wordpress.android.prealpha
Commit6a34720
Installation URL7cas2f2jnq4e0
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

wpmobilebot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

App Icon📲 You can test the changes from this Pull Request in Jetpack Android by scanning the QR code below to install the corresponding build.

App NameJetpack Android
Build TypeDebug
Versionpr23081-6a34720
Build Number1498
Application IDcom.jetpack.android.prealpha
Commit6a34720
Installation URL4tr0sbatq4g98
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.76923% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 37.37%. Comparing base (27c9a69) to head (6a34720).
⚠️ Report is 1 commits behind head on trunk.

Files with missing lines Patch % Lines
...roid/ui/newstats/datasource/StatsDataSourceImpl.kt 0.00% 14 Missing ⚠️
...s/android/ui/newstats/mostviewed/MostViewedCard.kt 0.00% 5 Missing ⚠️
...droid/ui/newstats/authors/AuthorsDetailActivity.kt 0.00% 2 Missing ⚠️
...ui/newstats/mostviewed/MostViewedDetailActivity.kt 0.00% 2 Missing ⚠️
...ewstats/subscribers/emails/EmailsDetailActivity.kt 0.00% 2 Missing ⚠️
...s/subscriberslist/SubscribersListDetailActivity.kt 0.00% 2 Missing ⚠️
...press/android/ui/newstats/utm/UtmDetailActivity.kt 0.00% 2 Missing ⚠️
...ewstats/yearinreview/YearInReviewDetailActivity.kt 0.00% 2 Missing ⚠️
...ss/android/ui/newstats/datasource/StatsApiError.kt 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            trunk   #23081   +/-   ##
=======================================
  Coverage   37.37%   37.37%           
=======================================
  Files        2339     2340    +1     
  Lines      126952   126991   +39     
  Branches    17499    17507    +8     
=======================================
+ Hits        47452    47469   +17     
- Misses      75618    75639   +21     
- Partials     3882     3883    +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Detail screens are only reachable via a card's "Show all" action, which
is absent when a card's stats are unavailable. The NOT_AVAILABLE state
can therefore never render on a detail screen, making the isNotAvailable
retry-hiding logic there dead code.

Revert the detail path (MostViewedDetailActivity showRetry param/logic,
MostViewedDetailViewModel Error field/threading, and the four
MostViewedDetailFetcher error mappings) while keeping the error-message
centering and all card/repository/data-source NOT_AVAILABLE handling.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@adalpari
adalpari marked this pull request as ready for review July 9, 2026 11:14
@adalpari
adalpari requested a review from nbradbury July 9, 2026 11:15

@nbradbury nbradbury 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.

Fixes are good! :shipit:

@adalpari
adalpari merged commit 9a3dbf4 into trunk Jul 9, 2026
26 of 30 checks passed
@adalpari
adalpari deleted the fix/stats-error-message-and-unavailable branch July 9, 2026 13:47
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.

4 participants