Skip to content

Premium Analytics: declare the chart type attribute in widget.json - #53778

Merged
retrofox merged 26 commits into
trunkfrom
update/chart-type-attribute-json
Oct 20, 2026
Merged

retrofox merged 26 commits into
trunkfrom
update/chart-type-attribute-json

Conversation

@retrofox

@retrofox retrofox commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Part of WOOA7S-2331

Builds on #53771 (a jpa/toggle-group option names its icon by reference) and includes it until it lands; the diff then shrinks to the widget.json move. #53774, the registry carrying attributes, is on trunk.

Proposed changes

The fifteen chart widgets declare their chartType attribute in widget.json

This 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-group with two options, with icons jpa/chart-line and jpa/chart-bar.

widget.ts keeps only what JSON cannot carry

The attribute type, example, reportParamsAttributeField() where the widget owns its date control, and in Traffic summary the getValue that 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

useWidgetTypes lists the record's entries first and the module-only ones after. A setting whose control stays in the module is therefore listed in widget.json by id alone, where it belongs, and the module fills it in. Traffic summary lists chartInterval ahead of chartType: its control reads the page's date range, which a DataViews field cannot. Subscriber summary and the WordAds chart tabs list reportParams ahead of it, so their date control keeps leading the header. The vocabulary in docs/dashboard-widgets.md states the rule; WordPress/gutenberg#85082 asks upstream to keep the module's position instead.

CHART_TYPE_ELEMENTS leaves the widgets toolkit; ChartDisplayChartType stays. The two private copies of the chart-line glyph (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/icons dependency, which nothing there imports any more.

createStoryWidgetType() merges the manifest's attributes over the module's by id, as useWidgetTypes does, so the stories keep the control.

The three labels (Chart type, Line chart, Bar chart) now travel as widget.json strings.

Like every widget title and description, they render in English until the widget.json strings reach a catalog (WOOA7S-2175); the attribute contexts in src/widget-i18n.json are ready for them.

Related product discussion/links

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

No.

Testing instructions

  • Build with dependencies
jetpack build --deps packages/premium-analytics
jetpack build packages/woocommerce-stats
jetpack build packages/ads
  • GET /wp-json/wpcom/v2/widget-modules

Each of the fifteen records carries attributes with the chartType entry, two elements, and their icon references.

Screenshot 2026-10-19 at 11 44 23 AM 2
  • On the dashboard

Each widget keeps its line/bar toggle 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 WidgetDashboardWithWidget story of any of the six widgets here shows the toggle.

  • pnpm run test in projects/packages/premium-analytics: the Traffic chart suite reads the switch default through the module's getValue; the toggle group suite covers the reference form.

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
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack or WordPress.com Site Helper), and enable the update/chart-type-attribute-json branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/chart-type-attribute-json
bin/jetpack-downloader test jetpack-mu-wpcom-plugin update/chart-type-attribute-json

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions

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!

@retrofox
retrofox added this pull request to stack #53780 October 19, 2026 10:00
@jp-launch-control

jp-launch-control Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 10 files. Only the first 5 are listed here.

File Coverage Δ% Δ Uncovered
projects/packages/premium-analytics/widgets/traffic-chart/widget.ts 9/9 (100.00%) 0.00% 0 💚
projects/packages/premium-analytics/packages/widgets-toolkit/src/helpers/chart-display-attribute-fields.ts 0/0 (—%) 0.00% 0 💚
projects/packages/woocommerce-stats/widgets/average-items-per-order/widget.ts 0/0 (—%) 100.00% -1 💚
projects/packages/woocommerce-stats/widgets/average-order-value/widget.ts 0/0 (—%) 100.00% -1 💚
projects/packages/woocommerce-stats/widgets/bookings-over-time/widget.ts 0/0 (—%) 100.00% -1 💚

Full summary · PHP report · JS report

the manifest orders the settings; a module-only one is listed by id
@retrofox retrofox added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Oct 19, 2026
retrofox and others added 5 commits October 19, 2026 14:08
…-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>
…stry' into update/chart-type-attribute-json

Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	projects/packages/premium-analytics/docs/dashboard-widgets.md
Base automatically changed from update/pa-widget-attributes-registry to trunk October 19, 2026 14:01
…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
@retrofox
retrofox marked this pull request as ready for review October 19, 2026 17:47
@retrofox
retrofox requested a review from a team as a code owner October 19, 2026 17:47
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
@adamwoodnz

adamwoodnz commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • resolveOptionIcons drops back to text segments when an icon reference does not resolve, so a segment is never blank, and the new tests cover both the reference form and the fallback.
  • createStoryWidgetType() merges the manifest attributes by id the same way useWidgetTypes does, so the stories still show what the dashboard shows.
  • Traffic summary keeps its Stats v1 default through getValue, and the bare chartInterval entry keeps the controls in their old order.

One note, not a blocker: "Chart type", "Line chart" and "Bar chart" went through __() before and now come from widget.json, so they show in English until WOOA7S-2175 lands. "Line chart" and "Bar chart" are also the segments' accessible names, so a screen reader reads them in English on a translated site. You already call this out, and with the follow-up planned it is your call which order to ship them in. Just flagging it so it stays on the list.

What I checked:

  • Storybook in the browser, at d1493e3: the WidgetDashboardWithWidget stories of Traffic summary and Post views. The jpa/chart-line and jpa/chart-bar references resolve to icon segments with their tooltips, and the control is a "Chart type" radio group with "Line chart" and "Bar chart" radios. Switching between them redraws the chart both ways in both widgets, the same as on trunk.
  • pnpm run test in packages/premium-analytics: 4147 passed. In packages/woocommerce-stats: 63 passed.
  • pnpm run typecheck in premium-analytics, woocommerce-stats and ads: clean.
  • The tests and type checks ran at 5b3fae4, before your push that merges trunk and moves the contract to 1.15.0. I read that change but did not rerun them.

Not checked: the WooCommerce Stats and WordAds chart widgets (they have no dashboard story), the dashboard on a real site, and the /widget-modules response.

@chihsuan chihsuan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice to see the duplicate chart icons go! @retrofox I tested it, and it works well. I left a few small notes inline.

"category": "subscribers",
"presentation": "framed"
"presentation": "framed",
"attributes": [

@chihsuan chihsuan Oct 20, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

download (1)
Suggested change
"attributes": [
"attributes": [
{
"id": "reportParams"
},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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[] {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Does resolveOptionIcons need to be exported? Only this file uses it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Merged the fix from #53771 (9334d4f), so it is module-private here too.

},
] as WidgetAttributeField< AverageOrderValueAttributes >[],
};
export default {};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Could we remove @wordpress/icons from these widgets' package.json files? With chartBar gone, none of the chart widgets use it anymore.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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
@retrofox

Copy link
Copy Markdown
Contributor Author

Thanks, Chi, for the review. Feedback addressed.

@chihsuan chihsuan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! @retrofox LGTM 🚀 Do we need to sync the SDK README and AGENTS.md with the new widget.json form too? Happy for that to be a follow-up.

@retrofox
retrofox merged commit 36c50b2 into trunk Oct 20, 2026
129 checks passed
@retrofox
retrofox deleted the update/chart-type-attribute-json branch October 20, 2026 09:21
@github-actions github-actions Bot added [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. and removed [Status] In Progress [Status] Needs Review This PR is ready for review. labels Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants