From cfef9ac48c65e8c967248c7bb16452782843cd0a Mon Sep 17 00:00:00 2001 From: Sajid Mehmood Date: Fri, 17 Jul 2026 14:22:44 +0000 Subject: [PATCH] Make WorldMap countries clickable to filter by country Clicking a country on the world map now applies a `country=eq.` filter to the dashboard, matching the behavior of the country list's FilterLink. Antarctica and empty codes are ignored, and hoverable countries show a pointer cursor. Run-on: Niteshift --- src/components/metrics/WorldMap.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/metrics/WorldMap.tsx b/src/components/metrics/WorldMap.tsx index 3c8fadb80..6f4ce3744 100644 --- a/src/components/metrics/WorldMap.tsx +++ b/src/components/metrics/WorldMap.tsx @@ -6,6 +6,7 @@ import { useCountryNames, useLocale, useMessages, + useNavigation, useWebsiteMetricsQuery, } from '@/components/hooks'; import { getThemeColors } from '@/lib/colors'; @@ -25,6 +26,7 @@ export function WorldMap({ websiteId, data, ...props }: WorldMapProps) { const { locale } = useLocale(); const { formatMessage, labels } = useMessages(); const { countryNames } = useCountryNames(locale); + const { router, updateParams } = useNavigation(); const visitorsLabel = formatMessage(labels.visitors).toLocaleLowerCase(locale); const unknownLabel = formatMessage(labels.unknown); @@ -54,6 +56,11 @@ export function WorldMap({ websiteId, data, ...props }: WorldMapProps) { return code === 'AQ' ? 0 : 1; }; + const handleClick = (code: string) => { + if (!code || code === 'AQ') return; + router.replace(updateParams({ country: `eq.${code}` })); + }; + const handleHover = (code: string) => { if (code === 'AQ') return; const country = metrics?.find(({ x }) => x === code); @@ -86,12 +93,13 @@ export function WorldMap({ websiteId, data, ...props }: WorldMapProps) { stroke={colors.map.strokeColor} opacity={getOpacity(code)} style={{ - default: { outline: 'none' }, + default: { outline: 'none', cursor: code === 'AQ' ? 'default' : 'pointer' }, hover: { outline: 'none', fill: colors.map.hoverColor }, pressed: { outline: 'none' }, }} onMouseOver={() => handleHover(code)} onMouseOut={() => setTooltipPopup(null)} + onClick={() => handleClick(code)} /> ); });