mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 09:45:04 +01:00
Fix event table.
This commit is contained in:
parent
62b032ab19
commit
7ae457669b
@ -1,62 +1,28 @@
|
|||||||
import React, { useState } from 'react';
|
import { defineMessages, useIntl } from 'react-intl';
|
||||||
import { FormattedMessage } from 'react-intl';
|
|
||||||
import MetricsTable from './MetricsTable';
|
import MetricsTable from './MetricsTable';
|
||||||
import Tag from 'components/common/Tag';
|
|
||||||
import DropDown from 'components/common/DropDown';
|
|
||||||
import { eventTypeFilter } from 'lib/filters';
|
import { eventTypeFilter } from 'lib/filters';
|
||||||
import usePageQuery from 'hooks/usePageQuery';
|
|
||||||
import styles from './EventsTable.module.css';
|
|
||||||
|
|
||||||
const EVENT_FILTER_DEFAULT = {
|
const messages = defineMessages({
|
||||||
value: 'all',
|
events: { id: 'metrics.events', defaultMessage: 'Events' },
|
||||||
label: <FormattedMessage id="label.all-events" defaultMessage="All events" />,
|
actions: { id: 'metrics.actions', defaultMessage: 'Actions' },
|
||||||
};
|
});
|
||||||
|
|
||||||
export default function EventsTable({ websiteId, ...props }) {
|
export default function EventsTable({ websiteId, ...props }) {
|
||||||
const [eventType, setEventType] = useState(EVENT_FILTER_DEFAULT.value);
|
const { formatMessage } = useIntl();
|
||||||
const [eventTypes, setEventTypes] = useState([]);
|
|
||||||
const { resolve, router } = usePageQuery();
|
|
||||||
|
|
||||||
const dropDownOptions = [EVENT_FILTER_DEFAULT, ...eventTypes.map(t => ({ value: t, label: t }))];
|
|
||||||
|
|
||||||
function handleDataLoad(data) {
|
function handleDataLoad(data) {
|
||||||
setEventTypes([...new Set(data.map(({ x }) => x.split('\t')[0]))]);
|
|
||||||
props.onDataLoad?.(data);
|
props.onDataLoad?.(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleChange(value) {
|
|
||||||
router.replace(resolve({ eventType: value === 'all' ? undefined : value }));
|
|
||||||
setEventType(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<MetricsTable
|
||||||
{eventTypes?.length > 1 && (
|
{...props}
|
||||||
<div className={styles.filter}>
|
title={formatMessage(messages.events)}
|
||||||
<DropDown value={eventType} options={dropDownOptions} onChange={handleChange} />
|
type="event"
|
||||||
</div>
|
metric={formatMessage(messages.actions)}
|
||||||
)}
|
websiteId={websiteId}
|
||||||
<MetricsTable
|
dataFilter={eventTypeFilter}
|
||||||
{...props}
|
onDataLoad={handleDataLoad}
|
||||||
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}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Label = ({ value }) => {
|
|
||||||
const [event, label] = value.split('\t');
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Tag>{event}</Tag>
|
|
||||||
{label}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
.filter {
|
|
||||||
display: flex;
|
|
||||||
justify-content: flex-start;
|
|
||||||
align-items: center;
|
|
||||||
margin-bottom: 15px;
|
|
||||||
}
|
|
@ -1,5 +1,5 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { FormattedMessage } from 'react-intl';
|
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import WebsiteChart from 'components/metrics/WebsiteChart';
|
import WebsiteChart from 'components/metrics/WebsiteChart';
|
||||||
import WorldMap from 'components/common/WorldMap';
|
import WorldMap from 'components/common/WorldMap';
|
||||||
@ -18,12 +18,25 @@ import CountriesTable from 'components/metrics/CountriesTable';
|
|||||||
import LanguagesTable from 'components/metrics/LanguagesTable';
|
import LanguagesTable from 'components/metrics/LanguagesTable';
|
||||||
import EventsTable from 'components/metrics/EventsTable';
|
import EventsTable from 'components/metrics/EventsTable';
|
||||||
import EventsChart from 'components/metrics/EventsChart';
|
import EventsChart from 'components/metrics/EventsChart';
|
||||||
|
import ScreenTable from 'components/metrics/ScreenTable';
|
||||||
|
import UTMTable from 'components/metrics/UTMTable';
|
||||||
import useFetch from 'hooks/useFetch';
|
import useFetch from 'hooks/useFetch';
|
||||||
import usePageQuery from 'hooks/usePageQuery';
|
import usePageQuery from 'hooks/usePageQuery';
|
||||||
import { DEFAULT_ANIMATION_DURATION } from 'lib/constants';
|
import { DEFAULT_ANIMATION_DURATION } from 'lib/constants';
|
||||||
import styles from './WebsiteDetails.module.css';
|
import styles from './WebsiteDetails.module.css';
|
||||||
import ScreenTable from 'components/metrics/ScreenTable';
|
|
||||||
import UTMTable from 'components/metrics/UTMTable';
|
const messages = defineMessages({
|
||||||
|
pages: { id: 'pages', defaultMessage: 'Pages' },
|
||||||
|
referrers: { id: 'metrics.referrers', defaultMessage: 'Referrers' },
|
||||||
|
screens: { id: 'metrics.screens', defaultMessage: 'Screens' },
|
||||||
|
browsers: { id: 'metrics.browsers', defaultMessage: 'Browsers' },
|
||||||
|
os: { id: 'metrics.os', defaultMessage: 'Operating system' },
|
||||||
|
devices: { id: 'metrics.device', defaultMessage: 'Devices' },
|
||||||
|
countries: { id: 'metrics.screens', defaultMessage: 'Screens' },
|
||||||
|
languages: { id: 'metrics.languages', defaultMessage: 'Languages' },
|
||||||
|
events: { id: 'metrics.screens', defaultMessage: 'Screens' },
|
||||||
|
utm: { id: 'metrics.utm', defaultMessage: 'UTM' },
|
||||||
|
});
|
||||||
|
|
||||||
const views = {
|
const views = {
|
||||||
url: PagesTable,
|
url: PagesTable,
|
||||||
@ -47,6 +60,7 @@ export default function WebsiteDetails({ websiteId }) {
|
|||||||
resolve,
|
resolve,
|
||||||
query: { view },
|
query: { view },
|
||||||
} = usePageQuery();
|
} = usePageQuery();
|
||||||
|
const { formatMessage } = useIntl();
|
||||||
|
|
||||||
const BackButton = () => (
|
const BackButton = () => (
|
||||||
<div key="back-button" className={classNames(styles.backButton, 'col-12')}>
|
<div key="back-button" className={classNames(styles.backButton, 'col-12')}>
|
||||||
@ -61,43 +75,43 @@ export default function WebsiteDetails({ websiteId }) {
|
|||||||
render: BackButton,
|
render: BackButton,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: <FormattedMessage id="metrics.pages" defaultMessage="Pages" />,
|
label: formatMessage(messages.pages),
|
||||||
value: resolve({ view: 'url' }),
|
value: resolve({ view: 'url' }),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: <FormattedMessage id="metrics.referrers" defaultMessage="Referrers" />,
|
label: formatMessage(messages.referrers),
|
||||||
value: resolve({ view: 'referrer' }),
|
value: resolve({ view: 'referrer' }),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: <FormattedMessage id="metrics.screens" defaultMessage="Screens" />,
|
label: formatMessage(messages.screens),
|
||||||
value: resolve({ view: 'screen' }),
|
value: resolve({ view: 'screen' }),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: <FormattedMessage id="metrics.browsers" defaultMessage="Browsers" />,
|
label: formatMessage(messages.browsers),
|
||||||
value: resolve({ view: 'browser' }),
|
value: resolve({ view: 'browser' }),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: <FormattedMessage id="metrics.operating-systems" defaultMessage="Operating system" />,
|
label: formatMessage(messages.os),
|
||||||
value: resolve({ view: 'os' }),
|
value: resolve({ view: 'os' }),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: <FormattedMessage id="metrics.devices" defaultMessage="Devices" />,
|
label: formatMessage(messages.devices),
|
||||||
value: resolve({ view: 'device' }),
|
value: resolve({ view: 'device' }),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: <FormattedMessage id="metrics.countries" defaultMessage="Countries" />,
|
label: formatMessage(messages.countries),
|
||||||
value: resolve({ view: 'country' }),
|
value: resolve({ view: 'country' }),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: <FormattedMessage id="metrics.languages" defaultMessage="Languages" />,
|
label: formatMessage(messages.languages),
|
||||||
value: resolve({ view: 'language' }),
|
value: resolve({ view: 'language' }),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: <FormattedMessage id="metrics.events" defaultMessage="Events" />,
|
label: formatMessage(messages.events),
|
||||||
value: resolve({ view: 'event' }),
|
value: resolve({ view: 'event' }),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: <FormattedMessage id="metrics.utm" defaultMessage="UTM" />,
|
label: formatMessage(messages.utm),
|
||||||
value: resolve({ view: 'utm' }),
|
value: resolve({ view: 'utm' }),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
@ -10,6 +10,10 @@ function success(msg) {
|
|||||||
console.log(chalk.greenBright(`✓ ${msg}`));
|
console.log(chalk.greenBright(`✓ ${msg}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function error(msg) {
|
||||||
|
console.log(chalk.redBright(`✗ ${msg}`));
|
||||||
|
}
|
||||||
|
|
||||||
async function checkEnv() {
|
async function checkEnv() {
|
||||||
if (!process.env.DATABASE_URL) {
|
if (!process.env.DATABASE_URL) {
|
||||||
throw new Error('DATABASE_URL is not defined.');
|
throw new Error('DATABASE_URL is not defined.');
|
||||||
@ -34,6 +38,7 @@ async function checkTables() {
|
|||||||
|
|
||||||
success('Database tables found.');
|
success('Database tables found.');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
error('Database tables not found.');
|
||||||
console.log('Adding tables...');
|
console.log('Adding tables...');
|
||||||
|
|
||||||
console.log(execSync('prisma migrate deploy').toString());
|
console.log(execSync('prisma migrate deploy').toString());
|
||||||
|
Loading…
Reference in New Issue
Block a user