2022-12-29 00:43:22 +01:00
|
|
|
import { useState } from 'react';
|
2022-07-21 10:11:10 +02:00
|
|
|
import { useIntl, defineMessage } from 'react-intl';
|
2022-04-10 12:51:43 +02:00
|
|
|
import FilterLink from 'components/common/FilterLink';
|
2020-10-13 01:31:51 +02:00
|
|
|
import FilterButtons from 'components/common/FilterButtons';
|
2020-08-23 04:05:07 +02:00
|
|
|
import { urlFilter } from 'lib/filters';
|
2020-09-06 02:27:01 +02:00
|
|
|
import MetricsTable from './MetricsTable';
|
2020-08-23 04:05:07 +02:00
|
|
|
|
2020-10-13 01:31:51 +02:00
|
|
|
export const FILTER_COMBINED = 0;
|
|
|
|
export const FILTER_RAW = 1;
|
|
|
|
|
2022-07-21 10:11:10 +02:00
|
|
|
const messages = defineMessage({
|
|
|
|
combined: { id: 'metrics.filter.combined', defaultMessage: 'Combined' },
|
|
|
|
raw: { id: 'metrics.filter.raw', defaultMessage: 'Raw' },
|
|
|
|
pages: { id: 'metrics.pages', defaultMessage: 'Pages' },
|
|
|
|
views: { id: 'metrics.views', defaultMessage: 'View' },
|
|
|
|
});
|
|
|
|
|
|
|
|
export default function PagesTable({ 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
|
|
|
|
|
|
|
const buttons = [
|
|
|
|
{
|
2022-07-21 10:11:10 +02:00
|
|
|
label: formatMessage(messages.combined),
|
2020-09-06 02:27:01 +02:00
|
|
|
value: FILTER_COMBINED,
|
|
|
|
},
|
2022-07-21 10:11:10 +02:00
|
|
|
{
|
|
|
|
label: formatMessage(messages.raw),
|
|
|
|
value: FILTER_RAW,
|
|
|
|
},
|
2020-09-06 02:27:01 +02:00
|
|
|
];
|
2020-08-23 07:01:14 +02:00
|
|
|
|
2021-11-22 07:00:14 +01:00
|
|
|
const renderLink = ({ x: url }) => {
|
2022-04-10 12:51:43 +02:00
|
|
|
return <FilterLink id="url" value={url} />;
|
2020-09-26 07:31:18 +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
|
2022-07-21 10:11:10 +02:00
|
|
|
title={formatMessage(messages.pages)}
|
2020-09-22 06:34:55 +02:00
|
|
|
type="url"
|
2022-07-21 10:11:10 +02:00
|
|
|
metric={formatMessage(messages.views)}
|
2020-09-22 06:34:55 +02:00
|
|
|
websiteId={websiteId}
|
2022-07-21 10:11:10 +02:00
|
|
|
dataFilter={filter !== FILTER_RAW ? urlFilter : null}
|
2020-09-26 07:31:18 +02:00
|
|
|
renderLabel={renderLink}
|
2020-10-11 10:33:26 +02:00
|
|
|
{...props}
|
2020-09-22 06:34:55 +02:00
|
|
|
/>
|
|
|
|
</>
|
2020-08-23 04:05:07 +02:00
|
|
|
);
|
|
|
|
}
|