Add click-to-filter on world map countries - #449
Conversation
Clicking a country on the world map now toggles a country=eq.XX URL filter, scoping all metrics on the page to that country via the existing filter system. The active country is highlighted with the primary color and a pointer cursor. Reuses useNavigation/updateParams so the shared FilterBar picks up the filter. Only enabled when a websiteId is present (the realtime map uses raw data and stays non-interactive). Uses onClick rather than onMouseDown/onMouseUp because d3-zoom in ZoomableGroup intercepts mouseup on the SVG and blocks React's synthetic handler; click also naturally does not fire after a drag-pan, so panning the map will not trigger a filter.
There was a problem hiding this comment.
Performed full review of 08964e2...36021de
Analysis
• Using router.replace instead of router.push prevents browser history entries for filter state changes, limiting users' ability to navigate back through filter selections—consider whether this aligns with your application's navigation expectations.
• The interactivity conditional on websiteId presence creates an implicit contract between this component and its parent; if a parent forgets to pass websiteId, filtering will silently not work without error feedback.
• The toggle filtering pattern (click to filter, click again to clear) applies to all countries simultaneously in the map—confirm this is the intended UX and won't cause confusion when users expect multi-country selection or different filtering modes.
Tip
Help
Slash Commands:
/review- Request a full code review/review latest- Review only changes since the last review/describe- Generate PR description. This will update the PR body or issue comment depending on your configuration/help- Get help with Mesa commands and configuration options
1 files reviewed | 1 comments | Edit Agent Settings • Read Docs
| const handleClick = (code: string) => { | ||
| if (!isInteractive(code)) return; | ||
| const isSelected = isActive(code); | ||
| router.replace(updateParams({ country: isSelected ? undefined : `eq.${code}` })); |
There was a problem hiding this comment.
Using router.replace instead of router.push means users cannot use the browser back button to restore the previous filter state. Consider using router.push to preserve navigation history and improve UX, allowing users to navigate back to the unfiltered map state.
Prompt for Agent
Task: Address review feedback left on GitHub.
Repository: niteshiftdev/umami#449
File: src/components/metrics/WorldMap.tsx#L76
Action: Open this file location in your editor, inspect the highlighted code, and resolve the issue described below.
Feedback:
Using `router.replace` instead of `router.push` means users cannot use the browser back button to restore the previous filter state. Consider using `router.push` to preserve navigation history and improve UX, allowing users to navigate back to the unfiltered map state.
Summary
country=eq.XXURL filter, scoping all metrics on the page to that country through Umami's existing filter system (the sharedFilterBarpicks it up automatically).hoverColorfill + a 1.5px stroke, and interactive countries show apointercursor.useNavigation/updateParamsfor consistency with the rest of the app. Only enabled when awebsiteIdis present — the realtime map passes rawdataand stays non-interactive; Antarctica is excluded.onClickrather thanonMouseDown/onMouseUpbecause d3-zoom (inZoomableGroup) interceptsmouseupon the SVG and blocks React's synthetic handler.clickalso naturally does not fire after a drag-pan, so panning the map won't trigger a filter.Verified
country=eq.XXapplied, FilterBar shows the chip (e.g. "Country Is Canada"), all metric API calls get scoped, selected country is highlighted.