Skip to content

Premium Analytics: link widget titles to detail pages - #50919

Merged
Nikschavan merged 5 commits into
trunkfrom
fix/pa-entity-detail-links
Aug 3, 2026
Merged

Nikschavan merged 5 commits into
trunkfrom
fix/pa-entity-detail-links

Conversation

@Nikschavan

@Nikschavan Nikschavan commented Jul 30, 2026 •

Copy link
Copy Markdown
Member

Fixes WOOA7S-1831

Proposed changes

  • Route post, page, and newsletter titles from Premium Analytics widgets to their matching in-app detail pages while preserving the active report date range.
  • Add a shared leaderboard entity-label component with safe public-URL fallback behavior for content that cannot open a detail page.
  • Add regression tests and Storybook routing and context coverage.

Widgets with detail page links

  • Authors — the post rows of the selected author, in the drill-down view.
  • Comments — the post rows, in the Posts view.
  • Emails — the newsletter rows. Each link opens the detail tab that matches the selected metric, Opens or Clicks.
  • Latest post — the post title on the card. This replaces the previous external link to the published post.
  • UTM Insights — the top post rows, in the drill-down view.

Rows without a post ID keep a safe public link, or plain text when no safe URL exists.

Related product discussion/links

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

No.

Testing instructions

  • Open the Premium Analytics dashboard and verify linked titles in the Authors, Comments (Posts view), Emails, Latest post, and UTM Insights widgets navigate without reloading the SPA.
  • Confirm the destination detail page preserves the dashboard date range.
  • In the Emails widget, switch between Opens and Clicks and confirm the matching detail tab opens.
  • Verify rows without a valid entity ID retain a safe public-link fallback or render as plain text when no safe URL exists.
  • Automated: 12 focused Jest suites (86 tests), Premium Analytics typecheck, targeted ESLint, and git diff --check.

@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 fix/pa-entity-detail-links branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/pa-entity-detail-links
bin/jetpack-downloader test jetpack-mu-wpcom-plugin fix/pa-entity-detail-links

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

github-actions Bot commented Jul 30, 2026 •

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!

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jul 30, 2026
@jp-launch-control

jp-launch-control Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 8 files. Only the first 5 are listed here.

File Coverage Δ% Δ Uncovered
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/chart-leaderboard/leaderboard-row.tsx 18/18 (100.00%) 0.00% 0 💚
projects/packages/premium-analytics/widgets/most-commented-posts/render.tsx 8/8 (100.00%) 0.00% 0 💚
projects/packages/premium-analytics/packages/data/src/hooks/use-stats-email-summary.ts 1/1 (100.00%) 100.00% -1 💚
projects/packages/premium-analytics/widgets/latest-post/render.tsx 14/15 (93.33%) 21.90% -3 💚
projects/packages/premium-analytics/widgets/authors/render.tsx 22/23 (95.65%) 15.65% -4 💚

2 files are newly checked for coverage.

File Coverage
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/leaderboard-post-label/leaderboard-post-label.tsx 4/4 (100.00%) 💚
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/leaderboard-post-label/index.ts 0/0 (—%) 🤷

Full summary · PHP report · JS report

@Nikschavan Nikschavan removed the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jul 30, 2026
@Nikschavan
Nikschavan marked this pull request as ready for review July 31, 2026 06:17
@Nikschavan
Nikschavan requested a review from a team July 31, 2026 06:17
@Nikschavan
Nikschavan requested a review from a team as a code owner July 31, 2026 06:17
@Nikschavan
Nikschavan force-pushed the fix/pa-entity-detail-links branch 2 times, most recently from 48f520f to aae6a49 Compare July 31, 2026 09:16
@Nikschavan Nikschavan self-assigned this Jul 31, 2026

@chihsuan chihsuan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work here! I just added two questions. Please see inline comments.

Copilot AI review requested due to automatic review settings August 3, 2026 05:10
@Nikschavan
Nikschavan force-pushed the fix/pa-entity-detail-links branch from aae6a49 to 21e30e4 Compare August 3, 2026 05:10

Copilot AI 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.

Pull request overview

Updates Premium Analytics widgets so post/page/newsletter titles navigate via in-app detail routes (preserving the active report date range), with safe public-URL (or plain-text) fallbacks for rows that can’t resolve to a detail page.

Changes:

  • Introduce a shared LeaderboardPostLabel wrapper around PostTitleLink to standardize linked leaderboard-row labels and preserve report window params.
  • Update multiple widgets (Authors, Comments, Emails, Latest post, UTM Insights) to use internal detail routing where possible, with external/plain fallbacks.
  • Add/expand Jest coverage and Storybook router/context setup for the updated navigation behavior.

Reviewed changes

Copilot reviewed 31 out of 31 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
projects/packages/premium-analytics/widgets/utm-insights/use-utm-insights.ts Add postId to UTM drill-down child rows for internal detail routing.
projects/packages/premium-analytics/widgets/utm-insights/style.module.css Adjust label layout; add inset class for post-label padding alignment.
projects/packages/premium-analytics/widgets/utm-insights/render.tsx Render drilled-in post rows with LeaderboardPostLabel (internal routing + window carry).
projects/packages/premium-analytics/widgets/utm-insights/tests/utm-insights.test.tsx Add navigation regression tests for internal vs fallback linking.
projects/packages/premium-analytics/widgets/utm-insights/tests/use-utm-insights.test.tsx New hook unit test for mapping child post IDs/URLs.
projects/packages/premium-analytics/widgets/latest-post/style.module.css Ensure title link color override wins deterministically via :any-link.
projects/packages/premium-analytics/widgets/latest-post/stories/latest-post-widget.stories.tsx Add Storybook router decorator for internal links.
projects/packages/premium-analytics/widgets/latest-post/render.tsx Swap published-post outbound link for internal post detail link + date-range carry.
projects/packages/premium-analytics/widgets/latest-post/package.json Add routing package dependency for report-window param picking.
projects/packages/premium-analytics/widgets/latest-post/tests/latest-post-card.test.tsx Update tests for internal detail routing + window carry + fallbacks.
projects/packages/premium-analytics/widgets/emails/style.module.css Remove obsolete custom label styling now handled by shared label component.
projects/packages/premium-analytics/widgets/emails/stories/emails-widget.stories.tsx Wrap presentational stories with WidgetRoot + router to support internal links.
projects/packages/premium-analytics/widgets/emails/render.tsx Use LeaderboardPostLabel for newsletter titles and open the metric-matching detail tab.
projects/packages/premium-analytics/widgets/emails/tests/emails.test.tsx New tests for metric→section routing and API row mapping into detail links.
projects/packages/premium-analytics/widgets/comments/use-comment-views.ts Capture post IDs for posts view to enable internal detail navigation.
projects/packages/premium-analytics/widgets/comments/render.tsx Render post rows via LeaderboardPostLabel instead of outbound permalink actions.
projects/packages/premium-analytics/widgets/comments/tests/comments.test.tsx Add regression test asserting in-app navigation for post rows.
projects/packages/premium-analytics/widgets/authors/render.tsx Render drilled-down post rows via LeaderboardPostLabel.
projects/packages/premium-analytics/widgets/authors/build-top-authors-data.ts Preserve post ID separately from row ID for internal detail routes.
projects/packages/premium-analytics/widgets/authors/tests/build-top-authors-data.test.ts Update expectations to include mapped postId.
projects/packages/premium-analytics/widgets/authors/tests/authors.test.tsx Add regression test for drilled-down post internal navigation.
projects/packages/premium-analytics/packages/widgets-toolkit/src/index.ts Re-export new shared leaderboard label component/types.
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/post-title-link/post-title-link.tsx Add default link styling (via module + clsx) while preserving caller overrides.
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/post-title-link/post-title-link.module.scss New default link styling to avoid wp-admin “admin blue” overrides.
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/leaderboard-post-label/leaderboard-post-label.tsx New shared component: row chrome + report-window carry + optional detail tab section.
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/leaderboard-post-label/leaderboard-post-label.module.scss New styles for compact vs overlay variants and ellipsis behavior.
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/leaderboard-post-label/index.ts New barrel export for the component/types.
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/leaderboard-post-label/tests/leaderboard-post-label.test.tsx New unit tests for internal routing, section param, and safe fallback behavior.
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/index.ts Export LeaderboardPostLabel from components index.
projects/packages/premium-analytics/packages/widgets-toolkit/src/components/chart-leaderboard/leaderboard-row.tsx Document why post/page/email labels should use LeaderboardPostLabel (no nested anchors in button rows).
projects/packages/premium-analytics/changelog/fix-widget-post-detail-links Changelog entry for the user-facing navigation change.

} );
return selectedAuthor.posts.map( post => ( {
id: post.id,
label: <LeaderboardPostLabel id={ post.postId } label={ post.title } link={ post.link } />,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

withOverlayLabel only pre-blends the bar fill colour — it sets no row height. The variant tracks the sibling rows in the same widget, and the top-level author rows here come from buildLeaderboardRow, which renders the shared 36px row. So compact is what keeps the drilled-in posts aligned with the authors above them; overlay is what would make them taller than their siblings.

action: href ? { kind: 'link', href } : { kind: 'static' },
} );
return {
label: <LeaderboardPostLabel id={ row.postId } label={ row.label } link={ row.link } />,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the Authors thread — the authors view of this widget renders through buildLeaderboardRow at the shared 36px height, so the posts view matches it at compact. Emails and UTM Insights use overlay because their sibling rows carry padding-block instead.

@Nikschavan
Nikschavan requested a review from chihsuan August 3, 2026 06:12
Adds a postLink action kind to LeaderboardRow, so post titles reuse the shared row chrome instead of a parallel component. LeaderboardPostLabel now only resolves the report window. The row height variant moves to LeaderboardRow.

PostTitleLink renders its router link through the design system link, which supplies the unstyled anchor treatment and the unlayered wp-admin guard. Both component stylesheets are dropped.
Trunk split the Comments widget into two, which dropped this branch's change to the posts view. Ports it onto most-commented-posts: rows render through LeaderboardPostLabel, so a row with a post ID opens the detail page and only a row without one falls back to the permalink.
@Nikschavan
Nikschavan force-pushed the fix/pa-entity-detail-links branch from 2372cc7 to 090abac Compare August 3, 2026 07:35
chihsuan
chihsuan previously approved these changes Aug 3, 2026

@chihsuan chihsuan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Nikschavan Looks good and tested well! 🚢

One small thing, could you update chart-leaderboard/README.md before merging? Thanks!

Covers the new postLink action kind, LeaderboardPostLabel as the widget-level entry point, and the variant and className row props. States that the variant follows the sibling rows in the widget, not the chart's withOverlayLabel prop, which only tints the bar fill.
@github-actions github-actions Bot added the Docs label Aug 3, 2026
@Nikschavan
Nikschavan merged commit 8411533 into trunk Aug 3, 2026
97 of 99 checks passed
@Nikschavan
Nikschavan deleted the fix/pa-entity-detail-links branch August 3, 2026 09:38
@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 labels Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Docs [Package] Premium Analytics [Status] UI Changes Add this to PRs that change the UI so documentation can be updated.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants