Repository navigation
Stats: Add a "View in new tab" row action to the Posts & pages and Emails reports - #54058
Conversation
… row Classic Stats gave each post row two ways in: the title opened the post's stats and a "View" action opened the live post. Stats v2 rows with a post ID opened the stats page only. `ViewLiveLink` is the trailing action, and `LeaderboardRow` renders it beside the title whenever a row has both a detail page and a public URL; `MetricList` takes it as a row `action` for the Emails widget. It shows on hover and focus, and stays visible where there is no hover. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Resolves the conflicts with #54017, which gates post detail links on `isPostDetailAvailable()` and puts post-row media inside the title link. - Changelog: move the plugin entry from wpcomsh, which does not bundle Premium Analytics, to plugins/jetpack and plugins/premium-analytics. - Emails: show the "View" action only beside a title that opens the email's stats, so a row without a post ID keeps one link and a row without a URL leaves no gap. - Leaderboard rows: keep the `title` tooltip on the title link, so the arrow shows only "View". A reader who cannot open post details gets the title linked out with no arrow, via the shared `toPostDetailId()`. - Metric list: scope the label link styles to `.labelText`, so the arrow keeps the toolkit colour. - Docs: update `LeaderboardPostLabel` and the chart-leaderboard README. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. Premium Analytics plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Code Coverage SummaryCoverage changed in 2 files.
1 file is newly checked for coverage.
|
…email row in the reports Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
b203605 to
f33a383
Compare
…rline Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…nk' into add/stats-report-rows-view-live-action
…and log the change against the plugins that ship it Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
6e924e8 to
160133b
Compare
Nikschavan
left a comment
There was a problem hiding this comment.
Thank you for carrying the "View" action over to the reports. I left three notes inline. The one about the Posts gate test is the one I would like to see addressed before this merges, and the other two are fine as follow-ups once #53996 settles.
| /> | ||
| ); | ||
|
|
||
| if ( isHomepage || toPostDetailId( item.id ) === undefined ) { |
There was a problem hiding this comment.
This gate can be replaced with if ( false ) and the posts suite stays green. The homepage fixture has link: null and id: 0, so the new toHaveLength( 1 ) in fields.test.tsx#L187 holds with or without it. The case this commit is for, a reader who cannot open post details, is not reachable in the file, because isPostDetailAvailable is mocked to true at L19. A row with an ID and a public URL, rendered with that mock returning false and expected to show one link, would cover it.
There was a problem hiding this comment.
Addressed in b393dad: the gate moved into ReportTitleCell, which asks toViewLiveUrl() from #53996, and the Posts suite now renders a row with both an ID and a link for a reader who cannot open post details and expects a single link. Removing the gate fails that test with two links, and if ( false ) fails the "offers the live post" test beside it.
There was a problem hiding this comment.
Gone with 191bec8: the reports no longer render a title-cell link, so this gate and its fixture are out. The row action is gated by toViewLiveUrl() alone, and the Posts page test asserts the homepage row is not eligible.
| ReportThumbnail, | ||
| REPORT_TITLE_LINK_CLASS_NAMES, | ||
| ReportTitleCell, | ||
| type ReportTitleCellProps, |
There was a problem hiding this comment.
Nothing outside the toolkit imports ReportTitleCellProps; the three reports only render ReportTitleCell. The package's AGENTS.md asks for root exports only when an outside import needs them, types included. Is there a consumer planned that needs the props type?
There was a problem hiding this comment.
Dropped in b393dad. Only ReportTitleCell leaves the root now.
There was a problem hiding this comment.
ReportTitleCell is gone as of 191bec8, along with its props type and the toDetailId export, so nothing is left to narrow.
| > | ||
| { title } | ||
| </PostDetailLink> | ||
| <ReportTitleCell liveUrl={ typeof item.link === 'string' ? item.link : null } label={ title }> |
There was a problem hiding this comment.
Each report chooses its own "View" gate: Posts checks toPostDetailId() at posts/config/fields.tsx#L82, Videos checks toDetailId() at videos/config/fields.tsx#L83, and this one checks only for a missing ID at L67, while the Emails widget uses toPostDetailId(). If #53996 gains the single helper for the live URL, ReportTitleCell could take the row's ID and URL and call it, so the three reports and the widgets cannot disagree and toDetailId would not need a root export. Fine as a follow-up after the parent settles.
There was a problem hiding this comment.
Just a thought: could PostTitleLink / VideoTitleLink render "View" themselves, behind a prop? They already decide the detail link, and the route gate drifted once (160133b).
There was a problem hiding this comment.
Done in b393dad along those lines: ReportTitleCell takes the row's content kind, ID and public URL and calls toViewLiveUrl(), so the three reports and the widgets share one rule and toDetailId is no longer a root export.
@chihsuan I kept the action in the cell rather than behind a prop on PostTitleLink / VideoTitleLink: the Emails report renders PostDetailLink, not PostTitleLink, and the widgets place the action from the leaderboard row, so the cell is the one place every report goes through.
There was a problem hiding this comment.
Resolved in 191bec8 the way you suggested: the three reports now hand toViewLiveUrl() the row kind, ID and URL and pass the result to one createViewLiveAction(), so there is a single gate shared with the widgets and no per-report copy.
# Conflicts: # projects/packages/premium-analytics/packages/widgets-toolkit/src/components/index.ts
… out of a row Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
chihsuan
left a comment
There was a problem hiding this comment.
Nice work bringing "View" to the reports! @dognose24 Hover and title links work well on my test site. 👍 A few inline notes below.
| <InternalLink | ||
| to="/video/$videoId" | ||
| params={ { videoId: String( videoId ) } } | ||
| search={ getVideoDetailSearch } | ||
| ariaLabel={ getVideoTitle( item ) } | ||
| > | ||
| { thumbnail } | ||
| </InternalLink> |
There was a problem hiding this comment.
Could we check the poster with a mouse? Clicking it does nothing, since DataViews' ::after overlay covers the link (what #53011 fixed). Its focus ring is also clipped.
There was a problem hiding this comment.
Good catch, thanks. On trunk DataViews rendered the row link itself, so the anchor was the media wrapper and the overlay sat on it. With the title now carrying two links, the poster link renders inside the wrapper, under DataViews' ::after.
Fixed in ed6ec80 in the records table's stylesheet: the overlay gets pointer-events: none, and the link fills the wrapper and draws its focus ring inset, as @wordpress/ui does in its own clipped containers. Tests, lint and types pass; I have not clicked it on a live site yet, so a second look there is welcome.
There was a problem hiding this comment.
This went away with the approach: design asked for a DataViews row action instead of a link beside the title (191bec8), so the Videos report keeps the row link it had on trunk and the poster is back inside it, with no overlay to fight.
| renderVideosField( 'poster', video ); | ||
|
|
||
| const link = screen.getByRole( 'link', { name: 'Launch video' } ); | ||
| expect( getMockRouteLinkUrl( link ).pathname ).toBe( '/video/12' ); |
There was a problem hiding this comment.
Should this assert the date window too? Removing search from VideoPoster keeps the suite green.
| expect( getMockRouteLinkUrl( link ).pathname ).toBe( '/video/12' ); | |
| const url = getMockRouteLinkUrl( link ); | |
| expect( url.pathname ).toBe( '/video/12' ); | |
| expect( Object.fromEntries( url.searchParams ) ).toEqual( { | |
| from: '2026-06-01', | |
| to: '2026-06-16', | |
| interval: 'day', | |
| ref: 'videos', | |
| } ); |
There was a problem hiding this comment.
The poster link and this test are gone in 191bec8; the Videos report keeps its trunk row link, whose date window is covered by the existing page test.
| } | ||
|
|
||
| return ( | ||
| <ReportTitleCell liveUrl={ item.link } label={ title }> |
There was a problem hiding this comment.
Could we fall back to Untitled here, like Top posts? An untitled post names this arrow View "" in a new tab.
There was a problem hiding this comment.
Done in ed6ec80: the Posts report falls back to Untitled as Top posts does, with a test that the title and its "View" action both carry it.
There was a problem hiding this comment.
No longer applies: the row action is labelled "View in new tab" for every row (191bec8), so an untitled post has nothing to name. The Posts report title itself is unchanged from trunk.
`toViewLiveUrl()` returns the live URL a row's "View" action opens, or undefined when the row's title already links out or the URL is unsafe, so the leaderboard, the Emails widget and the link itself no longer each spell the rule. `toPostDetailId` goes back to being internal to the toolkit. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
`ReportTitleCell` now takes the row's content kind, ID and public URL and asks `toViewLiveUrl()` whether the row gets the action, so the Posts, Videos and Emails reports share one gate with the widgets instead of each writing their own. The Posts gate is covered for a reader who cannot open post details. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…ed post in its "View" action DataViews draws the media border on an overlay above the cell, which swallowed clicks on the poster link the Videos report renders inside the wrapper and clipped its focus ring. The Posts report now names an untitled post "Untitled", as Top posts does, so its "View" action no longer reads `View ""`, and the poster test asserts the date window the link carries. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
chihsuan
left a comment
There was a problem hiding this comment.
Thanks for the updates! @dognose24 LGTM 🚀 Just one small nit inline.
| fallbackIcon={ videoIcon } | ||
| /> | ||
| ); | ||
| const videoId = toDetailId( item.id ); |
There was a problem hiding this comment.
nit: Could the poster reuse VideoTitleLink with the thumbnail as children, like LeaderboardRow does? That way the poster and title share one detail-page check, and toDetailId could stay internal. It's still exported from the root index.ts, by the way.
There was a problem hiding this comment.
Done in a55e530: the poster now renders VideoTitleLink around the thumbnail, so it follows the title into the detail page, or out to the live video on rows without one, and toDetailId is no longer exported from the toolkit. One thing to note: with the thumbnail decorative, the outbound marker alone would have named the external link, so the poster carries a visually hidden copy of the title as the standard image-link pattern.
There was a problem hiding this comment.
Superseded by 191bec8: the poster no longer carries its own link, so there is nothing to share with VideoTitleLink, and toDetailId is no longer exported.
The poster now renders `VideoTitleLink` around the thumbnail, as the leaderboard rows do, so the poster and the title share one detail-page check and follow each other to the live video on rows without one. That leaves `toDetailId` with no caller outside widgets-toolkit, so it is no longer exported. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
# Conflicts: # projects/packages/premium-analytics/packages/widgets-toolkit/src/components/chart-leaderboard/__tests__/leaderboard-row.test.tsx # projects/packages/premium-analytics/packages/widgets-toolkit/src/components/chart-leaderboard/leaderboard-row.tsx # projects/packages/premium-analytics/packages/widgets-toolkit/src/components/view-live-link/view-live-link.module.scss # projects/packages/premium-analytics/packages/widgets-toolkit/src/components/view-live-link/view-live-link.tsx
Design asked for the reports to keep row actions in DataViews' actions column rather than beside the title, where the arrow read like the new-tab marker a linked-out title carries. The three reports now pass a primary "View in new tab" action that opens the row's public URL, gated by `toViewLiveUrl()` so they share the widgets' one rule. The report title cell, the poster link and the toolkit exports that only served them go. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
A primary action draws its label on the row, which crowds the metric columns. The action now lives in the row's actions menu, where the Referrers report keeps "Mark as spam…". Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Heads-up for a fresh look: this PR changed approach after design feedback on STATS-552.
The description and testing instructions are rewritten for the new shape. |
chihsuan
left a comment
There was a problem hiding this comment.
Thanks for reworking this around the row menu! @dognose24 I tried Posts & pages and Emails, and View in new tab opens the live post nicely. 👍 I left a few inline notes, mostly about the Videos table.
| isFetching={ records.isFetching } | ||
| initialView={ RECORDS_VIEW } | ||
| searchLabel={ __( 'Search videos', 'jetpack-premium-analytics-pkg' ) } | ||
| actions={ actions } |
There was a problem hiding this comment.
Good catch, thanks. Done in 1a909e5: the Videos page is back to trunk, with no actions prop, so no sticky column. The PR title, description and changelogs now name only Posts & pages and Emails, and the testing instructions include a narrow-window check that Retention rate stays uncovered.
| const actions = useMemo( | ||
| () => [ | ||
| createViewLiveAction< StatsVideoPlaysComparisonItem >( video => | ||
| toViewLiveUrl( 'video', video.id, video.link ) |
There was a problem hiding this comment.
Heads-up rather than a change request: without complete_stats, the endpoint's video url is the wp-admin/media.php?action=edit link, not the public page. When the summary gains a URL, could we make sure it's the permalink? The Storybook mock also sends url here, so stories show an action production won't.
There was a problem hiding this comment.
Noted, and recorded in the PR description so it is there when the endpoint changes: the Videos page should only pass the action once the summary sends the permalink, not the media.php edit link. I left the Storybook mock alone for now since the page no longer reads url.
There was a problem hiding this comment.
Opened STATS-567 for the endpoint: both shapes of stats/video-plays should send the public permalink as url. The PR description links it.
| mockEmailSummary(); | ||
|
|
||
| render( <EmailsReportPage /> ); | ||
| await userEvent.click( screen.getByRole( 'button', { name: 'Actions' } ) ); |
There was a problem hiding this comment.
nit: Should this test use fake timers? findByRole polls like waitFor, and the package AGENTS.md asks for jest.useFakeTimers() with userEvent.setup( { advanceTimers: jest.advanceTimersByTime } ) there.
There was a problem hiding this comment.
Right, that is what the package AGENTS.md asks for. The Emails test now runs on jest.useFakeTimers() with userEvent.setup( { advanceTimers: jest.advanceTimersByTime } ) (1a909e5).
| expect( | ||
| action?.isEligible?.( { | ||
| id: 0, | ||
| label: 'Home page', | ||
| views: 3, | ||
| link: 'https://example.com/', | ||
| type: 'homepage', | ||
| } ) | ||
| ).toBe( false ); |
There was a problem hiding this comment.
nit: Would it be worth dropping the homepage case here? The page has no homepage logic of its own, so this only fails if toViewLiveUrl() regresses, which view-live-url.test.ts already covers. Same for the id: undefined case in the Videos test.
There was a problem hiding this comment.
Agreed. The homepage case is gone from the Posts test, which now only checks that the page wires the action in and that a plain row is eligible; the Videos test went away with the action (1a909e5).
…sends a video URL DataViews renders the sticky Actions column even when no row is eligible, so an empty one covered Retention rate in a narrow window. The Posts and Emails page tests now leave `toViewLiveUrl()`'s own cases to its unit test, and the Emails one drives the menu on fake timers. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

Part of STATS-552. Follows #53996, which added the "View" action to widget rows.
Proposed changes
Classic Stats let people open the live post from any row of a report. In Stats v2 the Posts & pages and Emails reports link each row's title to its stats detail page only, so reaching the live post takes a second click from there.
This PR gives those two report tables a DataViews row action, View in new tab, that opens the row's public URL in a new tab. Design asked for this over an icon beside the title (STATS-552): the Referrers report already keeps its row actions in DataViews' actions column, and an arrow next to a title that stays in the dashboard reads like the new-tab marker a linked-out title carries.
createViewLiveAction()builds the action once for both reports. It sits in the row's ⋮ actions menu, where the Referrers report keeps "Mark as spam…", so the tables offer their actions in one place.toViewLiveUrl()from Stats: Add a "View" action that opens the live post from every widget row #53996, so the reports share the widgets' one gate: a title that opens a detail page the reader can reach, and a URL with an http(s) scheme. The homepage row, the Archives tab and rows that link out from their title get no action, as before.complete_stats=1) returns no URL for a video, and DataViews still renders the sticky Actions column when no row is eligible, so an empty column would cover Retention rate in a narrow window. Once the endpoint sends the video's permalink (not thewp-admin/media.phpedit link the non-summary response carries), the Videos page can pass the same action. STATS-567 tracks that endpoint change.Related product discussion/links
stats/video-playsURL the Videos report waits on)Does this pull request change what data or activity we track or use?
No.
Screenshots
Posts & pages, with a row's ⋮ menu open: "View in new tab" opens the live post, the title still opens its stats.
Testing instructions
On a Jetpack site with Premium Analytics, open the Stats dashboard.
🤖 Generated with Claude Code