umami/components/metrics/PagesTable.js

50 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-04-10 12:51:43 +02:00
import FilterLink from 'components/common/FilterLink';
2023-03-31 14:55:28 +02:00
import FilterButtons from 'components/common/FilterButtons';
2020-09-06 02:27:01 +02:00
import MetricsTable from './MetricsTable';
2023-03-22 22:05:55 +01:00
import useMessages from 'hooks/useMessages';
2023-03-31 14:55:28 +02:00
import usePageQuery from 'hooks/usePageQuery';
2023-04-09 01:31:21 +02:00
import { emptyFilter } from 'lib/filters';
2023-03-31 14:55:28 +02:00
export default function PagesTable({ websiteId, showFilters, ...props }) {
const {
router,
resolveUrl,
query: { view = 'url' },
2023-03-31 14:55:28 +02:00
} = usePageQuery();
2023-03-22 22:05:55 +01:00
const { formatMessage, labels } = useMessages();
2020-09-06 02:27:01 +02:00
2023-03-31 14:55:28 +02:00
const handleSelect = key => {
router.push(resolveUrl({ view: key }), null, { shallow: true });
};
const buttons = [
{
2023-04-09 00:51:49 +02:00
label: 'URL',
2023-03-31 14:55:28 +02:00
key: 'url',
},
{
label: formatMessage(labels.title),
key: 'title',
},
];
const renderLink = ({ x }) => {
2023-04-02 19:00:28 +02:00
return <FilterLink id={view} value={x} label={!x && formatMessage(labels.none)} />;
2020-09-26 07:31:18 +02:00
};
return (
2020-09-22 06:34:55 +02:00
<>
2023-03-31 14:55:28 +02:00
{showFilters && <FilterButtons items={buttons} selectedKey={view} onSelect={handleSelect} />}
2020-09-22 06:34:55 +02:00
<MetricsTable
2023-04-01 06:31:58 +02:00
{...props}
2023-02-10 12:26:57 +01:00
title={formatMessage(labels.pages)}
2023-03-31 14:55:28 +02:00
type={view}
2023-02-10 12:26:57 +01:00
metric={formatMessage(labels.views)}
2020-09-22 06:34:55 +02:00
websiteId={websiteId}
2023-04-02 19:00:28 +02:00
dataFilter={emptyFilter}
2020-09-26 07:31:18 +02:00
renderLabel={renderLink}
2020-09-22 06:34:55 +02:00
/>
</>
);
}