Premium Analytics: add Top posts & pages widget to Storybook - #49735
Conversation
|
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. 🤷 |
Add a prop-driven TopPostsWidget and Storybook story under Packages/Premium Analytics/Widgets/TopPosts, mimicking the "Top posts & pages" widget from #49568 as a self-contained, mock-data-backed component. The widget renders the most-viewed posts/pages as an overlay leaderboard (each row links to the published content) and supports previous-period comparison with colored deltas, mirroring the overlay comparison mode of the toolkit's LeaderboardChart. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CpN9Z3MTaLb4GxTNsGFaEQ
… story Replace the duplicated ChartThemeProvider + withChartTheme in the Top Posts widget story with the canonical decorator from the widgets-toolkit. Behavior is identical. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CpN9Z3MTaLb4GxTNsGFaEQ
…root Relocate widgets/ from premium-analytics/packages/widgets to premium-analytics/widgets. Update the story's relative import to the toolkit decorator, add widgets/**/* to the package tsconfig include, and register the new path in the Storybook projects list so stories are still discovered. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CpN9Z3MTaLb4GxTNsGFaEQ
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CpN9Z3MTaLb4GxTNsGFaEQ
739d2b9 to
05eb446
Compare
In overlay-label mode the bar should read as a faint tint of the primary color so the label stays legible on top of it. We were passing `hexToRgba( primary, 0.08 )` to the chart's `primaryColor` prop, but that prop resolves through getElementStyles, which strips the alpha channel — so the bar rendered at full primary color and the intended fade never appeared. Pre-blend the primary with white instead, producing the opaque equivalent of an 8% alpha fill via charts' own `lightenHexColor` (`normalizeColorToHex` first so non-hex theme colors are handled). The result is opaque, so nothing gets stripped, and it still tracks the themed primary. Top Posts and any other consumer of this shared component inherit the fix automatically. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MtarPnJhd516aUvykDVubW
acb8e27 to
0ec43f8
Compare
kangzj
left a comment
There was a problem hiding this comment.
I don't see any blocking issue. Happy for it to ship and iterate 👍
Address review feedback on the Top posts & pages widget: - The Loading story rendered the empty state instead of loading. The toolkit LeaderboardChart short-circuits empty data to ChartEmptyState before the loading prop reaches the base chart, so loading+empty never showed a spinner. Render WidgetLoadingOverlay directly for the initial loading-with-no-data case (matching the sibling leaderboard widgets), and let the chart own the empty state via emptyStateText. - Export WidgetLoadingOverlay from the widgets-toolkit public entry so consumers outside the toolkit can reuse it. - Use a plain "&" in the changelog entry instead of "&". Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01X6csUCvWX89ymfNSHGMXYv
|
@kangzj I addressed your feedback, this should be good for a re-review |
Nvm, I thought a re-review was needed. Given the changes are minimal, I merged it. |
Summary
Adds a prop-driven Top posts & pages widget and its Storybook story under Packages → Premium Analytics → Widgets → TopPosts (not under Widgets Toolkit), mimicking the widget from #49568 as a self-contained, mock-data-backed component so it can be browsed/tested in the Jetpack Storybook.
It is purely presentational: it takes already-fetched rows via props and renders the loading, error, empty, and populated states.
What's included
widgets/top-posts/in thepremium-analyticspackage:types.ts—TopPostRow(with optionalpreviousValue)top-posts-widget.tsx—TopPostsWidget, rendering the most-viewed posts/pages as an overlay leaderboard (each row links to the published content)top-posts-widget.module.css— label-link stylingindex.ts— public exportsstories/top-posts-widget.stories.tsx— story with mock posts/pages rowsStories
Default, WithComparison, Loading, NoViews, ErrorState, LongLabels, SizeMedium, SizeLarge.
Notes
LeaderboardChart(shares +calculateDelta).padding-inline-start) to match the chart's default overlay.label, since a custom label element bypasses that rule.typecheckpasses andstorybook buildsucceeds with the story present in the built index.Does this pull request change what data or activity we track or use?
No
Testing instructions
This story lives in the shared Jetpack Storybook. To browse it locally:
pnpm install). Node^24.15.0is required.cd projects/js-packages/storybook pnpm run storybook:dev🤖 Generated with Claude Code