2022-08-08 10:26:20 +02:00
|
|
|
import { useState } from 'react';
|
2022-08-29 05:20:54 +02:00
|
|
|
import { safeDecodeURI } from 'next-basics';
|
|
|
|
import FilterButtons from 'components/common/FilterButtons';
|
2023-04-02 19:00:28 +02:00
|
|
|
import { emptyFilter, paramFilter } from 'lib/filters';
|
2023-02-11 08:21:50 +01:00
|
|
|
import { FILTER_RAW, FILTER_COMBINED } from 'lib/constants';
|
2022-08-29 05:20:54 +02:00
|
|
|
import MetricsTable from './MetricsTable';
|
2023-03-22 22:05:55 +01:00
|
|
|
import useMessages from 'hooks/useMessages';
|
2023-04-01 07:01:36 +02:00
|
|
|
import styles from './QueryParametersTable.module.css';
|
2022-08-08 10:26:20 +02:00
|
|
|
|
2023-02-11 08:21:50 +01:00
|
|
|
const filters = {
|
2023-04-02 19:00:28 +02:00
|
|
|
[FILTER_RAW]: emptyFilter,
|
2023-02-11 08:21:50 +01:00
|
|
|
[FILTER_COMBINED]: paramFilter,
|
|
|
|
};
|
2022-08-08 10:26:20 +02:00
|
|
|
|
2023-04-21 17:00:42 +02:00
|
|
|
export function QueryParametersTable({ websiteId, showFilters, ...props }) {
|
2022-08-08 10:26:20 +02:00
|
|
|
const [filter, setFilter] = useState(FILTER_COMBINED);
|
2023-03-22 22:05:55 +01:00
|
|
|
const { formatMessage, labels } = useMessages();
|
2022-08-08 10:26:20 +02:00
|
|
|
|
|
|
|
const buttons = [
|
|
|
|
{
|
2023-02-11 08:21:50 +01:00
|
|
|
label: formatMessage(labels.filterCombined),
|
|
|
|
key: FILTER_COMBINED,
|
2022-08-08 10:26:20 +02:00
|
|
|
},
|
2023-02-11 08:21:50 +01:00
|
|
|
{ label: formatMessage(labels.filterRaw), key: FILTER_RAW },
|
2022-08-08 10:26:20 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2023-02-11 08:21:50 +01:00
|
|
|
{showFilters && <FilterButtons items={buttons} selectedKey={filter} onSelect={setFilter} />}
|
2022-08-08 10:26:20 +02:00
|
|
|
<MetricsTable
|
|
|
|
{...props}
|
2023-02-11 08:21:50 +01:00
|
|
|
title={formatMessage(labels.query)}
|
2022-08-08 10:26:20 +02:00
|
|
|
type="query"
|
2023-02-11 08:21:50 +01:00
|
|
|
metric={formatMessage(labels.views)}
|
2022-08-08 10:26:20 +02:00
|
|
|
websiteId={websiteId}
|
2023-02-11 08:21:50 +01:00
|
|
|
dataFilter={filters[filter]}
|
2022-08-08 10:26:20 +02:00
|
|
|
renderLabel={({ x, p, v }) =>
|
|
|
|
filter === FILTER_RAW ? (
|
|
|
|
x
|
|
|
|
) : (
|
2023-04-01 07:01:36 +02:00
|
|
|
<div className={styles.item}>
|
|
|
|
<div className={styles.param}>{safeDecodeURI(p)}</div>
|
|
|
|
<div className={styles.value}>{safeDecodeURI(v)}</div>
|
|
|
|
</div>
|
2022-08-08 10:26:20 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
delay={0}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
2023-04-21 17:00:42 +02:00
|
|
|
|
|
|
|
export default QueryParametersTable;
|