Skip to content

Add click-to-filter on world map countries - #449

Open
smehmood wants to merge 1 commit into
masterfrom
smehmood/add-country-map-filter-6w2h6d
Open

Add click-to-filter on world map countries#449
smehmood wants to merge 1 commit into
masterfrom
smehmood/add-country-map-filter-6w2h6d

Conversation

@smehmood

Copy link
Copy Markdown

Summary

  • Clicking a country on the world map now toggles a country=eq.XX URL filter, scoping all metrics on the page to that country through Umami's existing filter system (the shared FilterBar picks it up automatically).
  • The active country is highlighted with the primary hoverColor fill + a 1.5px stroke, and interactive countries show a pointer cursor.
  • Reuses useNavigation / updateParams for consistency with the rest of the app. Only enabled when a websiteId is present — the realtime map passes raw data and stays non-interactive; Antarctica is excluded.
  • 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 won't trigger a filter.

Verified

  • Click a country → country=eq.XX applied, FilterBar shows the chip (e.g. "Country Is Canada"), all metric API calls get scoped, selected country is highlighted.
  • Click a different country → filter switches.
  • Click the active country again → filter is cleared (toggle off), map returns to full data view.

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.

@mesa-dot-dev mesa-dot-dev Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 SettingsRead Docs

const handleClick = (code: string) => {
if (!isInteractive(code)) return;
const isSelected = isActive(code);
router.replace(updateParams({ country: isSelected ? undefined : `eq.${code}` }));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Medium

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.

Agent: 🏛 Architecture • Fix in Cursor • Fix in Claude

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant