Skip to content

Premium Analytics: split the Comments widget into Most commented posts and Most commented authors - #50929

Merged
louwie17 merged 2 commits into
trunkfrom
wooa7s-1787-adapt-insights-tab-based-on-current-experience-comment-widgets
Aug 3, 2026
Merged

Premium Analytics: split the Comments widget into Most commented posts and Most commented authors#50929
louwie17 merged 2 commits into
trunkfrom
wooa7s-1787-adapt-insights-tab-based-on-current-experience-comment-widgets

Conversation

@louwie17

@louwie17 louwie17 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #

Proposed changes

Splits the Jetpack Stats "Comments" module out of a single widget with an in-widget authors/posts view toggle into two focused, quarter-width Insights widgets, per WOOA7S-1787.

  • jpa/most-commented-posts — "Most commented posts": the posts and pages that receive the most comments, each row linking to the published post (through safeHttpUrl).
  • jpa/most-commented-authors — "Most commented authors": the site's most active commenters, avatar + name, each row linking to the comment management screen filtered to that author when the report carries an email for them.
  • Shared data layer, one request. Both widgets consume the same all-time stats/comments response through a new useStatsCommentsRows( { group, max } ) hook over a new selectStatsCommentsRows() selector in packages/data/src/processing/stats/comments.ts. Row keying, flattening, sorting and max trimming (0 = all rows, via limitStatsRows) live in the data layer; only the label/media/link treatment differs per widget. The Comments report page (routes/reports/comments/config/use-report-records.ts) now reads the same selector instead of carrying its own copy of the mapping.
  • The combined jpa/comments widget is removed and the Insights default layout points at the two new widgets instead. See "Fate of the old widget" below.
  • Both widgets render loading / error / empty through <WidgetState>, with describeError() so only retryable failures (the proxy's no_connection 403) offer Retry, and a neutral per-widget glyph for empty.
  • Storybook stories for both: Default close-up, Loading / ErrorState / RetryableErrorState / Empty forced-state stories, and a WidgetDashboardWithWidget story mounting the real dashboard. A shared forceStatsCommentsState() helper was added next to forceWordAdsEarningsState() so the two story files don't each hand-roll the cache reset (the stats/comments query key carries no date params, so a distinct preset can't isolate a forced-state story). No WithComparison story: useStatsComments is not a mergeComparisonRows hook — the endpoint is all-time and has no comparison period.
Screenshot 2026-07-31 at 11 23 45

Fate of the old jpa/comments widget: removed

jpa/comments is removed rather than kept for back-compat:

  • It has never been released. Its changelog entry (changelog/add-comments-widget) is still pending and CHANGELOG.md has no releases, so no persisted user layout in the wild can reference jpa/comments.
  • Precedent. Premium Analytics: remove the superseded Videos widget #50431 removed the superseded jpa/videos widget the same way — drop the widget, repoint the default layout, add a removed changelog entry alongside the original added one.
  • The host degrades gracefully anyway. WidgetChrome renders an "Widget is no longer available." card naming the missing type for an unknown widget in a saved layout, so even a stale layout would not crash.
  • Keeping it would leave three overlapping widgets covering the same report in the widget picker, and its view attribute toggle is exactly what the split removes.

Design notes / points a human may want to veto

  • Titles differ from the Linear issue text. The issue says "Top commented authors" / "Top commented posts". The designer's prototype renders "Most commented posts" / "Most commented authors", so that is what shipped here, including the jpa/most-commented-* slugs so the registered name and the visible title can't drift. Easy to flip back if the issue wording was intended.
  • Layout. Both are quarter-width (1 of 4 columns), height 2, placed adjacent with posts before authors to match the prototype's bottom row. The prototype's bottom row is posts / authors / shares / tags; jpa/tags currently sits in Insights row 2 and was left alone, and two prototype modules (All-time total views — WOOA7S-1512, Most popular post — part of WOOA7S-1510) are not ported yet, so the Insights layout still can't match the prototype row-for-row.
  • Footer link kept. The prototype shows no footer link on these two cards. Both widgets keep a <ReportLink report="comments" section="posts|authors"> footer, as the old Comments widget had — dropping it would remove the only entry point into the Comments report page. Trivial to remove if the design is authoritative here.
  • max default kept at 10. The prototype shows 7 rows; 10 matches the old Comments widget and the neighbouring Insights leaderboards (jpa/shares, jpa/tags). Rows are trimmed after fetching, so max = 0 still means "all rows".

Related product discussion/links

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

No. Both widgets read the existing all-time stats/comments report through the existing Premium Analytics data proxy — no new endpoint, no new prefix in PREFIX_CONFIG, no new tracking.

Testing instructions

  • Build the package: jetpack build --deps packages/premium-analytics (or jetpack build plugins/premium-analytics --deps).
  • Open Jetpack → Stats → Insights. In the bottom rows you should see Most commented posts and Most commented authors side by side, each a quarter-width leaderboard, and no "Comments" widget with a "View by" header control.
  • Most commented posts: rows are post/page titles with the comment count right-aligned; clicking a row opens the published post in a new tab. A post whose permalink is not http(s) renders as plain text instead of a link.
  • Most commented authors: rows are avatar + author name; a guest commenter links to edit-comments.php?s=<email> (the comment management screen filtered to them), while a WordPress.com user row stays unlinked.
  • Both widgets' "See report" footer links open the Comments report on the matching tab (Authors / Posts & pages), and the report page still renders both tabs correctly.
  • Open the gear on either widget and change Number of results; the row count follows, and 0 shows every row.
  • Storybook (pnpm storybook:dev in projects/js-packages/storybook): Packages/Premium Analytics/Widgets/MostCommentedPosts and .../MostCommentedAuthors — check Default, the WidgetDashboardWithWidget dashboard story, and the Loading / ErrorState (no Retry) / RetryableErrorState (Retry) / Empty states.
  • Automated: jetpack test js packages/premium-analytics, jetpack test php packages/premium-analytics, jetpack phan packages/premium-analytics.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HAX3YkQxDLLXhKXjft6qU2

…oards

Breaks the Jetpack Stats "Comments" module out of one widget with an
authors/posts view toggle into two focused widgets:

- `jpa/most-commented-posts` — posts and pages by comment count.
- `jpa/most-commented-authors` — the site's most active commenters.

Both read the same all-time `stats/comments` response through a new shared
`useStatsCommentsRows` data hook over `selectStatsCommentsRows`, so showing
both still costs a single request and the row normalisation lives in the data
layer instead of being copied per widget. The Comments report page now reads
the same selector.

The combined `jpa/comments` widget is removed and the Insights default layout
points at the two new widgets. It was never released, so no persisted layout
can reference it.

WOOA7S-1787
@louwie17
louwie17 requested a review from a team as a code owner July 30, 2026 14:45
@louwie17 louwie17 added the Enhancement Changes to an existing feature — removing, adding, or changing parts of it label Jul 30, 2026
@louwie17
louwie17 requested a review from a team as a code owner July 30, 2026 14:45
@louwie17 louwie17 added [Status] Needs Review This PR is ready for review. Enhancement Changes to an existing feature — removing, adding, or changing parts of it labels Jul 30, 2026
@louwie17 louwie17 self-assigned this Jul 30, 2026
@github-actions

github-actions Bot commented Jul 30, 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 or WordPress.com Site Helper), and enable the wooa7s-1787-adapt-insights-tab-based-on-current-experience-comment-widgets branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack wooa7s-1787-adapt-insights-tab-based-on-current-experience-comment-widgets
bin/jetpack-downloader test jetpack-mu-wpcom-plugin wooa7s-1787-adapt-insights-tab-based-on-current-experience-comment-widgets

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

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!

@louwie17
louwie17 marked this pull request as draft July 30, 2026 14:48
@jp-launch-control

jp-launch-control Bot commented Jul 30, 2026

Copy link
Copy Markdown

Code Coverage Summary

Cannot generate coverage summary while tests are failing. 🤐

Please fix the tests, or re-run the Code coverage job if it was something being flaky.

Full summary · JS report

`toCommentsAuthorRow` and `toCommentsPostRow` derived `label`, `value` and
`link` identically; only the row key and the group-specific `avatarUrl` /
`postId` differed. Merge them into a single `toCommentsRow( item, group )` that
builds the shared fields once and branches only on the genuine differences,
carrying both key-derivation rationales into the merged function.

The `id` fallback chains are unchanged: authors still key on the gravatar hash
then a label-derived key, posts still key on the post id, then the raw link
(so identity survives a consumer rejecting that URL), then the label.

Adds the fallback-branch tests that were missing first — an author with no
gravatar, a post with no id, a post with neither id nor link, and post id 0
(falsy but present, so the check must stay `!= null`). They were written and
confirmed green against the two original functions before the merge.

WOOA7S-1787
@louwie17
louwie17 marked this pull request as ready for review July 31, 2026 09:24

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

Reviewed the diff (tested the sibling PR's flow on a local docker env earlier today). Clean split — one endpoint, two focused leaderboards, and the defaults + PHP test are exactly what I'd hoped to see. Four light notes, nothing blocking:

  1. Deleting jpa/comments outright is the right call pre-beta (an alias to either new widget would misrepresent the old combined card). One 30-second sanity check worth doing: confirm the host degrades gracefully when a saved layout references a now-unregistered type — a11n dogfooding sites may have persisted boards with the old card, and every future widget removal will lean on the same behavior. An empty slot or dropped entry is fine; a crash isn't.
  2. Cache sharing between the two widgets: since the endpoint returns both groups in one response, please confirm group (and differing max) stays out of the query key/request params so both cards share a single cache entry — a small test asserting one request for a board with both widgets would lock it in.
  3. All-time copy: the endpoint is dateless, so both cards show all-time data while sitting under the dashboard's date pills. Worth saying "all-time" in the help copy until the Insights date-model question on WOOA7S-1787 is settled. (Verified the widgets don't consume reportParams, so no stray comparison request here — the stories are the only touchpoints.)
  4. 👍 for updating dashboard-layout.php defaults with a PHP test in the same PR — #50931 currently leaves its new widget out of the Insights defaults; would be great to mirror this there.

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

LGTM — tested locally (defaults populate the two new cards after a reset, and both cards share a single comments request). The notes in my earlier comment are all non-blocking.

截圖 2026-07-31 晚上10 30 21

@louwie17
louwie17 merged commit 912be6e into trunk Aug 3, 2026
79 of 81 checks passed
@louwie17
louwie17 deleted the wooa7s-1787-adapt-insights-tab-based-on-current-experience-comment-widgets branch August 3, 2026 07:29
@github-actions github-actions Bot added [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. and removed [Status] In Progress [Status] Needs Review This PR is ready for review. labels Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Package] Premium Analytics [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants