mirror of
https://github.com/umami-software/umami.git
synced 2026-02-12 08:37:13 +01:00
Events filtering. Closes #3356
This commit is contained in:
parent
b8a582c8da
commit
d4b786380b
4 changed files with 59 additions and 21 deletions
|
|
@ -4,27 +4,33 @@ import EventsDataTable from './EventsDataTable';
|
||||||
import EventsMetricsBar from './EventsMetricsBar';
|
import EventsMetricsBar from './EventsMetricsBar';
|
||||||
import EventsChart from '@/components/metrics/EventsChart';
|
import EventsChart from '@/components/metrics/EventsChart';
|
||||||
import { GridRow } from '@/components/layout/Grid';
|
import { GridRow } from '@/components/layout/Grid';
|
||||||
import MetricsTable from '@/components/metrics/MetricsTable';
|
import EventsTable from '@/components/metrics/EventsTable';
|
||||||
import { useMessages } from '@/components/hooks';
|
import { useMessages } from '@/components/hooks';
|
||||||
import { Item, Tabs } from 'react-basics';
|
import { Item, Tabs } from 'react-basics';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import EventProperties from './EventProperties';
|
import EventProperties from './EventProperties';
|
||||||
|
|
||||||
export default function EventsPage({ websiteId }) {
|
export default function EventsPage({ websiteId }) {
|
||||||
|
const [label, setLabel] = useState(null);
|
||||||
const [tab, setTab] = useState('activity');
|
const [tab, setTab] = useState('activity');
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
|
|
||||||
|
const handleLabelClick = (value: string) => {
|
||||||
|
setLabel(value !== label ? value : '');
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<WebsiteHeader websiteId={websiteId} />
|
<WebsiteHeader websiteId={websiteId} />
|
||||||
<EventsMetricsBar websiteId={websiteId} />
|
<EventsMetricsBar websiteId={websiteId} />
|
||||||
<GridRow columns="two-one">
|
<GridRow columns="two-one">
|
||||||
<EventsChart websiteId={websiteId} />
|
<EventsChart websiteId={websiteId} focusLabel={label} />
|
||||||
<MetricsTable
|
<EventsTable
|
||||||
websiteId={websiteId}
|
websiteId={websiteId}
|
||||||
type="event"
|
type="event"
|
||||||
title={formatMessage(labels.events)}
|
title={formatMessage(labels.events)}
|
||||||
metric={formatMessage(labels.actions)}
|
metric={formatMessage(labels.actions)}
|
||||||
|
onLabelClick={handleLabelClick}
|
||||||
/>
|
/>
|
||||||
</GridRow>
|
</GridRow>
|
||||||
<div>
|
<div>
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ export function Chart({
|
||||||
className,
|
className,
|
||||||
chartOptions,
|
chartOptions,
|
||||||
}: ChartProps) {
|
}: ChartProps) {
|
||||||
const canvas = useRef();
|
const canvas = useRef(null);
|
||||||
const chart = useRef(null);
|
const chart = useRef(null);
|
||||||
const [legendItems, setLegendItems] = useState([]);
|
const [legendItems, setLegendItems] = useState([]);
|
||||||
|
|
||||||
|
|
@ -86,7 +86,7 @@ export function Chart({
|
||||||
dataset.data = data?.datasets[index]?.data;
|
dataset.data = data?.datasets[index]?.data;
|
||||||
|
|
||||||
if (chart.current.legend.legendItems[index]) {
|
if (chart.current.legend.legendItems[index]) {
|
||||||
chart.current.legend.legendItems[index].text = data?.datasets[index]?.label;
|
chart.current.legend.legendItems[index].text = data.datasets[index]?.label;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -95,6 +95,12 @@ export function Chart({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data.focusLabel !== null) {
|
||||||
|
chart.current.data.datasets.forEach(ds => {
|
||||||
|
ds.hidden = data.focusLabel ? ds.label !== data.focusLabel : false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
chart.current.options = options;
|
chart.current.options = options;
|
||||||
|
|
||||||
// Allow config changes before update
|
// Allow config changes before update
|
||||||
|
|
@ -105,16 +111,6 @@ export function Chart({
|
||||||
setLegendItems(chart.current.legend.legendItems);
|
setLegendItems(chart.current.legend.legendItems);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (data) {
|
|
||||||
if (!chart.current) {
|
|
||||||
createChart(data);
|
|
||||||
} else {
|
|
||||||
updateChart(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [data, options]);
|
|
||||||
|
|
||||||
const handleLegendClick = (item: LegendItem) => {
|
const handleLegendClick = (item: LegendItem) => {
|
||||||
if (type === 'bar') {
|
if (type === 'bar') {
|
||||||
const { datasetIndex } = item;
|
const { datasetIndex } = item;
|
||||||
|
|
@ -136,6 +132,16 @@ export function Chart({
|
||||||
setLegendItems(chart.current.legend.legendItems);
|
setLegendItems(chart.current.legend.legendItems);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (data) {
|
||||||
|
if (!chart.current) {
|
||||||
|
createChart(data);
|
||||||
|
} else {
|
||||||
|
updateChart(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [data, options]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className={classNames(styles.chart, className)}>
|
<div className={classNames(styles.chart, className)}>
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,23 @@
|
||||||
|
import { useMemo, useState, useEffect } from 'react';
|
||||||
import { colord } from 'colord';
|
import { colord } from 'colord';
|
||||||
import BarChart from '@/components/charts/BarChart';
|
import BarChart from '@/components/charts/BarChart';
|
||||||
import { useDateRange, useLocale, useWebsiteEventsSeries } from '@/components/hooks';
|
import { useDateRange, useLocale, useWebsiteEventsSeries } from '@/components/hooks';
|
||||||
import { renderDateLabels } from '@/lib/charts';
|
import { renderDateLabels } from '@/lib/charts';
|
||||||
import { CHART_COLORS } from '@/lib/constants';
|
import { CHART_COLORS } from '@/lib/constants';
|
||||||
import { useMemo } from 'react';
|
|
||||||
|
|
||||||
export interface EventsChartProps {
|
export interface EventsChartProps {
|
||||||
websiteId: string;
|
websiteId: string;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
focusLabel?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function EventsChart({ websiteId, className }: EventsChartProps) {
|
export function EventsChart({ websiteId, className, focusLabel }: EventsChartProps) {
|
||||||
const {
|
const {
|
||||||
dateRange: { startDate, endDate, unit, value },
|
dateRange: { startDate, endDate, unit, value },
|
||||||
} = useDateRange(websiteId);
|
} = useDateRange(websiteId);
|
||||||
const { locale } = useLocale();
|
const { locale } = useLocale();
|
||||||
const { data, isLoading } = useWebsiteEventsSeries(websiteId);
|
const { data, isLoading } = useWebsiteEventsSeries(websiteId);
|
||||||
|
const [label, setLabel] = useState<string>(focusLabel);
|
||||||
|
|
||||||
const chartData = useMemo(() => {
|
const chartData = useMemo(() => {
|
||||||
if (!data) return [];
|
if (!data) return [];
|
||||||
|
|
@ -42,8 +44,15 @@ export function EventsChart({ websiteId, className }: EventsChartProps) {
|
||||||
borderWidth: 1,
|
borderWidth: 1,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
|
focusLabel,
|
||||||
};
|
};
|
||||||
}, [data, startDate, endDate, unit]);
|
}, [data, startDate, endDate, unit, focusLabel]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (label !== focusLabel) {
|
||||||
|
setLabel(focusLabel);
|
||||||
|
}
|
||||||
|
}, [focusLabel]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BarChart
|
<BarChart
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,28 @@
|
||||||
import MetricsTable, { MetricsTableProps } from './MetricsTable';
|
import MetricsTable, { MetricsTableProps } from './MetricsTable';
|
||||||
import { useMessages } from '@/components/hooks';
|
import { useMessages } from '@/components/hooks';
|
||||||
|
|
||||||
export function EventsTable(props: MetricsTableProps) {
|
export interface EventsTableProps extends MetricsTableProps {
|
||||||
|
onLabelClick?: (value: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function EventsTable({ onLabelClick, ...props }: EventsTableProps) {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
|
|
||||||
function handleDataLoad(data: any) {
|
const handleDataLoad = (data: any) => {
|
||||||
props.onDataLoad?.(data);
|
props.onDataLoad?.(data);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const renderLabel = ({ x: label }) => {
|
||||||
|
if (onLabelClick) {
|
||||||
|
return (
|
||||||
|
<div onClick={() => onLabelClick(label)} style={{ cursor: 'pointer' }}>
|
||||||
|
{label}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return label;
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MetricsTable
|
<MetricsTable
|
||||||
|
|
@ -15,6 +31,7 @@ export function EventsTable(props: MetricsTableProps) {
|
||||||
type="event"
|
type="event"
|
||||||
metric={formatMessage(labels.actions)}
|
metric={formatMessage(labels.actions)}
|
||||||
onDataLoad={handleDataLoad}
|
onDataLoad={handleDataLoad}
|
||||||
|
renderLabel={renderLabel}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue