forked from umami-software/umami
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
47 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,28 @@ | ||
import React, { useState } from 'react'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { defineMessages, useIntl } from 'react-intl'; | ||
import MetricsTable from './MetricsTable'; | ||
import Tag from 'components/common/Tag'; | ||
import DropDown from 'components/common/DropDown'; | ||
import { eventTypeFilter } from 'lib/filters'; | ||
import usePageQuery from 'hooks/usePageQuery'; | ||
import styles from './EventsTable.module.css'; | ||
|
||
const EVENT_FILTER_DEFAULT = { | ||
value: 'all', | ||
label: <FormattedMessage id="label.all-events" defaultMessage="All events" />, | ||
}; | ||
const messages = defineMessages({ | ||
events: { id: 'metrics.events', defaultMessage: 'Events' }, | ||
actions: { id: 'metrics.actions', defaultMessage: 'Actions' }, | ||
}); | ||
|
||
export default function EventsTable({ websiteId, ...props }) { | ||
const [eventType, setEventType] = useState(EVENT_FILTER_DEFAULT.value); | ||
const [eventTypes, setEventTypes] = useState([]); | ||
const { resolve, router } = usePageQuery(); | ||
|
||
const dropDownOptions = [EVENT_FILTER_DEFAULT, ...eventTypes.map(t => ({ value: t, label: t }))]; | ||
const { formatMessage } = useIntl(); | ||
|
||
function handleDataLoad(data) { | ||
setEventTypes([...new Set(data.map(({ x }) => x.split('\t')[0]))]); | ||
props.onDataLoad?.(data); | ||
} | ||
|
||
function handleChange(value) { | ||
router.replace(resolve({ eventType: value === 'all' ? undefined : value })); | ||
setEventType(value); | ||
} | ||
|
||
return ( | ||
<> | ||
{eventTypes?.length > 1 && ( | ||
<div className={styles.filter}> | ||
<DropDown value={eventType} options={dropDownOptions} onChange={handleChange} /> | ||
</div> | ||
)} | ||
<MetricsTable | ||
{...props} | ||
title={<FormattedMessage id="metrics.events" defaultMessage="Events" />} | ||
type="event" | ||
metric={<FormattedMessage id="metrics.actions" defaultMessage="Actions" />} | ||
websiteId={websiteId} | ||
dataFilter={eventTypeFilter} | ||
filterOptions={eventType === EVENT_FILTER_DEFAULT.value ? [] : [eventType]} | ||
renderLabel={({ x }) => <Label value={x} />} | ||
onDataLoad={handleDataLoad} | ||
/> | ||
</> | ||
<MetricsTable | ||
{...props} | ||
title={formatMessage(messages.events)} | ||
type="event" | ||
metric={formatMessage(messages.actions)} | ||
websiteId={websiteId} | ||
dataFilter={eventTypeFilter} | ||
onDataLoad={handleDataLoad} | ||
/> | ||
); | ||
} | ||
|
||
const Label = ({ value }) => { | ||
const [event, label] = value.split('\t'); | ||
return ( | ||
<> | ||
<Tag>{event}</Tag> | ||
{label} | ||
</> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters