Skip to content

Premium Analytics: Add Locations geo mode controls - #50251

Merged
dognose24 merged 24 commits into
trunkfrom
codex/locations-inline-geo-mode
Jul 8, 2026
Merged

Premium Analytics: Add Locations geo mode controls#50251
dognose24 merged 24 commits into
trunkfrom
codex/locations-inline-geo-mode

Conversation

@dognose24

@dognose24 dognose24 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Part of WOOA7S-1491.

Proposed changes

  • Add onError error reporting to @automattic/charts GeoChart. A MutationObserver on the chart container also reports the draw errors Google renders as DOM elements without firing the ChartWrapper error event (e.g. async map-file load failures).
  • Locations widget: implement the three geo views switched by the geoGranularity toolbar attribute (promoted to the widget host in Premium Analytics: update widget packages and promote in-body controls to widget attributes #50293) — Countries with a world map, country drill-down into a region leaderboard + province map, and Cities with a country-level map aggregated from city rows.
  • Fall back countries without a Google provinces map (e.g. Taiwan, Singapore) to a world map scoped to the selected country. Unsupported countries are learned at runtime from any error during a provinces draw — no hardcoded list — cached per page load, and the injected error element is removed before the next paint, so no Requested map does not exist. error is shown.
  • Keep the previous settled map/list visible under the loading overlay while placeholder data is active, so drill-down and back navigation don't flicker through wrongly sized maps.
  • Storybook and docs: add a Cities-mode story and a geoGranularity control to the Locations stories, and update the GeoChart API reference/docs with onError/GeoChartError (backfilling the pre-existing region/resolution props in the same table).

Related product discussion/links

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

No. This changes how existing Locations widget data is displayed.

Testing instructions

  • From projects/js-packages/charts: pnpm run test -- src/charts/geo-chart/test/geo-chart.test.tsx, pnpm run typecheck, pnpm run build.
  • From projects/packages/premium-analytics: pnpm run typecheck, pnpm run build.
  • Optional: run Storybook (pnpm run storybook:dev from projects/js-packages/storybook) and check the Locations stories (Default / CitiesMode / WidgetDashboardWithWidget) and the Geo Chart API Reference page.
  • Open the Premium Analytics dashboard with the Locations widget and confirm the Countries/Cities selector appears in the widget toolbar.
  • Countries mode: confirm the country leaderboard + world map render; click United States and confirm a region leaderboard + province map.
  • Click Singapore or Taiwan: confirm the region leaderboard renders with no Requested map does not exist. error and a world map containing only the selected country.
  • Use the back link from a drill-down and confirm the map does not flash through an incorrectly sized intermediate map.
  • Cities mode: confirm the leaderboard shows city rows while the map highlights the countries those rows belong to.
2026-07-08.10.29.35.mov

@github-actions

github-actions Bot commented Jul 7, 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 codex/locations-inline-geo-mode branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack codex/locations-inline-geo-mode
bin/jetpack-downloader test jetpack-mu-wpcom-plugin codex/locations-inline-geo-mode

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

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

jp-launch-control Bot commented Jul 7, 2026

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/js-packages/charts/src/charts/geo-chart/geo-chart.tsx 75/79 (94.94%) -2.36% 3 ❤️‍🩹

Full summary · PHP report · JS report

@dognose24
dognose24 requested a review from retrofox July 7, 2026 04:56
@dognose24 dognose24 self-assigned this Jul 7, 2026
dognose24 and others added 11 commits July 7, 2026 13:04
…ne-geo-mode

# Conflicts:
#	projects/packages/premium-analytics/widgets/locations/package.json
#	projects/packages/premium-analytics/widgets/locations/render.tsx
#	projects/packages/premium-analytics/widgets/locations/style.module.css
#	projects/packages/premium-analytics/widgets/locations/widget.ts
The ChartWrapper error event does not fire when GeoChart's async map-file
load fails, so watch the chart container for the error elements Google
injects and report them through the same onError callback.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Treat any GeoChart error during a provinces draw as an unsupported
province map instead of matching the (localizable) error message, and
add Singapore to the known-unsupported fast path alongside Taiwan.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Drop the hardcoded country list; every country now goes through the
GeoChart onError detection, with a module-level cache so each country
pays the failed provinces draw at most once per page load. The error
element is removed in a MutationObserver microtask before the next
paint, so the failed draw is not visible.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@dognose24
dognose24 marked this pull request as ready for review July 8, 2026 06:24
@dognose24
dognose24 requested review from a team as code owners July 8, 2026 06:24
Expose the geoGranularity toolbar attribute as a Storybook control with a
dedicated CitiesMode story, and re-export GeoChartError through the
widgets-toolkit charts passthrough instead of re-declaring the shape inline.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
dognose24 and others added 2 commits July 8, 2026 22:16
Markers with named locations require Google Maps geocoding (a mapsApiKey
in the charts loader), which the package does not configure, so they
silently render nothing. Switch the story to latitude/longitude city data
and document the constraint.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The Cities-as-markers design that motivated it was abandoned mid-branch
(markers with named locations need a Google Maps geocoding key), leaving
displayMode with no consumers. Keep only the error reporting additions.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

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

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Comment thread projects/js-packages/charts/src/charts/geo-chart/geo-chart.tsx Outdated
GeoChart mutates its container heavily while drawing and resizing; rescan
for rendered error elements only when a mutation record's added nodes
involve a Google error element instead of on every mutation batch.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

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

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Comment thread projects/packages/premium-analytics/widgets/locations/render.tsx
The outer component already defaults max and geoGranularity before
passing them down; type LocationsInner's props as required so the
invariant is visible and drop the duplicated fallbacks inside.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

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

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Comment thread projects/packages/premium-analytics/widgets/locations/render.tsx
useSelectedCountryFallbackMap became identical to useCountryFallbackMap
after the fallback-state stabilization; drop it and derive
fallbackCountry from the single remaining flag.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

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

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

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

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Comment thread projects/packages/premium-analytics/widgets/locations/render.tsx
Stragglers from a failed provinces draw arrive after the widget already
switched to the fallback map; match them via the learned unsupported-country
set instead of relying only on the English error message, which Google may
localize.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

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

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

@dognose24
dognose24 merged commit 5b148c5 into trunk Jul 8, 2026
95 checks passed
@dognose24
dognose24 deleted the codex/locations-inline-geo-mode branch July 8, 2026 15:44
@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] Needs Review This PR is ready for review. labels Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants