Skip to content

WOOA7S-1510: Port Stats Latest post widget#50159

Draft
kangzj wants to merge 2 commits into
trunkfrom
add/wooa7s-1510-latest-post
Draft

WOOA7S-1510: Port Stats Latest post widget#50159
kangzj wants to merge 2 commits into
trunkfrom
add/wooa7s-1510-latest-post

Conversation

@kangzj

@kangzj kangzj commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Fixes WOOA7S-1510

Proposed changes

Ports the Jetpack Stats "Latest post" module into a registered Premium Analytics dashboard widget, plus the data-layer support it needs.

  • Widget (widgets/latest-post/): shows the site's most recently published post — title as an external link, publish date, and three metric tiles (Views / Likes / Comments). Framed presentation, no own heading, --wpds-* tokens only, picker-preview aspect-ratio block. Two-component split (WidgetRoot outer + data-connected inner). Three Storybook stories (Default / WithComparison / WidgetDashboardWithWidget).
  • Data hook (useStatsLatestPost): resolves the newest published post, then composes its all-time views from the existing proxied useStatsPost query. Adds the latest-post normalizer (+ fixtures/tests) and the query.

Fetching the posts list

The WPCOM posts endpoint is public, so the latest-post query calls it directly — plain fetch, no proxy and no blog token:

GET https://public-api.wordpress.com/rest/v1.1/sites/<blogId>/posts/?number=1&status=publish&order_by=date&order=DESC&fields=ID,title,URL,date,like_count,discussion

<blogId> is resolved from the dashboard's client-side site data (@automattic/jetpack-script-datagetSiteData()?.wpcom?.blog_id), so there is no change to the proxy controller (class-api-proxy-controller.php) and no new PREFIX_CONFIG entry. All-time views still come from the existing proxied stats/post/<id> endpoint via useStatsPost (unchanged). like_count and discussion.comment_count come straight from the posts response.

WithComparison renders identically to Default — the metrics are lifetime totals, so the module has no comparison period (documented in the story).

Related product discussion/links

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

No. It reads existing published-post data (public posts endpoint + already-proxied post views) for display only.

Testing instructions

  • Storybook: run the dashboard Storybook and open Packages / Premium Analytics / Widgets / LatestPost. The Default, WithComparison, and WidgetDashboardWithWidget stories should render a populated card (title, date, and Views / Likes / Comments tiles). The public posts endpoint is stubbed via window.fetch and views via an apiFetch middleware.
  • Live-dashboard verification pending — handled centrally.

Add the "Latest post" Premium Analytics widget showing the site's most
recently published post with its all-time views, likes, and comments.

- Data: a `useStatsLatestPost` hook that fetches the public WPCOM posts
  endpoint directly (plain fetch, no proxy and no blog token), resolving the
  blog ID from the dashboard's client-side site data, then composes the
  post's all-time views from the existing proxied `useStatsPost` query. Adds
  the latest-post normalizer + fixtures/tests and the direct-fetch query.
- Widget: `widgets/latest-post/` renders the post title (external link),
  publish date, and Views / Likes / Comments metric tiles, with a
  three-story Storybook file (public posts endpoint stubbed via window.fetch).
@github-actions

github-actions Bot commented Jul 2, 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 2, 2026
@jp-launch-control

Copy link
Copy Markdown

Code Coverage Summary

This PR did not change code coverage!

That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷

Full summary · PHP report

Rename latest-post.module.css to style.module.css (post-#50112 convention)
and correct the normalizer docblock to reference the public WPCOM posts
endpoint rather than the proxy, since this widget fetches it directly.
@kangzj

kangzj commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Live dashboard verification — Latest post

Rendered on the connected Premium Analytics dashboard (Insights tab, raven env, blog 254382195) with real data and zero console errors.

Latest post

@kangzj kangzj marked this pull request as ready for review July 2, 2026 07:35
@kangzj kangzj requested review from a team as code owners July 2, 2026 07:35
@kangzj kangzj marked this pull request as draft July 2, 2026 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Premium Analytics [Status] In Progress [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant