umami/components/metrics/PagesTable.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

import { useState } from 'react';
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';
import { urlFilter } from 'lib/filters';
2020-09-06 02:27:01 +02:00
import MetricsTable from './MetricsTable';
import { FILTER_COMBINED, FILTER_RAW } from 'lib/constants';
2023-03-22 22:05:55 +01:00
import useMessages from 'hooks/useMessages';
const filters = {
[FILTER_RAW]: null,
[FILTER_COMBINED]: urlFilter,
};
2020-10-13 01:31:51 +02:00
export default function PagesTable({ websiteId, showFilters, ...props }) {
2020-09-06 02:27:01 +02:00
const [filter, setFilter] = useState(FILTER_COMBINED);
2023-03-22 22:05:55 +01:00
const { formatMessage, labels } = useMessages();
2020-09-06 02:27:01 +02:00
const buttons = [
{
2023-02-10 12:26:57 +01:00
label: formatMessage(labels.filterCombined),
key: FILTER_COMBINED,
2020-09-06 02:27:01 +02:00
},
{
2023-02-10 12:26:57 +01:00
label: formatMessage(labels.filterRaw),
key: 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
};
return (
2020-09-22 06:34:55 +02:00
<>
{showFilters && <FilterButtons items={buttons} selectedKey={filter} onSelect={setFilter} />}
2020-09-22 06:34:55 +02:00
<MetricsTable
2023-02-10 12:26:57 +01:00
title={formatMessage(labels.pages)}
2020-09-22 06:34:55 +02:00
type="url"
2023-02-10 12:26:57 +01:00
metric={formatMessage(labels.views)}
2020-09-22 06:34:55 +02:00
websiteId={websiteId}
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
/>
</>
);
}