2023-04-14 07:28:29 +02:00
|
|
|
import MetricsTable from './MetricsTable';
|
|
|
|
import { emptyFilter } from 'lib/filters';
|
|
|
|
import FilterLink from 'components/common/FilterLink';
|
2023-08-21 11:06:09 +02:00
|
|
|
import useLocale from 'components/hooks/useLocale';
|
|
|
|
import useMessages from 'components/hooks/useMessages';
|
2023-08-26 21:46:27 +02:00
|
|
|
import useCountryNames from 'components/hooks/useCountryNames';
|
2023-04-14 07:28:29 +02:00
|
|
|
|
2023-04-21 17:00:42 +02:00
|
|
|
export function CitiesTable({ websiteId, ...props }) {
|
2023-04-14 07:28:29 +02:00
|
|
|
const { locale } = useLocale();
|
|
|
|
const { formatMessage, labels } = useMessages();
|
2023-08-26 21:46:27 +02:00
|
|
|
const countryNames = useCountryNames(locale);
|
2023-04-14 07:28:29 +02:00
|
|
|
|
2023-08-26 21:46:27 +02:00
|
|
|
const renderLabel = (city, country) => {
|
|
|
|
const name = countryNames[country];
|
|
|
|
return name ? `${city}, ${name}` : city;
|
|
|
|
};
|
|
|
|
|
|
|
|
const renderLink = ({ x: city, country }) => {
|
2023-04-14 07:28:29 +02:00
|
|
|
return (
|
2023-08-26 21:46:27 +02:00
|
|
|
<FilterLink id="city" value={city} label={renderLabel(city, country)}>
|
|
|
|
{country && (
|
|
|
|
<img
|
2023-09-29 14:29:22 +02:00
|
|
|
src={`${process.env.basePath}/images/flags/${country?.toLowerCase() || 'xx'}.png`}
|
2023-08-26 21:46:27 +02:00
|
|
|
alt={country}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</FilterLink>
|
2023-04-14 07:28:29 +02:00
|
|
|
);
|
2023-08-26 21:46:27 +02:00
|
|
|
};
|
2023-04-14 07:28:29 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<MetricsTable
|
|
|
|
{...props}
|
|
|
|
title={formatMessage(labels.cities)}
|
|
|
|
type="city"
|
|
|
|
metric={formatMessage(labels.visitors)}
|
|
|
|
websiteId={websiteId}
|
|
|
|
dataFilter={emptyFilter}
|
|
|
|
renderLabel={renderLink}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2023-04-21 17:00:42 +02:00
|
|
|
|
|
|
|
export default CitiesTable;
|