WOOA7S-1510: Port Stats Latest post widget#50159
Draft
kangzj wants to merge 2 commits into
Draft
Conversation
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).
Contributor
|
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! |
Code Coverage SummaryThis 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. 🤷 |
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.
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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.
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 (WidgetRootouter + data-connected inner). Three Storybook stories (Default / WithComparison / WidgetDashboardWithWidget).useStatsLatestPost): resolves the newest published post, then composes its all-time views from the existing proxieduseStatsPostquery. 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:<blogId>is resolved from the dashboard's client-side site data (@automattic/jetpack-script-data→getSiteData()?.wpcom?.blog_id), so there is no change to the proxy controller (class-api-proxy-controller.php) and no newPREFIX_CONFIGentry. All-time views still come from the existing proxiedstats/post/<id>endpoint viauseStatsPost(unchanged).like_countanddiscussion.comment_countcome straight from the posts response.WithComparisonrenders identically toDefault— 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
Default,WithComparison, andWidgetDashboardWithWidgetstories should render a populated card (title, date, and Views / Likes / Comments tiles). The public posts endpoint is stubbed viawindow.fetchand views via anapiFetchmiddleware.