Premium Analytics: port Stats Search Terms widget#49985
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! 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. |
Code Coverage SummaryCoverage changed in 1 file.
Coverage check overridden by
Covered by non-unit tests
|
ec5da44 to
ea30566
Compare
…erns (#49987) * Premium Analytics: document widget conventions and Stats porting patterns Consolidates conventions surfaced during code review of the Locations (#49513), Devices (#49928), and Search Terms (#49985) ports into shared agent guidance so future batch ports have a single source of truth. - `.agents/rules/widgets.md` — adds Two-component structure section (outer WidgetRoot / inner useWidgetRootContext, reportParams from context) - `AGENTS.md` — adds package-wide pitfalls (alias naming, English comments) and new Widget pitfalls (presentation source of truth, attribute type locality, button type, inline styles, toolkit helpers); new Stats widgets section covering data hooks, data access path, max=0 semantics, loading strategy, comparison placeholders, and visual conventions - `.agents/skills/widget-audit.md` — extends checklist with presentation consistency, ghost attributes, alias names, WidgetRenderProps<T> import, inline styles, button type, i18n scope, and English comments Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> * changelog: add entry for widget conventions docs update Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> * Premium Analytics: clarify widget guidance * Premium Analytics: refine widget guidance --------- Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…erns (#49987) * Premium Analytics: document widget conventions and Stats porting patterns Consolidates conventions surfaced during code review of the Locations (#49513), Devices (#49928), and Search Terms (#49985) ports into shared agent guidance so future batch ports have a single source of truth. - `.agents/rules/widgets.md` — adds Two-component structure section (outer WidgetRoot / inner useWidgetRootContext, reportParams from context) - `AGENTS.md` — adds package-wide pitfalls (alias naming, English comments) and new Widget pitfalls (presentation source of truth, attribute type locality, button type, inline styles, toolkit helpers); new Stats widgets section covering data hooks, data access path, max=0 semantics, loading strategy, comparison placeholders, and visual conventions - `.agents/skills/widget-audit.md` — extends checklist with presentation consistency, ghost attributes, alias names, WidgetRenderProps<T> import, inline styles, button type, i18n scope, and English comments Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> * changelog: add entry for widget conventions docs update Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> * Premium Analytics: clarify widget guidance * Premium Analytics: refine widget guidance --------- Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
chihsuan
left a comment
There was a problem hiding this comment.
I ran the three stories in Storybook and none of them render the widget with data. We should feeding fixtures.
Also left a few suggestions/questions.
registerReportMocks() covers Woo analytics paths out of the box but not Stats proxy paths (/proxy/v1.1/stats/*). Stats widgets need their endpoint wired into routeStatsReport() in register-report-mocks.ts. Discovered via PR #49985 review feedback. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
chihsuan
left a comment
There was a problem hiding this comment.
Built it locally and all three stories render correctly. Thanks @dognose24 👍
One thing I noticed while reviewing the WidgetDashboardWithWidget story:
When rows exceed the tile height you get a scrollbar instead of the rows fitting the space. Not a regression here. It comes from the shared LeaderboardChart (__content { overflow: auto }), so Top Posts behaves the same. Worth a follow-up at the chart / widgets-toolkit layer so it fixes both widgets in one place. Not blocking.
Followed up on the "widget setting doesn't work" observation, it's not a problem with this widget. Fixed separately in #50070 |
registerReportMocks() covers Woo analytics paths out of the box but not Stats proxy paths (/proxy/v1.1/stats/*). Stats widgets need their endpoint wired into routeStatsReport() in register-report-mocks.ts. Discovered via PR #49985 review feedback. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
accbc9e to
fbc15af
Compare
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Add itemLabel wrapper with padding (mirrors top-platforms pattern) so the overlay bar gets its height from the label element. Pass loading prop and use chart's built-in emptyStateText. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
- widget.ts: add `as const` to attributes type field so it narrows to literal 'integer' rather than string (fixes StoryWidgetMetadata mismatch) - use-search-term-views: cast reportParams to StatsReportParams (same pattern as use-location-views) Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…is source of truth) Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…empty state Remove manual empty/loading early returns that bypassed the header. Use WidgetLoadingOverlay for initial load, and LeaderboardChart's built-in emptyStateText for no-data state (same pattern as top-platforms). Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…with devices) Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Mirrors the top-platforms pattern to guarantee unique React keys. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
- Storybook: add Stats proxy mock handler so stories render real data. registerReportMocks() now intercepts /proxy/v1.1/stats/* in addition to the existing /proxy/v2/analytics/reports/* coverage; adds search-terms fixture data (primary + comparison). - render.tsx: fix JSDoc @param tags (root0 → props); use useMemo<LeaderboardChartData> generic instead of `as` cast. - style.module.css: replace hardcoded 32px/13px with WPDS tokens (--wpds-dimension-size-md / --wpds-typography-font-size-md). Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
registerReportMocks() covers Woo analytics paths out of the box but not Stats proxy paths (/proxy/v1.1/stats/*). Stats widgets need their endpoint wired into routeStatsReport() in register-report-mocks.ts. Discovered via PR #49985 review feedback. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
useStatsSearchTerms already fetches both primary and comparison periods when compare_from/compare_to are present. useSearchTermViews now reads the comparison result, builds a label→views map, and pairs each primary term with its comparison view count. render.tsx uses previousViews for previousValue/previousShare/delta so LeaderboardChart shows trend arrows and sparklines in comparison mode. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
LeaderboardChart requires withComparison={true} to render delta arrows
and previous-period bars. Wire hasComparison from useSearchTermViews.
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Long search terms caused the bar height to grow when the widget was narrow. Add overflow/text-overflow to the label so it ellipsis-clips. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
399ca86 to
31ca743
Compare
…-stats-module-search-terms # Conflicts: # projects/packages/premium-analytics/packages/widgets-toolkit/src/stories/mocks/register-report-mocks.ts
Fixes WOOA7S-1496
Proposed changes
Ports the Jetpack Stats Search Terms module into Premium Analytics as the
jpa/search-termswidget.widgets/search-terms/widget contract (package.json,widget.json,widget.ts,render.tsx,style.module.css, and stories).LeaderboardChartUI.useStatsSearchTermsdata layer, including comparison-aware report params.Default,WithComparison, andWidgetDashboardWithWidgetStorybook stories.Related product discussion/links
Does this pull request change what data or activity we track or use?
No. This reads existing Jetpack Stats search-term data through the existing Premium Analytics stats data layer.
Testing instructions
Run:
In Storybook:
Packages/Premium Analytics/Widgets/SearchTerms.Default,WithComparison, andWidgetDashboardWithWidgetrender correctly.WithComparison.On a Jetpack-connected test site with search-term data: