mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-24 18:26:20 +01:00
50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
import React, { useState } from 'react';
|
|
import MetricsTable from './MetricsTable';
|
|
import { refFilter } from 'lib/filters';
|
|
import ButtonGroup from 'components/common/ButtonGroup';
|
|
|
|
export default function ReferrersTable({ websiteId, websiteDomain, limit, onExpand = () => {} }) {
|
|
const [filter, setFilter] = useState('Combined');
|
|
|
|
const renderLink = ({ x: url }) => {
|
|
return url.startsWith('http') ? (
|
|
<a href={url} target="_blank" rel="noreferrer">
|
|
{decodeURI(url)}
|
|
</a>
|
|
) : (
|
|
decodeURI(url)
|
|
);
|
|
};
|
|
|
|
return (
|
|
<MetricsTable
|
|
title="Referrers"
|
|
type="referrer"
|
|
metric="Views"
|
|
headerComponent={limit ? null : <FilterButtons selected={filter} onClick={setFilter} />}
|
|
websiteId={websiteId}
|
|
websiteDomain={websiteDomain}
|
|
limit={limit}
|
|
dataFilter={refFilter}
|
|
filterOptions={{
|
|
domain: websiteDomain,
|
|
domainOnly: filter === 'Domain only',
|
|
raw: filter === 'Raw',
|
|
}}
|
|
onExpand={onExpand}
|
|
renderLabel={renderLink}
|
|
/>
|
|
);
|
|
}
|
|
|
|
const FilterButtons = ({ selected, onClick }) => {
|
|
return (
|
|
<ButtonGroup
|
|
size="xsmall"
|
|
items={['Domain only', 'Combined', 'Raw']}
|
|
selectedItem={selected}
|
|
onClick={onClick}
|
|
/>
|
|
);
|
|
};
|