umami/components/pages/websites/WebsiteEventData.js

41 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-07-10 14:46:45 +02:00
import { Flexbox } from 'react-basics';
import EventDataTable from 'components/pages/event-data/EventDataTable';
2023-07-10 14:46:45 +02:00
import EventDataValueTable from 'components/pages/event-data/EventDataValueTable';
import { EventDataMetricsBar } from 'components/pages/event-data/EventDataMetricsBar';
import { useDateRange, useApi, usePageQuery } from 'hooks';
2023-07-11 10:16:17 +02:00
import styles from './WebsiteEventData.module.css';
function useFields(websiteId, field) {
const [dateRange] = useDateRange(websiteId);
const { startDate, endDate } = dateRange;
const { get, useQuery } = useApi();
const { data, error, isLoading } = useQuery(
2023-07-10 14:46:45 +02:00
['event-data:fields', { websiteId, startDate, endDate, field }],
() =>
2023-07-11 10:16:17 +02:00
get('/event-data/fields', {
websiteId,
startAt: +startDate,
endAt: +endDate,
field,
}),
{ enabled: !!(websiteId && startDate && endDate) },
);
return { data, error, isLoading };
}
export default function WebsiteEventData({ websiteId }) {
2023-07-10 14:46:45 +02:00
const {
query: { view },
} = usePageQuery();
const { data } = useFields(websiteId, view);
return (
2023-07-11 10:16:17 +02:00
<Flexbox className={styles.container} direction="column" gap={20}>
<EventDataMetricsBar websiteId={websiteId} />
2023-07-10 14:46:45 +02:00
{!view && <EventDataTable data={data} />}
{view && <EventDataValueTable field={view} data={data} />}
</Flexbox>
);
}