umami/components/metrics/RegionsTable.js

40 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-04-14 07:28:29 +02:00
import MetricsTable from './MetricsTable';
import { emptyFilter } from 'lib/filters';
import FilterLink from 'components/common/FilterLink';
import useLocale from 'hooks/useLocale';
import useMessages from 'hooks/useMessages';
2023-04-21 23:35:00 +02:00
import useCountryNames from 'hooks/useCountryNames';
2023-04-14 07:28:29 +02:00
import regions from 'public/iso-3166-2.json';
2023-04-21 17:00:42 +02:00
export function RegionsTable({ websiteId, ...props }) {
2023-04-14 07:28:29 +02:00
const { locale } = useLocale();
const { formatMessage, labels } = useMessages();
2023-04-21 23:35:00 +02:00
const countryNames = useCountryNames(locale);
2023-04-14 07:28:29 +02:00
2023-04-21 23:35:00 +02:00
const renderLabel = x => {
return regions[x] ? `${regions[x]}, ${countryNames[x.split('-')[0]]}` : x;
};
2023-04-24 04:52:44 +02:00
const renderLink = ({ x: code }) => {
2023-04-14 07:28:29 +02:00
return (
2023-04-24 04:52:44 +02:00
<FilterLink id="region" className={locale} value={code} label={renderLabel(code)}>
<img src={`/images/flags/${code?.split('-')?.[0]?.toLowerCase() || 'xx'}.png`} alt={code} />
2023-04-24 04:52:44 +02:00
</FilterLink>
2023-04-14 07:28:29 +02:00
);
2023-04-21 23:35:00 +02:00
};
2023-04-14 07:28:29 +02:00
return (
<MetricsTable
{...props}
title={formatMessage(labels.regions)}
type="region"
metric={formatMessage(labels.visitors)}
websiteId={websiteId}
dataFilter={emptyFilter}
renderLabel={renderLink}
/>
);
}
2023-04-21 17:00:42 +02:00
export default RegionsTable;