2020-08-23 07:01:14 +02:00
|
|
|
import React, { useState } from 'react';
|
2020-09-06 02:27:01 +02:00
|
|
|
import { FormattedMessage } 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';
|
2020-10-11 11:29:55 +02:00
|
|
|
import { refFilter } from 'lib/filters';
|
2020-08-23 04:05:07 +02:00
|
|
|
|
2020-10-13 01:31:51 +02:00
|
|
|
export const FILTER_DOMAIN_ONLY = 0;
|
|
|
|
export const FILTER_COMBINED = 1;
|
|
|
|
export const FILTER_RAW = 2;
|
|
|
|
|
2020-10-11 11:29:55 +02:00
|
|
|
export default function ReferrersTable({ websiteId, websiteDomain, showFilters, ...props }) {
|
2020-09-06 02:27:01 +02:00
|
|
|
const [filter, setFilter] = useState(FILTER_COMBINED);
|
|
|
|
|
|
|
|
const buttons = [
|
|
|
|
{
|
|
|
|
label: <FormattedMessage id="metrics.filter.domain-only" defaultMessage="Domain only" />,
|
|
|
|
value: FILTER_DOMAIN_ONLY,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: <FormattedMessage id="metrics.filter.combined" defaultMessage="Combined" />,
|
|
|
|
value: FILTER_COMBINED,
|
|
|
|
},
|
|
|
|
{ label: <FormattedMessage id="metrics.filter.raw" defaultMessage="Raw" />, value: FILTER_RAW },
|
|
|
|
];
|
2020-08-23 07:01:14 +02:00
|
|
|
|
2020-09-16 06:25:51 +02:00
|
|
|
const renderLink = ({ w: href, x: url }) => {
|
|
|
|
return (href || url).startsWith('http') ? (
|
|
|
|
<a href={href || url} target="_blank" rel="noreferrer">
|
2020-08-25 08:49:14 +02:00
|
|
|
{decodeURI(url)}
|
2020-08-23 09:23:47 +02:00
|
|
|
</a>
|
|
|
|
) : (
|
2020-08-25 08:49:14 +02:00
|
|
|
decodeURI(url)
|
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
|
|
|
<>
|
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}
|
2020-09-22 06:34:55 +02:00
|
|
|
title={<FormattedMessage id="metrics.referrers" defaultMessage="Referrers" />}
|
|
|
|
type="referrer"
|
|
|
|
metric={<FormattedMessage id="metrics.views" defaultMessage="Views" />}
|
|
|
|
websiteId={websiteId}
|
|
|
|
websiteDomain={websiteDomain}
|
|
|
|
dataFilter={refFilter}
|
|
|
|
filterOptions={{
|
|
|
|
domain: websiteDomain,
|
|
|
|
domainOnly: filter === FILTER_DOMAIN_ONLY,
|
|
|
|
raw: filter === FILTER_RAW,
|
|
|
|
}}
|
|
|
|
renderLabel={renderLink}
|
|
|
|
/>
|
|
|
|
</>
|
2020-08-23 04:05:07 +02:00
|
|
|
);
|
|
|
|
}
|