Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/components/metrics/WorldMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
useCountryNames,
useLocale,
useMessages,
useNavigation,
useWebsiteMetricsQuery,
} from '@/components/hooks';
import { getThemeColors } from '@/lib/colors';
Expand All @@ -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, query } = useNavigation();
const visitorsLabel = formatMessage(labels.visitors).toLocaleLowerCase(locale);
const unknownLabel = formatMessage(labels.unknown);

Expand Down Expand Up @@ -64,6 +66,16 @@ export function WorldMap({ websiteId, data, ...props }: WorldMapProps) {
);
};

const isInteractive = (code: string) => !!websiteId && code !== 'AQ';

const isActive = (code: string) => query.country === `eq.${code}`;

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.

};

return (
<Column
{...props}
Expand All @@ -77,21 +89,25 @@ export function WorldMap({ websiteId, data, ...props }: WorldMapProps) {
{({ geographies }) => {
return geographies.map(geo => {
const code = ISO_COUNTRIES[geo.id];
const interactive = isInteractive(code);
const active = isActive(code);

return (
<Geography
key={geo.rsmKey}
geography={geo}
fill={getFillColor(code)}
fill={active ? colors.map.hoverColor : getFillColor(code)}
stroke={colors.map.strokeColor}
strokeWidth={active ? 1.5 : 0}
opacity={getOpacity(code)}
style={{
default: { outline: 'none' },
default: { outline: 'none', cursor: interactive ? 'pointer' : 'default' },
hover: { outline: 'none', fill: colors.map.hoverColor },
pressed: { outline: 'none' },
}}
onMouseOver={() => handleHover(code)}
onMouseOut={() => setTooltipPopup(null)}
onClick={interactive ? () => handleClick(code) : undefined}
/>
);
});
Expand Down