Skip to content

CMM-2133: Self-fetch clicks, search, video, file downloads and authors stats detail#23077

Open
adalpari wants to merge 3 commits into
trunkfrom
feature/cmm-2133-stats-detail-self-fetch-sources
Open

CMM-2133: Self-fetch clicks, search, video, file downloads and authors stats detail#23077
adalpari wants to merge 3 commits into
trunkfrom
feature/cmm-2133-stats-detail-self-fetch-sources

Conversation

@adalpari

@adalpari adalpari commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Description

Generalizes the new Stats detail-screen self-fetch — previously referrers-only (shipped in #23066) — to the remaining "most viewed" sources and to Authors.

These cards were fetching the full, unbounded list (max = 0) and passing the whole list to their detail Activity through the launching Intent, risking a TransactionTooLargeException on sites with many entries. Now only the selected period crosses the Intent, and the detail screen re-fetches its own full list.

Changes

  • Add MostViewedDetailSource enum and MostViewedDetailFetcher (routes each source to the right StatsRepository call and maps to the common detail shape).
  • Turn MostViewedDetailViewModel into a generic load(source, period) and replace startReferrers() with startSelfFetch(), so Clicks, Search Terms, Video Plays and File Downloads re-fetch their own full list when the detail screen opens.
  • Add AuthorsDetailViewModel and make AuthorsDetailActivity self-fetch the same way, with loading/error states.
  • Wire-up in NewStatsActivity, AuthorsViewModel, BaseStatsCardViewModel.

Notes

Test instructions

  1. Open new Stats on a site with many entries in Clicks / Search Terms / Video Plays / File Downloads / Authors.
  2. Tap into each card's detail screen; confirm the full list loads (self-fetched) with correct totals, and rotation doesn't re-fetch.
  3. Verify loading and error states render.

CMM-2133

🤖 Generated with Claude Code

These cards fetched the full unbounded list (max=0) and passed the whole
list to their detail Activity through the launching Intent, risking a
TransactionTooLargeException on sites with many entries — the same issue
already fixed for referrers.

Generalize the referrers self-fetch: add MostViewedDetailSource and
MostViewedDetailFetcher, turn MostViewedDetailViewModel into a generic
load(source, period), and replace startReferrers with startSelfFetch so
Clicks, Search Terms, Video Plays and File Downloads re-fetch their own
full list when the detail screen opens. Add AuthorsDetailViewModel and
make AuthorsDetailActivity self-fetch the same way (with loading/error
states). Only the selected period crosses the Intent now.

CMM-2133

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

dangermattic commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator
2 Warnings
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

Add unit tests for AuthorsDetailViewModel and MostViewedDetailFetcher,
and update MostViewedDetailViewModelTest for the new load(source, period)
API and MostViewedDetailFetcher-based constructor (the old test still
referenced loadReferrers/statsRepository and no longer compiled).

Also align AuthorsDetailViewModel error handling with
MostViewedDetailViewModel: rethrow CancellationException instead of
swallowing it, and log via AppLog + show the localized
stats_error_unknown string rather than the raw exception message.

CMM-2133

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

wpmobilebot commented Jul 8, 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
Versionpr23077-6710642
Build Number1498
Application IDorg.wordpress.android.prealpha
Commit6710642
Installation URL2orocsdun10f8
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

wpmobilebot commented Jul 8, 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
Versionpr23077-6710642
Build Number1498
Application IDcom.jetpack.android.prealpha
Commit6710642
Installation URL1vcpggqtb11ng
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

Follow-up to the stats detail self-fetch work, from PR review:

- Remove the now-orphaned getDetailData()/AuthorsDetailData and their
  dead backing fields, the unused cardType abstract contract and its
  subclass overrides, and the newly-unused AuthorsViewModel
  resourceProvider dependency (plus the tests that only covered them).
- Use the isAuthError flag the fetcher already produced: propagate it
  into the Most Viewed and Authors detail error states and offer an
  "Open WP Admin" action on auth errors, matching the cards and the UTM
  detail screen.
- Align the empty-list maxViewsForBar default to 0L across the detail
  screens.
- Reduce return counts in readSelfFetchArgs and fetch to satisfy detekt,
  and drop a blank line before a brace for checkstyle.

CMM-2133

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

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.68627% with 113 lines in your changes missing coverage. Please review.
✅ Project coverage is 37.36%. Comparing base (ba564f6) to head (6710642).

Files with missing lines Patch % Lines
...droid/ui/newstats/authors/AuthorsDetailActivity.kt 0.00% 70 Missing ⚠️
.../wordpress/android/ui/newstats/NewStatsActivity.kt 0.00% 21 Missing ⚠️
...ui/newstats/mostviewed/MostViewedDetailActivity.kt 0.00% 14 Missing ⚠️
...roid/ui/newstats/authors/AuthorsDetailViewModel.kt 93.61% 0 Missing and 3 partials ⚠️
...i/newstats/mostviewed/MostViewedDetailViewModel.kt 86.36% 0 Missing and 3 partials ⚠️
...ss/android/ui/newstats/authors/AuthorsViewModel.kt 90.90% 1 Missing ⚠️
...d/ui/newstats/mostviewed/BaseStatsCardViewModel.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            trunk   #23077      +/-   ##
==========================================
+ Coverage   37.33%   37.36%   +0.02%     
==========================================
  Files        2337     2339       +2     
  Lines      126824   126925     +101     
  Branches    17470    17492      +22     
==========================================
+ Hits        47354    47426      +72     
- Misses      75593    75618      +25     
- Partials     3877     3881       +4     

☔ 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.

@adalpari adalpari marked this pull request as ready for review July 8, 2026 15:34
@adalpari adalpari requested a review from nbradbury July 8, 2026 15:35
@adalpari

adalpari commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Note: you might find an error when retrieving Authors but it's not related to this PR. I'll investigate it in a different one

@nbradbury

Copy link
Copy Markdown
Contributor

I found a couple of issues that are unrelated to this PR. First, if you use a large font the network error message shows up as two lines aligned to the left.

network

Secondly, requesting file download stats fails for Jetpack sites.

Screenshot 2026-07-08 at 2 54 02 PM

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

Nice improvement! I left a couple of comments but I believe they're not the result of this PR. :shipit:

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