umami/components/metrics/ReferrersTable.js

50 lines
1.4 KiB
JavaScript
Raw Normal View History

import { useState } from 'react';
2023-02-10 12:26:57 +01:00
import { useIntl } from 'react-intl';
import MetricsTable from './MetricsTable';
2020-10-13 01:31:51 +02:00
import FilterButtons from 'components/common/FilterButtons';
2022-04-10 12:51:43 +02:00
import FilterLink from 'components/common/FilterLink';
2020-10-11 11:29:55 +02:00
import { refFilter } from 'lib/filters';
2023-02-10 12:26:57 +01:00
import { labels } from 'components/messages';
import { FILTER_COMBINED, FILTER_RAW } from 'lib/constants';
const filters = {
[FILTER_RAW]: null,
[FILTER_COMBINED]: refFilter,
};
2020-10-13 01:31:51 +02:00
export default function ReferrersTable({ websiteId, showFilters, ...props }) {
2020-09-06 02:27:01 +02:00
const [filter, setFilter] = useState(FILTER_COMBINED);
const { formatMessage } = useIntl();
2020-09-06 02:27:01 +02:00
2023-02-10 12:26:57 +01:00
const items = [
2020-09-06 02:27:01 +02:00
{
2023-02-10 12:26:57 +01:00
label: formatMessage(labels.filterCombined),
key: FILTER_COMBINED,
2020-09-06 02:27:01 +02:00
},
{ label: formatMessage(labels.filterRaw), key: FILTER_RAW },
2020-09-06 02:27:01 +02:00
];
2020-08-23 07:01:14 +02:00
2022-04-10 12:51:43 +02:00
const renderLink = ({ w: link, x: referrer }) => {
return referrer ? (
<FilterLink id="referrer" value={referrer} externalUrl={link} />
) : (
2023-02-10 12:26:57 +01:00
`(${formatMessage(labels.none)})`
);
2020-08-23 09:23:47 +02:00
};
return (
2020-09-22 06:34:55 +02:00
<>
{showFilters && <FilterButtons items={items} selectedKey={filter} onSelect={setFilter} />}
2020-09-22 06:34:55 +02:00
<MetricsTable
2020-10-11 10:33:26 +02:00
{...props}
2023-02-10 12:26:57 +01:00
title={formatMessage(labels.referrers)}
2020-09-22 06:34:55 +02:00
type="referrer"
2023-02-10 12:26:57 +01:00
metric={formatMessage(labels.views)}
2020-09-22 06:34:55 +02:00
websiteId={websiteId}
dataFilter={filters[filter]}
2020-09-22 06:34:55 +02:00
renderLabel={renderLink}
/>
</>
);
}