umami/components/metrics/CountriesTable.js

44 lines
1.3 KiB
JavaScript
Raw Normal View History

import React from 'react';
import MetricsTable from './MetricsTable';
2020-10-01 01:27:27 +02:00
import { percentFilter } from 'lib/filters';
import { useIntl, defineMessages } from 'react-intl';
2022-04-10 12:51:43 +02:00
import FilterLink from 'components/common/FilterLink';
2020-10-01 01:27:27 +02:00
import useCountryNames from 'hooks/useCountryNames';
import useLocale from 'hooks/useLocale';
const messages = defineMessages({
unknown: { id: 'label.unknown', defaultMessage: 'Unknown' },
2022-06-27 05:56:24 +02:00
countries: { id: 'metrics.countries', defaultMessage: 'Countries' },
visitors: { id: 'metrics.visitors', defaultMessage: 'Visitors' },
});
2020-10-11 11:29:55 +02:00
export default function CountriesTable({ websiteId, onDataLoad, ...props }) {
const { locale } = useLocale();
2020-10-01 01:27:27 +02:00
const countryNames = useCountryNames(locale);
const { formatMessage } = useIntl();
2020-10-01 01:27:27 +02:00
2022-04-10 12:51:43 +02:00
function renderLink({ x: code }) {
return (
<div className={locale}>
2022-04-10 12:51:43 +02:00
<FilterLink
id="country"
value={code}
label={countryNames[code] ?? formatMessage(messages.unknown)}
2022-04-10 12:51:43 +02:00
/>
</div>
);
2020-10-01 01:27:27 +02:00
}
return (
<MetricsTable
2020-10-11 10:33:26 +02:00
{...props}
title={formatMessage(messages.countries)}
type="country"
metric={formatMessage(messages.visitors)}
websiteId={websiteId}
2020-10-11 10:33:26 +02:00
onDataLoad={data => onDataLoad?.(percentFilter(data))}
2022-04-10 12:51:43 +02:00
renderLabel={renderLink}
/>
);
}