mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 12:47:13 +01:00
Updates to reports.
This commit is contained in:
parent
1869a809cf
commit
22d477b98b
22 changed files with 388 additions and 117 deletions
|
|
@ -1,8 +1,7 @@
|
|||
.menu {
|
||||
display: flex;
|
||||
flex-flow: row wrap;
|
||||
min-width: 600px;
|
||||
max-width: 100vw;
|
||||
max-width: 640px;
|
||||
padding: 10px;
|
||||
background: var(--base50);
|
||||
z-index: var(--z-index-popup);
|
||||
|
|
|
|||
|
|
@ -129,6 +129,8 @@ export const labels = defineMessages({
|
|||
window: { id: 'label.window', defaultMessage: 'Window' },
|
||||
addUrl: { id: 'label.add-url', defaultMessage: 'Add URL' },
|
||||
runQuery: { id: 'label.run-query', defaultMessage: 'Run query' },
|
||||
fields: { id: 'label.fields', defaultMessage: 'Fields' },
|
||||
addField: { id: 'label.add-field', defaultMessage: 'Add field' },
|
||||
});
|
||||
|
||||
export const messages = defineMessages({
|
||||
|
|
|
|||
43
components/pages/reports/BaseParameters.js
Normal file
43
components/pages/reports/BaseParameters.js
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import { FormRow } from 'react-basics';
|
||||
import DateFilter from 'components/input/DateFilter';
|
||||
import WebsiteSelect from 'components/input/WebsiteSelect';
|
||||
import { parseDateRange } from 'lib/date';
|
||||
import { useContext } from 'react';
|
||||
import { ReportContext } from './Report';
|
||||
import { useMessages } from 'hooks';
|
||||
|
||||
export function BaseParameters() {
|
||||
const { report, updateReport } = useContext(ReportContext);
|
||||
const { formatMessage, labels } = useMessages();
|
||||
|
||||
const { parameters } = report || {};
|
||||
const { websiteId, dateRange } = parameters || {};
|
||||
const { value, startDate, endDate } = dateRange || {};
|
||||
|
||||
const handleWebsiteSelect = websiteId => {
|
||||
updateReport({ parameters: { websiteId } });
|
||||
};
|
||||
|
||||
const handleDateChange = value => {
|
||||
updateReport({ parameters: { dateRange: { ...parseDateRange(value) } } });
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<FormRow label={formatMessage(labels.website)}>
|
||||
<WebsiteSelect websiteId={websiteId} onSelect={handleWebsiteSelect} />
|
||||
</FormRow>
|
||||
<FormRow label={formatMessage(labels.dateRange)}>
|
||||
<DateFilter
|
||||
value={value}
|
||||
startDate={startDate}
|
||||
endDate={endDate}
|
||||
onChange={handleDateChange}
|
||||
showAllTime
|
||||
/>
|
||||
</FormRow>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default BaseParameters;
|
||||
|
|
@ -8,8 +8,6 @@ export const ReportContext = createContext(null);
|
|||
export function Report({ reportId, defaultParameters, children, ...props }) {
|
||||
const report = useReport(reportId, defaultParameters);
|
||||
|
||||
//console.log(report);
|
||||
|
||||
return (
|
||||
<ReportContext.Provider value={{ ...report }}>
|
||||
<Page {...props} className={styles.container}>
|
||||
|
|
|
|||
|
|
@ -64,24 +64,14 @@ export function ReportHeader({ icon }) {
|
|||
|
||||
return (
|
||||
<PageHeader title={<Title />} className={styles.header}>
|
||||
<Flexbox gap={20}>
|
||||
<DateFilter
|
||||
value={value}
|
||||
startDate={startDate}
|
||||
endDate={endDate}
|
||||
onChange={handleDateChange}
|
||||
showAllTime
|
||||
/>
|
||||
<WebsiteSelect websiteId={websiteId} onSelect={handleWebsiteSelect} />
|
||||
<LoadingButton
|
||||
variant="primary"
|
||||
loading={isCreating || isUpdating}
|
||||
disabled={!websiteId || !value}
|
||||
onClick={handleSave}
|
||||
>
|
||||
{formatMessage(labels.save)}
|
||||
</LoadingButton>
|
||||
</Flexbox>
|
||||
<LoadingButton
|
||||
variant="primary"
|
||||
loading={isCreating || isUpdating}
|
||||
disabled={!websiteId || !value}
|
||||
onClick={handleSave}
|
||||
>
|
||||
{formatMessage(labels.save)}
|
||||
</LoadingButton>
|
||||
{toast}
|
||||
</PageHeader>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import styles from './ReportList.module.css';
|
|||
const reports = [
|
||||
{
|
||||
title: 'Event data',
|
||||
description: 'Query your event data.',
|
||||
description: 'Query your custom event data.',
|
||||
url: '/reports/event-data',
|
||||
icon: <Nodes />,
|
||||
},
|
||||
|
|
|
|||
66
components/pages/reports/event-data/EventDataParameters.js
Normal file
66
components/pages/reports/event-data/EventDataParameters.js
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import { useContext, useRef } from 'react';
|
||||
import { useApi, useMessages } from 'hooks';
|
||||
import { Form, FormRow, FormButtons, SubmitButton, Loading } from 'react-basics';
|
||||
import { ReportContext } from 'components/pages/reports/Report';
|
||||
import NoData from 'components/common/NoData';
|
||||
import styles from './EventDataParameters.module.css';
|
||||
import { DATA_TYPES } from 'lib/constants';
|
||||
|
||||
function useFields(websiteId, startDate, endDate) {
|
||||
const { get, useQuery } = useApi();
|
||||
const { data, error, isLoading } = useQuery(
|
||||
['fields', websiteId, startDate, endDate],
|
||||
() => get('/reports/event-data', { websiteId, startAt: +startDate, endAt: +endDate }),
|
||||
{ enabled: !!(websiteId && startDate && endDate) },
|
||||
);
|
||||
|
||||
return { data, error, isLoading };
|
||||
}
|
||||
|
||||
export function EventDataParameters() {
|
||||
const { report, runReport, isRunning } = useContext(ReportContext);
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const ref = useRef(null);
|
||||
const { parameters } = report || {};
|
||||
const { websiteId, dateRange } = parameters || {};
|
||||
const { startDate, endDate } = dateRange || {};
|
||||
const queryDisabled = !websiteId || !dateRange;
|
||||
const { data, error, isLoading } = useFields(websiteId, startDate, endDate);
|
||||
|
||||
const handleSubmit = values => {
|
||||
runReport(values);
|
||||
};
|
||||
|
||||
if (!websiteId || !dateRange) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return <Loading icon="dots" />;
|
||||
}
|
||||
|
||||
return (
|
||||
<Form ref={ref} values={parameters} error={error} onSubmit={handleSubmit}>
|
||||
<FormRow label={formatMessage(labels.fields)}>
|
||||
<div className={styles.fields}>
|
||||
{!data?.length && <NoData />}
|
||||
{data?.map?.(({ eventKey, eventDataType }) => {
|
||||
return (
|
||||
<div className={styles.field} key={eventKey}>
|
||||
<div className={styles.key}>{eventKey}</div>
|
||||
<div className={styles.type}>{DATA_TYPES[eventDataType]}</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</FormRow>
|
||||
<FormButtons>
|
||||
<SubmitButton variant="primary" disabled={queryDisabled} loading={isRunning}>
|
||||
{formatMessage(labels.runQuery)}
|
||||
</SubmitButton>
|
||||
</FormButtons>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
|
||||
export default EventDataParameters;
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
.fields {
|
||||
max-height: 300px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.field {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
height: 30px;
|
||||
cursor: pointer;
|
||||
padding: 4px;
|
||||
border-radius: var(--border-radius);
|
||||
}
|
||||
|
||||
.field:hover {
|
||||
background: var(--base75);
|
||||
}
|
||||
|
||||
.key {
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.type {
|
||||
color: var(--font-color300);
|
||||
}
|
||||
|
|
@ -1,30 +1,23 @@
|
|||
import { useState } from 'react';
|
||||
import { Form, FormRow, FormInput, TextField } from 'react-basics';
|
||||
import Report from '../Report';
|
||||
import ReportHeader from '../ReportHeader';
|
||||
import useMessages from 'hooks/useMessages';
|
||||
import ReportMenu from '../ReportMenu';
|
||||
import ReportBody from '../ReportBody';
|
||||
import EventDataParameters from './EventDataParameters';
|
||||
import Nodes from 'assets/nodes.svg';
|
||||
import styles from '../reports.module.css';
|
||||
|
||||
export default function EventDataReport({ websiteId, data }) {
|
||||
const [values, setValues] = useState({ query: '' });
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const defaultParameters = {
|
||||
type: 'event-data',
|
||||
parameters: { fields: [], filters: [] },
|
||||
};
|
||||
|
||||
export default function EventDataReport({ reportId }) {
|
||||
return (
|
||||
<Report>
|
||||
<ReportHeader title={formatMessage(labels.eventData)} icon={<Nodes />} />
|
||||
<div className={styles.container}>
|
||||
<div className={styles.menu}>
|
||||
<Form>
|
||||
<FormRow label="Properties">
|
||||
<FormInput name="query">
|
||||
<TextField value={values.query} />
|
||||
</FormInput>
|
||||
</FormRow>
|
||||
</Form>
|
||||
</div>
|
||||
<div className={styles.content}></div>
|
||||
</div>
|
||||
<Report reportId={reportId} defaultParameters={defaultParameters}>
|
||||
<ReportHeader icon={<Nodes />} />
|
||||
<ReportMenu>
|
||||
<EventDataParameters />
|
||||
</ReportMenu>
|
||||
<ReportBody>hi.</ReportBody>
|
||||
</Report>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
28
components/pages/reports/event-data/FieldAddForm.js
Normal file
28
components/pages/reports/event-data/FieldAddForm.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { useMessages } from 'hooks';
|
||||
import { Button, Form, FormButtons, FormRow } from 'react-basics';
|
||||
|
||||
export function FieldAddForm({ onClose }) {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
|
||||
const handleSave = () => {
|
||||
onClose();
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
onClose();
|
||||
};
|
||||
|
||||
return (
|
||||
<Form>
|
||||
<FormRow label={formatMessage(labels.url)}></FormRow>
|
||||
<FormButtons align="center" flex>
|
||||
<Button variant="primary" onClick={handleSave}>
|
||||
{formatMessage(labels.save)}
|
||||
</Button>
|
||||
<Button onClick={handleClose}>{formatMessage(labels.cancel)}</Button>
|
||||
</FormButtons>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
|
||||
export default FieldAddForm;
|
||||
|
|
@ -6,98 +6,99 @@ import {
|
|||
FormButtons,
|
||||
FormInput,
|
||||
FormRow,
|
||||
Modal,
|
||||
PopupTrigger,
|
||||
Popup,
|
||||
SubmitButton,
|
||||
Text,
|
||||
TextField,
|
||||
Tooltip,
|
||||
} from 'react-basics';
|
||||
import Icons from 'components/icons';
|
||||
import AddUrlForm from './AddUrlForm';
|
||||
import UrlAddForm from './UrlAddForm';
|
||||
import { ReportContext } from 'components/pages/reports/Report';
|
||||
import styles from './FunnelParameters.module.css';
|
||||
import BaseParameters from '../BaseParameters';
|
||||
|
||||
export function FunnelParameters() {
|
||||
const { report, runReport, updateReport, isRunning } = useContext(ReportContext);
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const [show, setShow] = useState(false);
|
||||
const ref = useRef(null);
|
||||
const { websiteId, parameters } = report || {};
|
||||
const queryDisabled = !websiteId || parameters?.urls?.length < 2;
|
||||
|
||||
const { parameters } = report || {};
|
||||
const { websiteId, dateRange, urls } = parameters || {};
|
||||
const queryDisabled = !websiteId || !dateRange || urls?.length < 2;
|
||||
|
||||
const handleSubmit = values => {
|
||||
runReport(values);
|
||||
};
|
||||
|
||||
const handleAddUrl = url => {
|
||||
updateReport({ parameters: { ...parameters, urls: parameters.urls.concat(url) } });
|
||||
updateReport({ parameters: { urls: parameters.urls.concat(url) } });
|
||||
};
|
||||
|
||||
const handleRemoveUrl = (index, e) => {
|
||||
e.stopPropagation();
|
||||
const urls = [...parameters.urls];
|
||||
urls.splice(index, 1);
|
||||
updateReport({ parameters: { ...parameters, urls } });
|
||||
updateReport({ parameters: { urls } });
|
||||
};
|
||||
|
||||
const showAddForm = () => setShow(true);
|
||||
const hideAddForm = () => setShow(false);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Form ref={ref} values={parameters} onSubmit={handleSubmit}>
|
||||
<FormRow label={formatMessage(labels.window)}>
|
||||
<FormInput
|
||||
name="window"
|
||||
rules={{ required: formatMessage(labels.required), pattern: /[0-9]+/ }}
|
||||
>
|
||||
<TextField autoComplete="off" />
|
||||
</FormInput>
|
||||
</FormRow>
|
||||
<FormRow label={formatMessage(labels.urls)} action={<AddUrlButton onClick={showAddForm} />}>
|
||||
<div className={styles.urls}>
|
||||
{parameters?.urls?.map((url, index) => {
|
||||
return (
|
||||
<div key={index} className={styles.url}>
|
||||
<Text>{url}</Text>
|
||||
<Tooltip
|
||||
className={styles.icon}
|
||||
label={formatMessage(labels.remove)}
|
||||
position="right"
|
||||
>
|
||||
<Icon onClick={handleRemoveUrl.bind(null, index)}>
|
||||
<Icons.Close />
|
||||
</Icon>
|
||||
</Tooltip>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</FormRow>
|
||||
<FormButtons>
|
||||
<SubmitButton variant="primary" disabled={queryDisabled} loading={isRunning}>
|
||||
{formatMessage(labels.runQuery)}
|
||||
</SubmitButton>
|
||||
</FormButtons>
|
||||
</Form>
|
||||
{show && (
|
||||
<Modal onClose={hideAddForm}>
|
||||
<AddUrlForm onSave={handleAddUrl} onClose={hideAddForm} />
|
||||
</Modal>
|
||||
)}
|
||||
</>
|
||||
<Form ref={ref} values={parameters} onSubmit={handleSubmit}>
|
||||
<BaseParameters />
|
||||
<FormRow label={formatMessage(labels.window)}>
|
||||
<FormInput
|
||||
name="window"
|
||||
rules={{ required: formatMessage(labels.required), pattern: /[0-9]+/ }}
|
||||
>
|
||||
<TextField autoComplete="off" />
|
||||
</FormInput>
|
||||
</FormRow>
|
||||
<FormRow label={formatMessage(labels.urls)} action={<AddUrlButton onAdd={handleAddUrl} />}>
|
||||
<div className={styles.urls}>
|
||||
{parameters?.urls?.map((url, index) => {
|
||||
return (
|
||||
<div key={index} className={styles.url}>
|
||||
<Text>{url}</Text>
|
||||
<Tooltip
|
||||
className={styles.icon}
|
||||
label={formatMessage(labels.remove)}
|
||||
position="right"
|
||||
>
|
||||
<Icon onClick={handleRemoveUrl.bind(null, index)}>
|
||||
<Icons.Close />
|
||||
</Icon>
|
||||
</Tooltip>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</FormRow>
|
||||
<FormButtons>
|
||||
<SubmitButton variant="primary" disabled={queryDisabled} loading={isRunning}>
|
||||
{formatMessage(labels.runQuery)}
|
||||
</SubmitButton>
|
||||
</FormButtons>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
|
||||
function AddUrlButton({ onClick }) {
|
||||
function AddUrlButton({ onAdd }) {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
|
||||
return (
|
||||
<Tooltip label={formatMessage(labels.addUrl)}>
|
||||
<Icon onClick={onClick}>
|
||||
<Icons.Plus />
|
||||
</Icon>
|
||||
</Tooltip>
|
||||
<PopupTrigger>
|
||||
<Tooltip label={formatMessage(labels.addUrl)}>
|
||||
<Icon>
|
||||
<Icons.Plus />
|
||||
</Icon>
|
||||
</Tooltip>
|
||||
<Popup position="bottom" alignment="start">
|
||||
{close => {
|
||||
return <UrlAddForm onSave={onAdd} onClose={close} />;
|
||||
}}
|
||||
</Popup>
|
||||
</PopupTrigger>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,15 @@
|
|||
import { useContext } from 'react';
|
||||
import FunnelChart from './FunnelChart';
|
||||
import FunnelTable from './FunnelTable';
|
||||
import FunnelParameters from './FunnelParameters';
|
||||
import Report, { ReportContext } from '../Report';
|
||||
import Report from '../Report';
|
||||
import ReportHeader from '../ReportHeader';
|
||||
import ReportMenu from '../ReportMenu';
|
||||
import ReportBody from '../ReportBody';
|
||||
import Funnel from 'assets/funnel.svg';
|
||||
import { useReport } from 'hooks';
|
||||
|
||||
const defaultParameters = {
|
||||
type: 'funnel',
|
||||
parameters: { window: 60, urls: ['/', '/docs'] },
|
||||
parameters: { window: 60, urls: [] },
|
||||
};
|
||||
|
||||
export default function FunnelReport({ reportId }) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import { useState } from 'react';
|
||||
import { useMessages } from 'hooks';
|
||||
import { Button, Form, FormButtons, FormRow, TextField } from 'react-basics';
|
||||
import styles from './UrlAddForm.module.css';
|
||||
|
||||
export function AddUrlForm({ defaultValue = '', onSave, onClose }) {
|
||||
export function UrlAddForm({ defaultValue = '', onSave, onClose }) {
|
||||
const [url, setUrl] = useState(defaultValue);
|
||||
const { formatMessage, labels } = useMessages();
|
||||
|
||||
|
|
@ -22,7 +23,7 @@ export function AddUrlForm({ defaultValue = '', onSave, onClose }) {
|
|||
};
|
||||
|
||||
return (
|
||||
<Form>
|
||||
<Form className={styles.form}>
|
||||
<FormRow label={formatMessage(labels.url)}>
|
||||
<TextField
|
||||
name="url"
|
||||
|
|
@ -42,4 +43,4 @@ export function AddUrlForm({ defaultValue = '', onSave, onClose }) {
|
|||
);
|
||||
}
|
||||
|
||||
export default AddUrlForm;
|
||||
export default UrlAddForm;
|
||||
8
components/pages/reports/funnel/UrlAddForm.module.css
Normal file
8
components/pages/reports/funnel/UrlAddForm.module.css
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
.form {
|
||||
background: var(--base50);
|
||||
padding: 30px;
|
||||
margin-top: 10px;
|
||||
border: 1px solid var(--base400);
|
||||
border-radius: var(--border-radius);
|
||||
box-shadow: 0 0 0 5px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue