umami/components/metrics/ReferrersTable.js

55 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-08-23 07:01:14 +02:00
import React, { useState } from 'react';
import { useIntl, defineMessages } 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';
2022-08-08 10:26:20 +02:00
const FILTER_COMBINED = 0;
const FILTER_RAW = 1;
2020-10-13 01:31:51 +02:00
const messages = defineMessages({
combined: { id: 'metrics.filter.combined', defaultMessage: 'Combined' },
raw: { id: 'metrics.filter.raw', defaultMessage: 'Raw' },
referrers: { id: 'metrics.referrers', defaultMessage: 'Referrers' },
views: { id: 'metrics.views', defaultMessage: 'Views' },
none: { id: 'label.none', defaultMessage: 'None' },
});
export default function ReferrersTable({ websiteId, showFilters, ...props }) {
2020-09-06 02:27:01 +02:00
const [filter, setFilter] = useState(FILTER_COMBINED);
const { formatMessage } = useIntl();
const none = formatMessage(messages.none);
2020-09-06 02:27:01 +02:00
const buttons = [
{
label: formatMessage(messages.combined),
2020-09-06 02:27:01 +02:00
value: FILTER_COMBINED,
},
{ label: formatMessage(messages.raw), value: 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} />
) : (
`(${none})`
);
2020-08-23 09:23:47 +02:00
};
return (
2020-09-22 06:34:55 +02:00
<>
2020-09-26 07:31:18 +02:00
{showFilters && <FilterButtons buttons={buttons} selected={filter} onClick={setFilter} />}
2020-09-22 06:34:55 +02:00
<MetricsTable
2020-10-11 10:33:26 +02:00
{...props}
title={formatMessage(messages.referrers)}
2020-09-22 06:34:55 +02:00
type="referrer"
metric={formatMessage(messages.views)}
2020-09-22 06:34:55 +02:00
websiteId={websiteId}
dataFilter={filter !== FILTER_RAW ? refFilter : null}
2020-09-22 06:34:55 +02:00
renderLabel={renderLink}
/>
</>
);
}