umami/components/metrics/ReferrersTable.js

58 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-08-23 07:01:14 +02:00
import React, { useState } from 'react';
import MetricsTable from './MetricsTable';
import { refFilter } from 'lib/filters';
2020-08-23 07:01:14 +02:00
import ButtonGroup from '../common/ButtonGroup';
export default function Referrers({
websiteId,
websiteDomain,
startDate,
endDate,
limit,
onExpand = () => {},
}) {
2020-08-23 07:01:14 +02:00
const [filter, setFilter] = useState('Combined');
2020-08-25 08:49:14 +02:00
const renderLink = ({ x: url }) => {
2020-08-23 09:23:47 +02:00
return url.startsWith('http') ? (
<a 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
);
};
return (
<MetricsTable
title="Referrers"
type="referrer"
metric="Views"
2020-08-23 07:01:14 +02:00
headerComponent={limit ? null : <FilterButtons selected={filter} onClick={setFilter} />}
websiteId={websiteId}
startDate={startDate}
endDate={endDate}
limit={limit}
dataFilter={refFilter}
2020-08-23 07:01:14 +02:00
filterOptions={{
domain: websiteDomain,
domainOnly: filter === 'Domain only',
raw: filter === 'Raw',
}}
onExpand={onExpand}
2020-08-25 08:49:14 +02:00
renderLabel={renderLink}
/>
);
}
2020-08-23 07:01:14 +02:00
const FilterButtons = ({ selected, onClick }) => {
return (
<ButtonGroup
size="xsmall"
items={['Domain only', 'Combined', 'Raw']}
selectedItem={selected}
onClick={onClick}
/>
);
};