umami/components/metrics/PagesTable.js

41 lines
1.4 KiB
JavaScript
Raw Normal View History

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';
import ButtonGroup from 'components/common/ButtonGroup';
import { urlFilter } from 'lib/filters';
2020-09-06 02:27:01 +02:00
import { FILTER_COMBINED, FILTER_RAW } from 'lib/constants';
import MetricsTable from './MetricsTable';
export default function PagesTable({ websiteId, token, websiteDomain, limit, onExpand }) {
2020-09-06 02:27:01 +02:00
const [filter, setFilter] = useState(FILTER_COMBINED);
const buttons = [
{
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
return (
<MetricsTable
2020-09-06 02:27:01 +02:00
title={<FormattedMessage id="metrics.pages" defaultMessage="Pages" />}
type="url"
2020-09-06 02:27:01 +02:00
metric={<FormattedMessage id="metrics.views" defaultMessage="Views" />}
headerComponent={
limit ? null : <FilterButtons buttons={buttons} selected={filter} onClick={setFilter} />
}
websiteId={websiteId}
token={token}
limit={limit}
dataFilter={urlFilter}
2020-09-06 02:27:01 +02:00
filterOptions={{ domain: websiteDomain, raw: filter === FILTER_RAW }}
2020-08-25 08:49:14 +02:00
renderLabel={({ x }) => decodeURI(x)}
onExpand={onExpand}
/>
);
}
2020-08-23 07:01:14 +02:00
2020-09-06 02:27:01 +02:00
const FilterButtons = ({ buttons, selected, onClick }) => {
return <ButtonGroup size="xsmall" items={buttons} selectedItem={selected} onClick={onClick} />;
2020-08-23 07:01:14 +02:00
};