Widgets: conform Woo-family render props to WidgetRenderProps<T> contract#50113
Widgets: conform Woo-family render props to WidgetRenderProps<T> contract#50113chihsuan wants to merge 3 commits into
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. 🤷 |
There was a problem hiding this comment.
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.tsxto useWidgetRenderProps<T>(with composed report-param attributes), defaultattributes = {}, and standardize optionalsetError. - Add
@wordpress/widget-primitivesto 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. |
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.widget.tsnow exports an attribute type (Record< string, never >, mirroringsubscribers-chart) since these widgets expose no configurable attributes.render.tsxtypes props asWidgetRenderProps< T > & { setError? }— composing the widget attribute type withPartial< ReportParamsFieldAttributes >— and defaultsattributes = {}. Previously each hand-rolled its own props shape (five different variants) and leftattributesundefaulted.average-items-per-ordernow acceptssetErrorfor parity with its siblings.@param/@returntags that only echoed the TypeScript types, keeping the descriptive summary.@wordpress/widget-primitivesto each widget'sdependencies.No runtime or behavior change. Widget metadata (
widget.json/widget.tstitle/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
pnpm --filter @automattic/jetpack-premium-analytics typecheckand lint the changed widgets — both pass clean.reportParamsthroughattributes.