Premium Analytics: port the Average items per order widget#49505
Premium Analytics: port the Average items per order widget#49505nerrad wants to merge 2 commits into
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
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. |
d922903 to
74722f2
Compare
91aa9fb to
909996e
Compare
74722f2 to
4538b65
Compare
Follow-up: the
|
909996e to
d060b2d
Compare
d060b2d to
5bb6dd9
Compare
Port the Average items per order widget from next-woocommerce-analytics (woocommerce/woocommerce-analytics@develop) into the Premium Analytics customizable dashboard (WOOA7S-1460). The widget is a thin composition over the merged internal packages: report data via @jetpack-premium-analytics/data (useReportOrders), the metric/sparkline rendering via @jetpack-premium-analytics/widgets-toolkit (WidgetRoot + OrderMetricWidget), with @automattic/charts underneath. Wires the internal packages for the wp-build externals resolver via link: deps on the parent manifest — the mechanism documented in #49189; this widget is the first built code to import them. Deviations from upstream, documented inline: - The host widget contract has no setError channel, so render.tsx holds the toolkit's setError state and renders an inline WidgetErrorNotice. - No reportParams range editor yet: wp-build's widget metadata build has no style plugins and the toolkit's ReportParamsField import graph carries .module.scss. New instances use the default last-30-days range with comparison enabled. - No URL-search reportParams fallback (handled by toolkit WidgetRoot's try/catch around useSearch outside a matched route).
With #49575 in trunk, the reportParams attribute gains its real editor: ReportParamsField from @jetpack-premium-analytics/fields, externalized as a script-module dependency so the styled date-picker graph never enters the metadata module's style-less build.
4538b65 to
bbf93fc
Compare
| @@ -0,0 +1 @@ | |||
| export { WidgetErrorNotice } from './widget-error-notice'; | |||
There was a problem hiding this comment.
Are there no existing widget error handling components at in either the widget toolkit or other packages? Other widgets will need something too? Also, check and see what exists for notices in the WordPress Design System.
| attributes: [ | ||
| { | ||
| id: 'reportParams', | ||
| label: __( 'Range', 'jetpack-premium-analytics' ), | ||
| Edit: ReportParamsField, | ||
| }, | ||
| ], |
There was a problem hiding this comment.
Investigate a way to hide this in the analytics dashboard but make available when the widget is inserted in non-analytics dashboards. Otherwise, if there is no straightforward implementation that can apply globally to all analytics type widgets, let's just remove this for now because report params will be defined at the global level for these widgets.
Fixes #
Proposed changes
Ports the Average items per order widget from
next-woocommerce-analytics(woocommerce/woocommerce-analytics@develop) into the Premium Analytics customizable dashboard — the first real analytics widget on the dashboard introduced by #49502, and the first consumer of the internal package ports.The widget is a thin composition over the merged internal packages (~200 lines total):
useReportOrdersfrom@jetpack-premium-analytics/data(feat(premium-analytics): port data package from next-woocommerce-analytics #49263) against/wc/v3/woocommerce-analytics/proxy/reports/orders, with comparison range.WidgetRoot+OrderMetricWidgetfrom@jetpack-premium-analytics/widgets-toolkit(feat(premium-analytics): port widgets-toolkit package from next-woocommerce-analytics #49422) — metric value, comparison delta, and@automattic/chartssparkline all come from the toolkit.reportParamsattribute'sEditcontrol isReportParamsFieldfrom@jetpack-premium-analytics/fields(Premium Analytics: add the fields package for widget DataForm controls #49575), externalized as a script-module dependency so the styled date-picker graph never enters the metadata module's style-less build.link:packages/*deps on the parent manifest for the packages the widget (transitively) imports — the mechanism documented in feat(premium-analytics): resolve internal packages for build and types #49189.Deviations from upstream (documented inline)
WidgetRenderProps) has nosetErrorchannel, sorender.tsxholds the toolkit'ssetErrorstate and renders an inlineWidgetErrorNotice(message + retry action from the toolkit's error config). Clearing the error remounts the widget, which refetches.jpa/average-items-per-order(host namespace) rather than the upstreamwoocommerce-analytics/average-items-per-order.Known limitations / follow-ups
align-series-dates) can be added cheaply.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
Requires pnpm ^11.5 and Node ^24.15.
pnpm --filter @automattic/jetpack-premium-analytics build— bothhello-worldandaverage-items-per-orderwidgets should build, andbuild/widgets.phpregisters them.pnpm --filter @automattic/jetpack-premium-analytics typecheck— only the pre-existinguseSelect/preferences errors inwidget-dashboard/widget-primitivesremain (present on the base branch; verified with a clean install).woocommerce-analyticsplugin active and synced, e.g. viajetpack rsync premium-analytics <site>:...):GET /wp-json/jetpack/v4/widget-moduleslistsjpa/average-items-per-order;widgets/average-items-per-order/render.min.jsloads as a separate chunk on mount; twoproxy/reports/ordersrequests fire (primary + comparison).