import { Row } from '@umami/react-zen'; import { Favicon } from '@/components/common/Favicon'; import { FilterLink } from '@/components/common/FilterLink'; import { TypeIcon } from '@/components/common/TypeIcon'; import { useCountryNames, useFormat, useLocale, useMessages, useRegionNames, } from '@/components/hooks'; import { GROUPED_DOMAINS } from '@/lib/constants'; import { decodePunycodeDomain } from '@/lib/format'; export interface MetricLabelProps { type: string; data: any; onClick?: () => void; } export function MetricLabel({ type, data }: MetricLabelProps) { switch (type) { case 'browser': case 'os': return ; case 'channel': return ; case 'city': return ; case 'region': return ; case 'country': return ; case 'path': case 'entry': case 'exit': return ; case 'fullPath': return ; case 'device': return ; case 'referrer': return ; case 'domain': return ; case 'language': return ; default: return ; } } function BrowserOsMetricLabel({ type, data, }: { type: 'browser' | 'os'; data: MetricLabelProps['data']; }) { const { formatValue } = useFormat(); const { label } = data; return ( } /> ); } function ChannelMetricLabel({ data }: Pick) { const { t, labels } = useMessages(); const { label } = data; return t(labels[label]); } function CityMetricLabel({ data }: Pick) { const { formatCity } = useFormat(); const { label, country } = data; return ( ) } /> ); } function RegionMetricLabel({ data }: Pick) { const { locale } = useLocale(); const { getRegionName } = useRegionNames(locale); const { label, country } = data; return ( } /> ); } function CountryMetricLabel({ data }: Pick) { const { formatValue } = useFormat(); const { locale } = useLocale(); const { countryNames } = useCountryNames(locale); const { label } = data; return ( } /> ); } function PathMetricLabel({ type, data }: MetricLabelProps) { const { t, labels } = useMessages(); const { label, domain } = data; return ( ); } function FullPathMetricLabel({ data }: Pick) { const { t, labels } = useMessages(); const { label } = data; return label || `(${t(labels.none)})`; } function DeviceMetricLabel({ data }: Pick) { const { formatValue } = useFormat(); const { labels } = useMessages(); const { label } = data; return ( } /> ); } function ReferrerMetricLabel({ data }: Pick) { const { t, labels } = useMessages(); const { label } = data; return ( } /> ); } function DomainMetricLabel({ data }: Pick) { const { t, labels } = useMessages(); const { label } = data; if (label === 'Other') { return `(${t(labels.other)})`; } const name = GROUPED_DOMAINS.find(({ domain }) => domain === label)?.name; if (!name) { return null; } return ( {name} ); } function LanguageMetricLabel({ data }: Pick) { const { formatValue } = useFormat(); const { label } = data; return formatValue(label, 'language'); } function DefaultMetricLabel({ type, data }: MetricLabelProps) { const { label } = data; return ; }