Skip to content

CMM-2133: Self-fetch the remaining Stats detail screens (clicks, search, video, downloads, authors)#23067

Draft
adalpari wants to merge 9 commits into
trunkfrom
feature/cmm-2133-stats-detail-self-fetch
Draft

CMM-2133: Self-fetch the remaining Stats detail screens (clicks, search, video, downloads, authors)#23067
adalpari wants to merge 9 commits into
trunkfrom
feature/cmm-2133-stats-detail-self-fetch

Conversation

@adalpari

@adalpari adalpari commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Description

Stacked on top of #23066 (feature/cmm-2133-stats-referrer-children) — please review/merge that one first.

#23066 fixed the referrers detail screen so it self-fetches its full list instead of passing it through the launching Intent (which risked TransactionTooLargeException). This PR applies the same fix to the other Stats cards that had the identical pattern: they fetch the full, unbounded list (max = 0) and hand the entire list to the detail Activity via an Intent extra.

Affected cards: Clicks, Search Terms, Video Plays, File Downloads (all share MostViewedDetailActivity) and Authors (its own AuthorsDetailActivity). Posts & Pages and Locations pass their list via the Intent too but are bounded (max = 10), so they are left as-is.

Changes

  • Added MostViewedDetailSource + MostViewedDetailFetcher: given a source, it fetches the full (unbounded) list and maps it to the common StatsCardFetchResult shape. The per-item mapping mirrors the corresponding card ViewModels.
  • Generalized MostViewedDetailViewModel (added in CMM-2133: Expandable referrers with children in new Stats #23066 for referrers) from loadReferrers(period) to load(source, period), so Referrers, Clicks, Search Terms, Video Plays and File Downloads all self-fetch through one path.
  • MostViewedDetailActivity: replaced startReferrers(period) with startSelfFetch(cardType, source, period, valueHeaderResId); the four clicks-family "Show all" handlers now launch self-fetch instead of passing the full item list.
  • Authors: new AuthorsDetailViewModel (self-fetches max = 0, exposes Loading/Loaded/Error), and AuthorsDetailActivity now self-fetches via startSelfFetch(period) with a loading/error/retry state. Extracted the shared TopAuthorItemData.toAuthorUiItem() mapper so the card and detail agree.
  • Added getCurrentPeriod() to BaseStatsCardViewModel and AuthorsViewModel so "Show all" can pass the selected period.

Notes

Testing instructions

For each of Clicks, Search Terms, Video Plays, File Downloads, Authors:

  1. Open the new Stats screen on a site with data for the card.
  • Tap Show all; verify a brief loading indicator, then the full list (more than the ~10 on the card).
  • Verify the summary header (total + change) and per-row values look correct.
  • Rotate the device on the detail screen; verify it does not re-fetch/flicker and keeps its data.
  • (Optional) With no network, tap Show all and verify an error state with a working Retry.
  1. Regression:

adalpari and others added 9 commits July 3, 2026 12:43
Referrer groups can contain child referrers (e.g. "Search Engines"),
but the new stats Referrers card discarded them and rendered a flat
list. Thread a children list (name, url, views) from the datasource
through the repository, UI state and ViewModel, and render referrer
groups with children as expand/collapse rows in both the card and the
detail screen, following the UTM card pattern. Tapping a child opens
its URL in a Chrome Custom Tab.

CMM-2133

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Remove the decorative right arrow from Most Viewed rows (shared by
posts, referrers, clicks, search terms, video plays and file downloads)
since it did not navigate anywhere. Move the expand/collapse dropdown
arrow before the views count on referrer groups with children, and show
a right arrow only on clickable URL child rows to signal they open a
link.

CMM-2133

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Expanded child rows sat flush against their parent row in the referrers
and UTM cards and detail screens. Add a small top margin so children are
visually separated when a group is expanded.

CMM-2133

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
When a group had more than one child, the child rows were rendered flush
against each other. Space them evenly in the referrers and UTM cards and
detail screens.

CMM-2133

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The referrers endpoint returns only 10 items when max is unset. Send an
explicit max=0 (which the server treats as unlimited) so it returns the
full referrer list, matching how Posts & Pages behaves: the card still
shows the first CARD_MAX_ITEMS entries while the detail screen shows all
of them.

CMM-2133

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Extract the duplicated chevron, child row and expandable-children block
from MostViewedCard and MostViewedDetailActivity into a shared
MostViewedCommonComposables file, reusing StatsListRowContainer for the
child row bar. Inject ActivityNavigator into NewStatsActivity and thread
the child-click callback down instead of constructing the navigator in a
composable and casting the context to Activity. Compute maxChildViews
only when a group is expanded, and document the referrers max=0
semantics.

CMM-2133

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The detail screen renders rows in a LazyColumn, so the per-row expanded
state held in a plain remember was discarded when a row scrolled off
screen and reset to collapsed when it returned. Use rememberSaveable and
key the list by item id so an expanded group stays expanded across
scrolling.

CMM-2133

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The referrers card fetched the full (max=0) list and passed it to the
detail screen through the launching Intent, and the detail LazyColumn was
keyed by item.id (derived from name.hashCode()). On sites with many
referrers this risked a TransactionTooLargeException, and empty/duplicate
referrer names could collide into duplicate keys and crash the list.

Bound the card request to REFERRERS_CARD_MAX and add fetchReferrersDetail
(max=0) so the detail screen self-fetches its own unbounded list via a new
MostViewedDetailViewModel (Loading/Error/Loaded), passing only the period
through the Intent. Key the detail list by index instead of item.id.

CMM-2133

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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

Copy link
Copy Markdown
Collaborator
2 Errors
🚫 Please add tests for class AuthorsDetailViewModel (or add unit-tests-exemption label to ignore this).
🚫 Please add tests for class MostViewedDetailFetcher (or add unit-tests-exemption label to ignore this).
1 Warning
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.
1 Message
📖 This PR is still a Draft: some checks will be skipped.

Generated by 🚫 Danger

@wpmobilebot

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
Versionpr23067-7519912
Build Number1498
Application IDorg.wordpress.android.prealpha
Commit7519912
Installation URL3b02igrvuu7tg
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

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
Versionpr23067-7519912
Build Number1498
Application IDcom.jetpack.android.prealpha
Commit7519912
Installation URL79kllv65k76h8
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

Base automatically changed from feature/cmm-2133-stats-referrer-children to trunk July 3, 2026 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants