Fix display of encoded characters. Closes #1171.

This commit is contained in:
Mike Cao 2022-06-23 13:44:30 -07:00
parent 11ae382209
commit 1bfb26ab44
2 changed files with 13 additions and 7 deletions

View File

@ -2,6 +2,7 @@ import React from 'react';
import Link from 'next/link';
import classNames from 'classnames';
import usePageQuery from 'hooks/usePageQuery';
import { safeDecodeURI } from 'lib/url';
import Icon from './Icon';
import External from 'assets/arrow-up-right-from-square.svg';
import styles from './FilterLink.module.css';
@ -20,7 +21,7 @@ export default function FilterLink({ id, value, label, externalUrl }) {
[styles.active]: active && selected,
})}
>
{label || value}
{safeDecodeURI(label || value)}
</a>
</Link>
{externalUrl && (

View File

@ -1,14 +1,21 @@
import React from 'react';
import MetricsTable from './MetricsTable';
import { percentFilter } from 'lib/filters';
import { FormattedMessage } from 'react-intl';
import { useIntl, defineMessages } from 'react-intl';
import FilterLink from 'components/common/FilterLink';
import useCountryNames from 'hooks/useCountryNames';
import useLocale from 'hooks/useLocale';
const messages = defineMessages({
unknown: { id: 'label.unknown', defaultMessage: 'Unknown' },
countries: { id: 'label.countries', defaultMessage: 'Countries' },
visitors: { id: 'label.visitors', defaultMessage: 'Visitors' },
});
export default function CountriesTable({ websiteId, onDataLoad, ...props }) {
const { locale } = useLocale();
const countryNames = useCountryNames(locale);
const { formatMessage } = useIntl();
function renderLink({ x: code }) {
return (
@ -16,9 +23,7 @@ export default function CountriesTable({ websiteId, onDataLoad, ...props }) {
<FilterLink
id="country"
value={code}
label={
countryNames[code] ?? <FormattedMessage id="label.unknown" defaultMessage="Unknown" />
}
label={countryNames[code] ?? formatMessage(messages.unknown)}
/>
</div>
);
@ -27,9 +32,9 @@ export default function CountriesTable({ websiteId, onDataLoad, ...props }) {
return (
<MetricsTable
{...props}
title={<FormattedMessage id="metrics.countries" defaultMessage="Countries" />}
title={formatMessage(messages.countries)}
type="country"
metric={<FormattedMessage id="metrics.visitors" defaultMessage="Visitors" />}
metric={formatMessage(messages.visitors)}
websiteId={websiteId}
onDataLoad={data => onDataLoad?.(percentFilter(data))}
renderLabel={renderLink}