Skip to content

Widgets: conform Woo-family render props to WidgetRenderProps<T> contract#50113

Open
chihsuan wants to merge 3 commits into
trunkfrom
wooa7s-1641-widgets-conform-woo-family-render-props-to
Open

Widgets: conform Woo-family render props to WidgetRenderProps<T> contract#50113
chihsuan wants to merge 3 commits into
trunkfrom
wooa7s-1641-widgets-conform-woo-family-render-props-to

Conversation

@chihsuan

@chihsuan chihsuan commented Jul 1, 2026

Copy link
Copy Markdown
Member

Fixes WOOA7S-1641

Proposed changes

Part of the Premium Analytics widget consistency cleanup (WOOA7S-1640). Type-only refactor of the five woocommerce-analytics-ported widgets (average-items-per-order, bookings-by-device, payment-status, sales-by-utm-channel, visitors-over-time) to follow the render-component contract in .agents/rules/widgets.md.

  • Each widget.ts now exports an attribute type (Record< string, never >, mirroring subscribers-chart) since these widgets expose no configurable attributes.
  • Each render.tsx types props as WidgetRenderProps< T > & { setError? } — composing the widget attribute type with Partial< ReportParamsFieldAttributes > — and defaults attributes = {}. Previously each hand-rolled its own props shape (five different variants) and left attributes undefaulted.
  • average-items-per-order now accepts setError for parity with its siblings.
  • Trimmed the render-function doc comments to the minimal house style: removed the @param/@return tags that only echoed the TypeScript types, keeping the descriptive summary.
  • Added @wordpress/widget-primitives to each widget's dependencies.

No runtime or behavior change. Widget metadata (widget.json / widget.ts title/description) is intentionally left untouched — that reconciliation is held for WordPress/gutenberg#79701.

Related product discussion/links

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

No. Type-only refactor; no data collection, tracking, or runtime behavior changes.

Testing instructions

  • From the repo root, run pnpm --filter @automattic/jetpack-premium-analytics typecheck and lint the changed widgets — both pass clean.
  • In Storybook, open each of the five widgets (Average items per order, Bookings by device, Payment status, Sales by UTM channel, Visitors over time) and confirm the Default and WithComparison stories render exactly as before — they still pass reportParams through attributes.
@github-actions

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

jp-launch-control Bot commented Jul 1, 2026

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Aligns the five WooCommerce-analytics-ported Premium Analytics widgets with the established widget render-props contract, reducing drift vs the existing Stats-family widgets and making the widgets’ render entry points consistently typed.

Changes:

  • Export explicit “no configurable attributes” attribute types from each widget’s widget.ts.
  • Update each widget’s render.tsx to use WidgetRenderProps<T> (with composed report-param attributes), default attributes = {}, and standardize optional setError.
  • Add @wordpress/widget-primitives to each affected widget package and add a Premium Analytics changelog entry.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
projects/packages/premium-analytics/widgets/visitors-over-time/widget.ts Adds exported attributes type for the widget (no configurable attributes).
projects/packages/premium-analytics/widgets/visitors-over-time/render.tsx Refactors render props typing to WidgetRenderProps<T>, composes report params, defaults attributes.
projects/packages/premium-analytics/widgets/visitors-over-time/package.json Adds @wordpress/widget-primitives dependency.
projects/packages/premium-analytics/widgets/sales-by-utm-channel/widget.ts Adds exported attributes type for the widget (no configurable attributes).
projects/packages/premium-analytics/widgets/sales-by-utm-channel/render.tsx Refactors render props typing to WidgetRenderProps<T>, composes report params, defaults attributes, normalizes JSDoc usage.
projects/packages/premium-analytics/widgets/sales-by-utm-channel/package.json Adds @wordpress/widget-primitives dependency.
projects/packages/premium-analytics/widgets/payment-status/widget.ts Adds exported attributes type for the widget (no configurable attributes).
projects/packages/premium-analytics/widgets/payment-status/render.tsx Refactors render props typing to WidgetRenderProps<T>, composes report params, defaults attributes.
projects/packages/premium-analytics/widgets/payment-status/package.json Adds @wordpress/widget-primitives dependency.
projects/packages/premium-analytics/widgets/bookings-by-device/widget.ts Adds exported attributes type for the widget (no configurable attributes).
projects/packages/premium-analytics/widgets/bookings-by-device/render.tsx Refactors render props typing to WidgetRenderProps<T>, composes report params, defaults attributes.
projects/packages/premium-analytics/widgets/bookings-by-device/package.json Adds @wordpress/widget-primitives dependency.
projects/packages/premium-analytics/widgets/average-items-per-order/widget.ts Adds exported attributes type for the widget (no configurable attributes).
projects/packages/premium-analytics/widgets/average-items-per-order/render.tsx Refactors render props typing to WidgetRenderProps<T>, composes report params, defaults attributes, adds optional setError pass-through.
projects/packages/premium-analytics/widgets/average-items-per-order/package.json Adds @wordpress/widget-primitives dependency.
projects/packages/premium-analytics/changelog/wooa7s-1641-widgets-conform-woo-render-contract Adds changelog entry for the typing/contract conformance work.
@chihsuan chihsuan marked this pull request as ready for review July 1, 2026 09:20
@chihsuan chihsuan requested review from a team as code owners July 1, 2026 09:20
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.

2 participants