2022-12-29 00:43:22 +01:00
|
|
|
import { useState } from 'react';
|
2023-02-10 12:26:57 +01:00
|
|
|
import { useIntl } from 'react-intl';
|
2020-08-23 04:05:07 +02:00
|
|
|
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';
|
2023-02-11 08:21:50 +01:00
|
|
|
import { FILTER_COMBINED, FILTER_RAW } from 'lib/constants';
|
2020-08-23 04:05:07 +02:00
|
|
|
|
2023-02-11 08:21:50 +01:00
|
|
|
const filters = {
|
|
|
|
[FILTER_RAW]: null,
|
|
|
|
[FILTER_COMBINED]: refFilter,
|
|
|
|
};
|
2020-10-13 01:31:51 +02:00
|
|
|
|
2022-07-21 10:11:10 +02:00
|
|
|
export default function ReferrersTable({ websiteId, showFilters, ...props }) {
|
2020-09-06 02:27:01 +02:00
|
|
|
const [filter, setFilter] = useState(FILTER_COMBINED);
|
2022-07-21 10:11:10 +02:00
|
|
|
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),
|
2023-02-11 08:21:50 +01:00
|
|
|
key: FILTER_COMBINED,
|
2020-09-06 02:27:01 +02:00
|
|
|
},
|
2023-02-11 08:21:50 +01: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 }) => {
|
2022-07-21 10:11:10 +02:00
|
|
|
return referrer ? (
|
|
|
|
<FilterLink id="referrer" value={referrer} externalUrl={link} />
|
|
|
|
) : (
|
2023-02-10 12:26:57 +01:00
|
|
|
`(${formatMessage(labels.none)})`
|
2022-07-21 10:11:10 +02:00
|
|
|
);
|
2020-08-23 09:23:47 +02:00
|
|
|
};
|
|
|
|
|
2020-08-23 04:05:07 +02:00
|
|
|
return (
|
2020-09-22 06:34:55 +02:00
|
|
|
<>
|
2023-02-11 08:21:50 +01: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}
|
2023-02-11 08:21:50 +01:00
|
|
|
dataFilter={filters[filter]}
|
2020-09-22 06:34:55 +02:00
|
|
|
renderLabel={renderLink}
|
|
|
|
/>
|
|
|
|
</>
|
2020-08-23 04:05:07 +02:00
|
|
|
);
|
|
|
|
}
|