Skip to content

Premium Analytics: link Most viewed post titles through the router - #50891

Merged
Nikschavan merged 4 commits into
trunkfrom
fix/top-posts-router-navigation
Jul 30, 2026
Merged

Nikschavan merged 4 commits into
trunkfrom
fix/top-posts-router-navigation

Conversation

@Nikschavan

@Nikschavan Nikschavan commented Jul 29, 2026 •

Copy link
Copy Markdown
Member

Fixes WOOA7S-1826

Proposed changes

  • The Most viewed widget linked post titles with a plain href that encoded the SPA path in the p query param. A click reloaded wp-admin and restarted the whole dashboard. Every other surface in the package navigates through the router.
  • Add a PostTitleLink toolkit component, modelled on the existing VideoTitleLink. A row with a post ID gets a router link to /post/{id}. A row without one falls back to the public URL and takes the external-link icon. Anything else stays plain text.
  • Internal links no longer carry the external-link icon. The icon now marks only destinations that leave the app, which is the rule the rest of the package already follows.
  • Use the component in the Most viewed widget and in the Posts & pages report. The report link previously passed no search, so opening a post detail page reset the selected date range to defaults. The shared component carries the range.
  • Add a View post action to the post detail page header — a primary button in the same header slot the reports use for Download and the dashboard uses for Customize. The lists that link there no longer carry their own outbound link, so this is now the only path from the dashboard to the live post. It renders as an anchor to keep a real href, with nativeButton={ false } and role="link" so it does not announce as a button.
  • Remove usePostDetailHrefBuilder. It existed to avoid router context, but the widget already renders a router link through ReportLink, so that property was gone before this change.

Related product discussion/links

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

No.

Testing instructions

  • Build Premium Analytics and open the analytics dashboard.
  • In the Most viewed widget, keep the Posts & pages view and click a post title. The post detail page opens without a full page reload, and the date range stays the same. The row shows no external-link icon.
  • Switch the widget to Archives and drill into a group, for example Searches. Leaf rows open the archive page in a new tab and keep the external-link icon. Group rows still drill down.
  • On the post detail page, click the View post button in the page header. The live post opens in a new tab. A page shows View page instead. The button should match the Download button on the report pages.
  • Open the Posts & pages report. Click a post title. Navigation stays in the app and the date range is preserved. The Homepage (Latest posts) row opens the site home in a new tab.
  • Change the dashboard date range first, then click a title from either surface. The detail page opens on that range, not on the default one.

The Most viewed widget linked post titles with a plain href. The href carried the SPA path in the p query param. A click reloaded wp-admin and restarted the whole dashboard.

Add PostTitleLink to the widgets toolkit. A row with a post ID gets a router link to the post detail page. A row without one falls back to the public URL and takes the external icon. Other rows stay plain text. An internal link carries no icon, because the icon marks a destination outside the app.

Use the component in the Most viewed widget and in the Posts and pages report. The report link dropped the report window before this change, so the detail page reseeded default dates.

Add a View post link to the post detail header. The lists that link there now carry no outbound link, so this link is the only path to the live post.

Delete usePostDetailHrefBuilder. The widget was its only caller.
@Nikschavan Nikschavan self-assigned this Jul 29, 2026
@github-actions

github-actions Bot commented Jul 29, 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/top-posts-router-navigation branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/top-posts-router-navigation
bin/jetpack-downloader test jetpack-mu-wpcom-plugin fix/top-posts-router-navigation

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 29, 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 29, 2026
@jp-launch-control

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

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 4 files.

File Coverage Δ% Δ Uncovered
projects/packages/premium-analytics/routes/reports/posts/config/fields.tsx 52/56 (92.86%) -0.36% 0 💚
projects/packages/premium-analytics/widgets/top-posts/render.tsx 77/95 (81.05%) -0.58% 0 💚
projects/packages/premium-analytics/routes/post-detail/hooks/use-post-summary.ts 30/31 (96.77%) 96.77% -12 💚
projects/packages/premium-analytics/routes/post-detail/stage.tsx 20/23 (86.96%) 86.96% -19 💚

2 files are newly checked for coverage.

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

Full summary · PHP report · JS report

The View post link sat inside the summary card. Move it to the Page actions slot, the same header position that reports use for Download and the dashboard uses for Customize.

Match the Download button treatment: solid variant, neutral tone, compact size, and no icon. The button renders as an anchor, so it keeps a real href to the live post.

wp-admin colours bare anchors outside any cascade layer, and the @wordpress/ui button styles live inside layer wp-ui. Unlayered rules beat layered rules whatever the specificity, so the admin link colour overrode the button foreground. Restore the button colour from the page stylesheet.
@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 29, 2026
The coverage bot flagged the post summary hook: the new public-URL selector added six uncovered lines to a file at zero coverage. The page stage had no test at all, so the header action was uncovered too.

Add tests for usePostSummary and for the page stage, following the video detail stage test. The hook reaches full coverage, and the stage reaches 83 percent of statements.

The stage test found two defects in the header action. Base UI logged a console error, because a button rendered as an anchor needs nativeButton set to false. With that set, Base UI then marked the anchor with a button role, so a screen reader announced a button for an element that opens a new tab. Set an explicit link role to match the behaviour.
@Nikschavan
Nikschavan marked this pull request as ready for review July 29, 2026 11:44
@Nikschavan
Nikschavan requested a review from a team July 29, 2026 11:44
@Nikschavan
Nikschavan requested a review from a team as a code owner July 29, 2026 11:44

@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 for the thorough fix! @Nikschavan

I left three inline comments about regressions or edge cases worth addressing:

  • Preserve ellipsis behavior for drill-down rows with long labels.
  • Keep a fallback path to the live post when core-data cannot resolve a post type, particularly CPTs with show_in_rest: false.
  • Add report-specific layout styles for external-link icons.

Once those are resolved, this should be good to go.

@Nikschavan
Nikschavan merged commit 8523e90 into trunk Jul 30, 2026
86 checks passed
@Nikschavan
Nikschavan deleted the fix/top-posts-router-navigation branch July 30, 2026 07:15
@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 Jul 30, 2026
href={ href }
variant="unstyled"
openInNewTab
rel="noopener noreferrer"

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.

BTW just a nit but you don't need to add these in modern browsers anymore. Link and ExternalLink components don't add them anymore either in Gutenberg.

Comment on lines +40 to +47
// The header action is a Button rendered as an anchor, so it can carry a real
// href to the live post. @wordpress/ui styles the button inside `@layer wp-ui`,
// and wp-admin colours bare anchors outside any cascade layer — unlayered wins
// over layered whatever the specificity, so admin's link blue overrode the
// button foreground. Re-apply the button's own colour from here (unlayered).
.viewPost:any-link {
color: var(--wp-ui-button-foreground-color);
}

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.

Would this be fixed by latest WP dependencies update or is this some kind of bug we should look into at UI library? It looks like an odd fix to need to do here.

What it kinda sounds is happening that you have Button with href, and you can now replace that with the new LinkButton component, and solve odd bugs like these.

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.

Right, this is an anchor inside a Button, so LinkButton will be the right fit. After the dependency bump in #50509, I will do a follow-up PR to remove this override and use the LinkButton, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[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