Repository navigation
Premium Analytics: declare the chart type attribute in widget.json - #53778
Conversation
jpa/toggle-group takes jpa/<name> icons; drops the chart-line copies
mirrors gutenberg#82485; an element keeps its icon reference
…type-attribute-json # Conflicts: # projects/packages/premium-analytics/docs/dashboard-widgets.md
the module keeps only what JSON cannot carry; CHART_TYPE_ELEMENTS goes
|
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! |
Code Coverage SummaryCoverage changed in 10 files. Only the first 5 are listed here.
|
the manifest orders the settings; a module-only one is listed by id
…-attributes-registry Co-authored-by: louwie17 <lourensschep@gmail.com>
mirrors gutenberg#82485; an element keeps its icon reference
…-attributes-registry Co-authored-by: louwie17 <lourensschep@gmail.com>
…-type-attribute-json
…stry' into update/chart-type-attribute-json Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # projects/packages/premium-analytics/docs/dashboard-widgets.md
…tribute-json Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # projects/packages/premium-analytics/docs/dashboard-widgets.md
…icon-references Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # projects/packages/premium-analytics/docs/dashboard-widgets.md
the icon-reference form ships with the field alone; widgets move to widget.json in the follow-up, and the contract takes 1.15.0 after the registry landed at 1.14.0
…e-attribute-json # Conflicts: # projects/packages/ads/widgets/wordads-chart-tabs/widget.ts # projects/packages/premium-analytics/docs/dashboard-widgets.md # projects/packages/premium-analytics/packages/widgets-toolkit/src/helpers/chart-display-attribute-fields.ts # projects/packages/woocommerce-stats/widgets/average-items-per-order/widget.ts # projects/packages/woocommerce-stats/widgets/average-order-value/widget.ts # projects/packages/woocommerce-stats/widgets/bookings-over-time/widget.ts # projects/packages/woocommerce-stats/widgets/gross-sales-over-time/widget.ts # projects/packages/woocommerce-stats/widgets/net-sales-over-time/widget.ts # projects/packages/woocommerce-stats/widgets/orders-over-time/widget.ts # projects/packages/woocommerce-stats/widgets/total-sales-over-time/widget.ts # projects/packages/woocommerce-stats/widgets/visitors-over-time/widget.ts
|
Thanks @retrofox, this is a nice cleanup. Fifteen copies of the same chart type attribute become one data-driven declaration, and the widgets get a lot smaller. Things I liked:
One note, not a blocker: "Chart type", "Line chart" and "Bar chart" went through What I checked:
Not checked: the WooCommerce Stats and WordAds chart widgets (they have no dashboard story), the dashboard on a real site, and the |
| "category": "subscribers", | ||
| "presentation": "framed" | ||
| "presentation": "framed", | ||
| "attributes": [ |
There was a problem hiding this comment.
Could we add reportParams here too, like chartInterval in Traffic summary? Without it, the chart type toggle now shows before the date picker, while on trunk the date picker comes first. WordAds chart tabs has the same issue.
| "attributes": [ | |
| "attributes": [ | |
| { | |
| "id": "reportParams" | |
| }, |
There was a problem hiding this comment.
Good catch. Both manifests now list reportParams by id ahead of chartType, the way Traffic summary lists chartInterval, so the date control leads the header again (3e28323).
| * @param elements - The options as the widget declares them. | ||
| * @return The options with every icon an element. | ||
| */ | ||
| export function resolveOptionIcons( elements: Option[] ): Option[] { |
There was a problem hiding this comment.
nit: Does resolveOptionIcons need to be exported? Only this file uses it.
| }, | ||
| ] as WidgetAttributeField< AverageOrderValueAttributes >[], | ||
| }; | ||
| export default {}; |
There was a problem hiding this comment.
nit: Could we remove @wordpress/icons from these widgets' package.json files? With chartBar gone, none of the chart widgets use it anymore.
There was a problem hiding this comment.
Dropped it from all 18 widgets and the package root: nothing in woocommerce-stats imports it any more (the other ten stopped in #53355). The widget folders are not workspace packages, so the lockfile only loses the root importer entry.
| type ChartDisplayChartType, | ||
| type CountLabel, | ||
| } from '@jetpack-premium-analytics/widgets-toolkit'; | ||
| import type { ChartDisplayChartType, CountLabel } from '@jetpack-premium-analytics/widgets-toolkit'; |
There was a problem hiding this comment.
nit: The comment above SubscribersChartType still mentions "the shared chart-display list", which this PR removes. Worth updating it here and in the other four chart widgets?
There was a problem hiding this comment.
Reworded in the five widgets: the alias ties the attribute to the toolkit's own union, which the chart reads. Removing the identity aliases altogether is WOOA7S-2286.
…type-attribute-json # Conflicts: # projects/packages/premium-analytics/packages/fields/src/field-toggle-group/__tests__/toggle-group-field.test.tsx # projects/packages/premium-analytics/packages/fields/src/field-toggle-group/stories/toggle-group-field.stories.tsx
|
Thanks, Chi, for the review. Feedback addressed. |
Part of WOOA7S-2331
Builds on #53771 (a
jpa/toggle-groupoption names its icon by reference) and includes it until it lands; the diff then shrinks to thewidget.jsonmove. #53774, the registry carryingattributes, is on trunk.Proposed changes
The fifteen chart widgets declare their
chartTypeattribute inwidget.jsonThis includes the eight WooCommerce Stats time series, the WordAds chart tabs, and Author views, Email performance, Post views, Subscriber summary, Traffic summary, and Video views.
The attribute is data: a
jpa/toggle-groupwith two options, with iconsjpa/chart-lineandjpa/chart-bar.widget.tskeeps only what JSON cannot carryThe attribute type,
example,reportParamsAttributeField()where the widget owns its date control, and in Traffic summary thegetValuethat defaults the switch to the Stats v1 choice.The registry's entry and the module's merge by
id. The eight WooCommerce Stats modules export{}.The manifest orders the settings
useWidgetTypeslists the record's entries first and the module-only ones after. A setting whose control stays in the module is therefore listed inwidget.jsonbyidalone, where it belongs, and the module fills it in. Traffic summary listschartIntervalahead ofchartType: its control reads the page's date range, which a DataViews field cannot. Subscriber summary and the WordAds chart tabs listreportParamsahead of it, so their date control keeps leading the header. The vocabulary indocs/dashboard-widgets.mdstates the rule; WordPress/gutenberg#85082 asks upstream to keep the module's position instead.CHART_TYPE_ELEMENTSleaves the widgets toolkit;ChartDisplayChartTypestays. The two private copies of thechart-lineglyph (woocommerce-stats/src/icons/chart-line.tsx,ads/widgets/wordads-chart-tabs/chart-line.tsx) go with it. The WooCommerce Stats package and its widgets drop their@wordpress/iconsdependency, which nothing there imports any more.createStoryWidgetType()merges the manifest'sattributesover the module's byid, asuseWidgetTypesdoes, so the stories keep the control.The three labels (
Chart type,Line chart,Bar chart) now travel aswidget.jsonstrings.Like every widget title and description, they render in English until the
widget.jsonstrings reach a catalog (WOOA7S-2175); the attribute contexts insrc/widget-i18n.jsonare ready for them.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
GET /wp-json/wpcom/v2/widget-modulesEach of the fifteen records carries
attributeswith thechartTypeentry, two elements, and their icon references.Each widget keeps its
line/bartoggle in the header, drawn as two icon segments; switching redraws the chart, and the choice persists.Traffic summary still defaults to bars, or to the chart type Stats v1 saved in this browser.
Storybook: the
WidgetDashboardWithWidgetstory of any of the six widgets here shows the toggle.pnpm run testinprojects/packages/premium-analytics: the Traffic chart suite reads the switch default through the module'sgetValue; the toggle group suite covers the reference form.