Lint format files. Updated rng function.
This commit is contained in:
1 parent
5bf1792b38
commit
306ca4a435
144 files changed
+962
-626
No files matched your search
@@ -37,7 +37,9 @@ export function PropertyChart({
|
||||
}) {
|
||||
const { t, labels } = useMessages();
|
||||
const { timezone } = useTimezone();
|
||||
const { dateRange: { startDate, endDate, unit } } = useDateRange({ timezone });
|
||||
const {
|
||||
dateRange: { startDate, endDate, unit },
|
||||
} = useDateRange({ timezone });
|
||||
const { locale, dateLocale } = useLocale();
|
||||
const propertySeriesQuery = usePropertySeriesQuery(
|
||||
source,
|
||||
|
||||
@@ -5,18 +5,23 @@ import {
|
||||
format,
|
||||
formatDistance,
|
||||
isValid,
|
||||
type Locale,
|
||||
startOfDay,
|
||||
startOfMonth,
|
||||
startOfWeek,
|
||||
startOfYear,
|
||||
type Locale,
|
||||
} from 'date-fns';
|
||||
import { toZonedTime } from 'date-fns-tz';
|
||||
import { type ReactNode, useCallback, useMemo } from 'react';
|
||||
import { BarChart } from '@/components/charts/BarChart';
|
||||
import { PieChart } from '@/components/charts/PieChart';
|
||||
import { LoadingPanel } from '@/components/common/LoadingPanel';
|
||||
import { useLocale, useMessages, usePropertyDateSeriesQuery, useTimezone } from '@/components/hooks';
|
||||
import {
|
||||
useLocale,
|
||||
useMessages,
|
||||
usePropertyDateSeriesQuery,
|
||||
useTimezone,
|
||||
} from '@/components/hooks';
|
||||
import type { PropertyDataSource } from '@/components/hooks/queries/usePropertyFieldsQuery';
|
||||
import { ListTable } from '@/components/metrics/ListTable';
|
||||
import { MetricsBar } from '@/components/metrics/MetricsBar';
|
||||
@@ -30,7 +35,11 @@ type DateChartUnit = 'day' | 'week' | 'month' | 'year';
|
||||
type ParsedDateRow = EventDataDateSeriesPoint & { date: Date };
|
||||
|
||||
function parseDateValue(value: string) {
|
||||
const normalized = value?.trim().replace(' ', 'T').replace(/Z$/, '').replace(/\.\d+$/, '');
|
||||
const normalized = value
|
||||
?.trim()
|
||||
.replace(' ', 'T')
|
||||
.replace(/Z$/, '')
|
||||
.replace(/\.\d+$/, '');
|
||||
const [datePart = '', timePart = '00:00:00'] = normalized.split('T');
|
||||
const [year = 0, month = 1, day = 1] = datePart.split('-').map(Number);
|
||||
const [hour = 0, minute = 0, second = 0] = timePart.split(':').map(Number);
|
||||
@@ -52,9 +61,17 @@ function InsightCard({ label, value, hint }: { label: string; value: string; hin
|
||||
height="100%"
|
||||
style={{ minWidth: 0 }}
|
||||
>
|
||||
<Text weight="bold" style={{ overflowWrap: 'anywhere' }}>{label}</Text>
|
||||
<Text weight="bold" style={{ overflowWrap: 'anywhere' }}>{value}</Text>
|
||||
{hint && <Text color="muted" style={{ overflowWrap: 'anywhere' }}>{hint}</Text>}
|
||||
<Text weight="bold" style={{ overflowWrap: 'anywhere' }}>
|
||||
{label}
|
||||
</Text>
|
||||
<Text weight="bold" style={{ overflowWrap: 'anywhere' }}>
|
||||
{value}
|
||||
</Text>
|
||||
{hint && (
|
||||
<Text color="muted" style={{ overflowWrap: 'anywhere' }}>
|
||||
{hint}
|
||||
</Text>
|
||||
)}
|
||||
</Column>
|
||||
);
|
||||
}
|
||||
@@ -98,7 +115,13 @@ export function PropertyDateChart({
|
||||
const { locale, dateLocale } = useLocale();
|
||||
const { timezone } = useTimezone();
|
||||
const { colors } = useMemo(() => getThemeColors(theme), [theme]);
|
||||
const query = usePropertyDateSeriesQuery(source, websiteId, propertyName, propertyFilters, eventName);
|
||||
const query = usePropertyDateSeriesQuery(
|
||||
source,
|
||||
websiteId,
|
||||
propertyName,
|
||||
propertyFilters,
|
||||
eventName,
|
||||
);
|
||||
|
||||
const rows = useMemo(() => query.data ?? [], [query.data]);
|
||||
const total = useMemo(() => rows.reduce((sum, { y }) => sum + y, 0), [rows]);
|
||||
@@ -119,7 +142,8 @@ export function PropertyDateChart({
|
||||
const minPropertyDate = exactDateRows[0]?.date ?? null;
|
||||
const maxPropertyDate = exactDateRows[exactDateRows.length - 1]?.date ?? null;
|
||||
const chartUnit = useMemo(
|
||||
() => (minPropertyDate && maxPropertyDate ? getChartUnit(minPropertyDate, maxPropertyDate) : 'day'),
|
||||
() =>
|
||||
minPropertyDate && maxPropertyDate ? getChartUnit(minPropertyDate, maxPropertyDate) : 'day',
|
||||
[maxPropertyDate, minPropertyDate],
|
||||
);
|
||||
|
||||
@@ -216,17 +240,28 @@ export function PropertyDateChart({
|
||||
},
|
||||
{} as Record<string, { date: Date; count: number }>,
|
||||
);
|
||||
return Object.values(dayTotals).sort((a, b) => b.count - a.count || b.date.getTime() - a.date.getTime())[0];
|
||||
return Object.values(dayTotals).sort(
|
||||
(a, b) => b.count - a.count || b.date.getTime() - a.date.getTime(),
|
||||
)[0];
|
||||
}, [exactDateRows, total]);
|
||||
|
||||
const topWeekday = useMemo(() => [...weekdayTableData].sort((a, b) => b.count - a.count)[0], [weekdayTableData]);
|
||||
const weekdayLabels = useMemo(() => weekdayTableData.map(({ label }) => label), [weekdayTableData]);
|
||||
const topWeekday = useMemo(
|
||||
() => [...weekdayTableData].sort((a, b) => b.count - a.count)[0],
|
||||
[weekdayTableData],
|
||||
);
|
||||
const weekdayLabels = useMemo(
|
||||
() => weekdayTableData.map(({ label }) => label),
|
||||
[weekdayTableData],
|
||||
);
|
||||
const weekdayColorMap = useMemo(
|
||||
() =>
|
||||
weekdayLabels.reduce((obj, label, index) => {
|
||||
obj[label] = CHART_COLORS[index % CHART_COLORS.length];
|
||||
return obj;
|
||||
}, {} as Record<string, string>),
|
||||
weekdayLabels.reduce(
|
||||
(obj, label, index) => {
|
||||
obj[label] = CHART_COLORS[index % CHART_COLORS.length];
|
||||
return obj;
|
||||
},
|
||||
{} as Record<string, string>,
|
||||
),
|
||||
[weekdayLabels],
|
||||
);
|
||||
|
||||
@@ -246,27 +281,48 @@ export function PropertyDateChart({
|
||||
|
||||
return (
|
||||
<Column gap="4">
|
||||
<LoadingPanel isLoading={query.isLoading} isFetching={query.isFetching} error={query.error} minHeight="100px">
|
||||
<LoadingPanel
|
||||
isLoading={query.isLoading}
|
||||
isFetching={query.isFetching}
|
||||
error={query.error}
|
||||
minHeight="100px"
|
||||
>
|
||||
<MetricsBar padding="2">
|
||||
<InsightCard
|
||||
label="Top weekday"
|
||||
value={topWeekday?.label ?? 'None'}
|
||||
hint={topWeekday ? `${topWeekday.count.toLocaleString(locale)} count - ${Math.round(topWeekday.percent)}%` : undefined}
|
||||
hint={
|
||||
topWeekday
|
||||
? `${topWeekday.count.toLocaleString(locale)} count - ${Math.round(topWeekday.percent)}%`
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
<InsightCard
|
||||
label="Top date"
|
||||
value={topDateByDay ? formatDate(topDateByDay.date, 'PP', locale) : 'None'}
|
||||
hint={topDateByDay ? `${topDateByDay.count.toLocaleString(locale)} count - ${Math.round((topDateByDay.count / total) * 100)}%` : undefined}
|
||||
hint={
|
||||
topDateByDay
|
||||
? `${topDateByDay.count.toLocaleString(locale)} count - ${Math.round((topDateByDay.count / total) * 100)}%`
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
<InsightCard
|
||||
label="Earliest date"
|
||||
value={minPropertyDate ? formatDate(minPropertyDate, 'PP', locale) : 'None'}
|
||||
hint={minPropertyDate ? formatDistance(minPropertyDate, zonedNow, { addSuffix: true }) : undefined}
|
||||
hint={
|
||||
minPropertyDate
|
||||
? formatDistance(minPropertyDate, zonedNow, { addSuffix: true })
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
<InsightCard
|
||||
label="Latest date"
|
||||
value={maxPropertyDate ? formatDate(maxPropertyDate, 'PP', locale) : 'None'}
|
||||
hint={maxPropertyDate ? formatDistance(maxPropertyDate, zonedNow, { addSuffix: true }) : undefined}
|
||||
hint={
|
||||
maxPropertyDate
|
||||
? formatDistance(maxPropertyDate, zonedNow, { addSuffix: true })
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
</MetricsBar>
|
||||
</LoadingPanel>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
'use client';
|
||||
import { useMessages } from '@/components/hooks';
|
||||
import type { PropertyDataSource } from '@/components/hooks/queries/usePropertyFieldsQuery';
|
||||
import { ListFilter } from '@/components/icons';
|
||||
import { DialogButton } from '@/components/input/DialogButton';
|
||||
import type { PropertyFilter } from '@/lib/types';
|
||||
import type { PropertyDataSource } from '@/components/hooks/queries/usePropertyFieldsQuery';
|
||||
import { PropertyFilterEditForm } from './PropertyFilterEditForm';
|
||||
|
||||
export function PropertyFilterButton({
|
||||
|
||||
@@ -1,13 +1,25 @@
|
||||
'use client';
|
||||
import { Button, Column, Grid, Icon, List, ListItem, Menu, MenuItem, MenuTrigger, Popover, Row } from '@umami/react-zen';
|
||||
import {
|
||||
Button,
|
||||
Column,
|
||||
Grid,
|
||||
Icon,
|
||||
List,
|
||||
ListItem,
|
||||
Menu,
|
||||
MenuItem,
|
||||
MenuTrigger,
|
||||
Popover,
|
||||
Row,
|
||||
} from '@umami/react-zen';
|
||||
import { format } from 'date-fns';
|
||||
import { useState } from 'react';
|
||||
import { Empty } from '@/components/common/Empty';
|
||||
import { useMessages, useMobile, usePropertyFieldsQuery } from '@/components/hooks';
|
||||
import type { PropertyDataSource } from '@/components/hooks/queries/usePropertyFieldsQuery';
|
||||
import { Plus } from '@/components/icons';
|
||||
import { DATA_TYPE, OPERATORS } from '@/lib/constants';
|
||||
import type { PropertyFilter } from '@/lib/types';
|
||||
import type { PropertyDataSource } from '@/components/hooks/queries/usePropertyFieldsQuery';
|
||||
import { PropertyFilterRecord } from './PropertyFilterRecord';
|
||||
|
||||
export function PropertyFilterEditForm({
|
||||
@@ -76,7 +88,10 @@ export function PropertyFilterEditForm({
|
||||
style={{ maxHeight: 'calc(100vh - 2rem)', overflowY: 'auto' }}
|
||||
>
|
||||
{(fields as any[]).map(field => (
|
||||
<MenuItem key={`${field.propertyName}:${field.dataType}`} id={field.propertyName}>
|
||||
<MenuItem
|
||||
key={`${field.propertyName}:${field.dataType}`}
|
||||
id={field.propertyName}
|
||||
>
|
||||
{field.propertyName}
|
||||
</MenuItem>
|
||||
))}
|
||||
|
||||
@@ -1,16 +1,32 @@
|
||||
'use client';
|
||||
import { Button, Calendar, Column, ComboBox, Dialog, DialogTrigger, Grid, Icon, Label, ListItem, Loading, Popover, Row, Select, TextField } from '@umami/react-zen';
|
||||
import {
|
||||
Button,
|
||||
Calendar,
|
||||
Column,
|
||||
ComboBox,
|
||||
Dialog,
|
||||
DialogTrigger,
|
||||
Grid,
|
||||
Icon,
|
||||
Label,
|
||||
ListItem,
|
||||
Loading,
|
||||
Popover,
|
||||
Row,
|
||||
Select,
|
||||
TextField,
|
||||
} from '@umami/react-zen';
|
||||
import { format, parseISO } from 'date-fns';
|
||||
import { useState } from 'react';
|
||||
import { DateDisplay } from '@/components/common/DateDisplay';
|
||||
import { Empty } from '@/components/common/Empty';
|
||||
import { MultiSelect } from '@/components/common/MultiSelect';
|
||||
import { useMessages, usePropertyValuesQuery } from '@/components/hooks';
|
||||
import type { PropertyDataSource } from '@/components/hooks/queries/usePropertyFieldsQuery';
|
||||
import { X } from '@/components/icons';
|
||||
import { DATA_TYPE, OPERATORS } from '@/lib/constants';
|
||||
import { getMaxSelectableDate } from '@/lib/date';
|
||||
import type { Operator, PropertyFilter } from '@/lib/types';
|
||||
import type { PropertyDataSource } from '@/components/hooks/queries/usePropertyFieldsQuery';
|
||||
|
||||
const STRING_OPERATORS: Operator[] = [
|
||||
OPERATORS.equals,
|
||||
@@ -92,19 +108,32 @@ export function PropertyFilterRecord({
|
||||
|
||||
const operatorLabel = (op: Operator) => {
|
||||
switch (op) {
|
||||
case OPERATORS.equals: return t(labels.is);
|
||||
case OPERATORS.notEquals: return t(labels.isNot);
|
||||
case OPERATORS.contains: return t(labels.contains);
|
||||
case OPERATORS.doesNotContain: return t(labels.doesNotContain);
|
||||
case OPERATORS.regex: return t(labels.regexMatch);
|
||||
case OPERATORS.notRegex: return t(labels.regexNotMatch);
|
||||
case OPERATORS.greaterThan: return t(labels.greaterThan);
|
||||
case OPERATORS.lessThan: return t(labels.lessThan);
|
||||
case OPERATORS.greaterThanEquals: return t(labels.greaterThanEquals);
|
||||
case OPERATORS.lessThanEquals: return t(labels.lessThanEquals);
|
||||
case OPERATORS.before: return t(labels.before);
|
||||
case OPERATORS.after: return t(labels.after);
|
||||
default: return op;
|
||||
case OPERATORS.equals:
|
||||
return t(labels.is);
|
||||
case OPERATORS.notEquals:
|
||||
return t(labels.isNot);
|
||||
case OPERATORS.contains:
|
||||
return t(labels.contains);
|
||||
case OPERATORS.doesNotContain:
|
||||
return t(labels.doesNotContain);
|
||||
case OPERATORS.regex:
|
||||
return t(labels.regexMatch);
|
||||
case OPERATORS.notRegex:
|
||||
return t(labels.regexNotMatch);
|
||||
case OPERATORS.greaterThan:
|
||||
return t(labels.greaterThan);
|
||||
case OPERATORS.lessThan:
|
||||
return t(labels.lessThan);
|
||||
case OPERATORS.greaterThanEquals:
|
||||
return t(labels.greaterThanEquals);
|
||||
case OPERATORS.lessThanEquals:
|
||||
return t(labels.lessThanEquals);
|
||||
case OPERATORS.before:
|
||||
return t(labels.before);
|
||||
case OPERATORS.after:
|
||||
return t(labels.after);
|
||||
default:
|
||||
return op;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -123,7 +152,10 @@ export function PropertyFilterRecord({
|
||||
<Label>{filter.propertyName}</Label>
|
||||
<Grid columns="1fr auto" gap>
|
||||
<Grid columns={{ base: '1fr', md: '200px 1fr' }} gap>
|
||||
<Select value={filter.operator} onChange={value => handleOperatorChange(value as Operator)}>
|
||||
<Select
|
||||
value={filter.operator}
|
||||
onChange={value => handleOperatorChange(value as Operator)}
|
||||
>
|
||||
{operators.map(op => (
|
||||
<ListItem key={op} id={op}>
|
||||
{operatorLabel(op)}
|
||||
|
||||
@@ -36,16 +36,44 @@ export function PropertyNumericChart({
|
||||
const { t, labels } = useMessages();
|
||||
const { theme } = useTheme();
|
||||
const { timezone } = useTimezone();
|
||||
const { dateRange: { startDate, endDate, unit } } = useDateRange({ timezone });
|
||||
const {
|
||||
dateRange: { startDate, endDate, unit },
|
||||
} = useDateRange({ timezone });
|
||||
const { locale, dateLocale } = useLocale();
|
||||
const { colors } = useMemo(() => getThemeColors(theme), [theme]);
|
||||
|
||||
const sumQuery = usePropertyNumericSeriesQuery(source, websiteId, propertyName, 'sum', propertyFilters, eventName);
|
||||
const avgQuery = usePropertyNumericSeriesQuery(source, websiteId, propertyName, 'avg', propertyFilters, eventName);
|
||||
const statsQuery = usePropertyNumericStatsQuery(source, websiteId, propertyName, propertyFilters, eventName);
|
||||
const sumQuery = usePropertyNumericSeriesQuery(
|
||||
source,
|
||||
websiteId,
|
||||
propertyName,
|
||||
'sum',
|
||||
propertyFilters,
|
||||
eventName,
|
||||
);
|
||||
const avgQuery = usePropertyNumericSeriesQuery(
|
||||
source,
|
||||
websiteId,
|
||||
propertyName,
|
||||
'avg',
|
||||
propertyFilters,
|
||||
eventName,
|
||||
);
|
||||
const statsQuery = usePropertyNumericStatsQuery(
|
||||
source,
|
||||
websiteId,
|
||||
propertyName,
|
||||
propertyFilters,
|
||||
eventName,
|
||||
);
|
||||
|
||||
const sumRows = useMemo(() => (sumQuery.data as { t: string; y: number }[] | undefined) ?? [], [sumQuery.data]);
|
||||
const avgRows = useMemo(() => (avgQuery.data as { t: string; y: number }[] | undefined) ?? [], [avgQuery.data]);
|
||||
const sumRows = useMemo(
|
||||
() => (sumQuery.data as { t: string; y: number }[] | undefined) ?? [],
|
||||
[sumQuery.data],
|
||||
);
|
||||
const avgRows = useMemo(
|
||||
() => (avgQuery.data as { t: string; y: number }[] | undefined) ?? [],
|
||||
[avgQuery.data],
|
||||
);
|
||||
const stats = statsQuery.data;
|
||||
|
||||
const chartData: any = useMemo(() => {
|
||||
@@ -85,7 +113,20 @@ export function PropertyNumericChart({
|
||||
},
|
||||
],
|
||||
};
|
||||
}, [avgQuery.data, avgRows, colors, dateLocale, endDate, labels.average, labels.sum, startDate, sumQuery.data, sumRows, t, unit]);
|
||||
}, [
|
||||
avgQuery.data,
|
||||
avgRows,
|
||||
colors,
|
||||
dateLocale,
|
||||
endDate,
|
||||
labels.average,
|
||||
labels.sum,
|
||||
startDate,
|
||||
sumQuery.data,
|
||||
sumRows,
|
||||
t,
|
||||
unit,
|
||||
]);
|
||||
|
||||
const renderXLabel = useCallback(renderDateLabels(unit, locale), [unit, locale]);
|
||||
|
||||
@@ -99,11 +140,27 @@ export function PropertyNumericChart({
|
||||
minHeight="100px"
|
||||
>
|
||||
<MetricsBar padding="2">
|
||||
<MetricCard label={t(labels.total)} value={stats?.total ?? 0} formatValue={formatLongNumber} />
|
||||
<MetricCard label={t(labels.average)} value={stats?.average ?? 0} formatValue={formatLongNumber} />
|
||||
<MetricCard
|
||||
label={t(labels.total)}
|
||||
value={stats?.total ?? 0}
|
||||
formatValue={formatLongNumber}
|
||||
/>
|
||||
<MetricCard
|
||||
label={t(labels.average)}
|
||||
value={stats?.average ?? 0}
|
||||
formatValue={formatLongNumber}
|
||||
/>
|
||||
<MetricCard label="Median" value={stats?.median ?? 0} formatValue={formatLongNumber} />
|
||||
<MetricCard label={t(labels.max)} value={stats?.max ?? 0} formatValue={formatLongNumber} />
|
||||
<MetricCard label={t(labels.min)} value={stats?.min ?? 0} formatValue={formatLongNumber} />
|
||||
<MetricCard
|
||||
label={t(labels.max)}
|
||||
value={stats?.max ?? 0}
|
||||
formatValue={formatLongNumber}
|
||||
/>
|
||||
<MetricCard
|
||||
label={t(labels.min)}
|
||||
value={stats?.min ?? 0}
|
||||
formatValue={formatLongNumber}
|
||||
/>
|
||||
</MetricsBar>
|
||||
</LoadingPanel>
|
||||
<LoadingPanel
|
||||
|
||||
Reference in new issue
Block a user