mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-18 15:23:38 +01:00
feature(dashboard): filter events by their type
This commit is contained in:
parent
67551fb129
commit
49b45acf4b
@ -1,18 +1,65 @@
|
|||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
import { FormattedMessage } from 'react-intl';
|
import { FormattedMessage } from 'react-intl';
|
||||||
import MetricsTable from './MetricsTable';
|
import MetricsTable from './MetricsTable';
|
||||||
import Tag from 'components/common/Tag';
|
import Tag from 'components/common/Tag';
|
||||||
|
import DropDown from 'components/common/DropDown';
|
||||||
|
import { eventTypeFilter } from 'lib/filters';
|
||||||
|
import useDateRange from 'hooks/useDateRange';
|
||||||
|
import useFetch from 'hooks/useFetch';
|
||||||
|
import usePageQuery from 'hooks/usePageQuery';
|
||||||
|
import useShareToken from 'hooks/useShareToken';
|
||||||
|
import { TOKEN_HEADER } from 'lib/constants';
|
||||||
|
|
||||||
|
const EVENT_FILTER_DEFAULT = {
|
||||||
|
value: 'EVENT_FILTER_DEFAULT',
|
||||||
|
label: 'All Events',
|
||||||
|
};
|
||||||
|
|
||||||
export default function EventsTable({ websiteId, ...props }) {
|
export default function EventsTable({ websiteId, ...props }) {
|
||||||
|
const [eventType, setEventType] = useState(EVENT_FILTER_DEFAULT.value);
|
||||||
|
|
||||||
|
const {
|
||||||
|
query: { url },
|
||||||
|
} = usePageQuery();
|
||||||
|
|
||||||
|
const shareToken = useShareToken();
|
||||||
|
const [dateRange] = useDateRange(websiteId);
|
||||||
|
|
||||||
|
const { startDate, endDate, modified } = dateRange;
|
||||||
|
const { data, loading, error } = useFetch(
|
||||||
|
`/api/website/${websiteId}/event-types`,
|
||||||
|
{
|
||||||
|
params: {
|
||||||
|
start_at: +startDate,
|
||||||
|
end_at: +endDate,
|
||||||
|
url,
|
||||||
|
},
|
||||||
|
headers: { [TOKEN_HEADER]: shareToken?.token },
|
||||||
|
},
|
||||||
|
[modified],
|
||||||
|
);
|
||||||
|
|
||||||
|
const eventTypes = data ? [...new Set(data.map(({ x }) => x))] : [];
|
||||||
|
const dropDownOptions = [EVENT_FILTER_DEFAULT, ...eventTypes.map(t => ({ value: t, label: t }))];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
|
{!loading && !error && eventTypes.length > 1 && (
|
||||||
|
<div style={{ display: 'flex', alignItems: 'center' }}>
|
||||||
|
<DropDown value={eventType} options={dropDownOptions} onChange={setEventType} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<MetricsTable
|
<MetricsTable
|
||||||
{...props}
|
{...props}
|
||||||
title={<FormattedMessage id="metrics.events" defaultMessage="Events" />}
|
title={<FormattedMessage id="metrics.events" defaultMessage="Events" />}
|
||||||
type="event"
|
type="event"
|
||||||
metric={<FormattedMessage id="metrics.actions" defaultMessage="Actions" />}
|
metric={<FormattedMessage id="metrics.actions" defaultMessage="Actions" />}
|
||||||
websiteId={websiteId}
|
websiteId={websiteId}
|
||||||
|
dataFilter={eventTypeFilter}
|
||||||
|
filterOptions={eventType === EVENT_FILTER_DEFAULT.value ? [] : [eventType]}
|
||||||
renderLabel={({ x }) => <Label value={x} />}
|
renderLabel={({ x }) => <Label value={x} />}
|
||||||
/>
|
/>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user