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
@@ -1,3 +1,5 @@
|
||||
import { useTheme } from '@umami/react-zen';
|
||||
import { memo, useCallback, useMemo, useState } from 'react';
|
||||
import { Chart, type ChartProps } from '@/components/charts/Chart';
|
||||
import { ChartTooltip } from '@/components/charts/ChartTooltip';
|
||||
import { useLocale } from '@/components/hooks';
|
||||
@@ -5,8 +7,6 @@ import { renderNumberLabels } from '@/lib/charts';
|
||||
import { getThemeColors } from '@/lib/colors';
|
||||
import { DATE_FORMATS, formatDate } from '@/lib/date';
|
||||
import { formatLongCurrency, formatLongNumber } from '@/lib/format';
|
||||
import { useTheme } from '@umami/react-zen';
|
||||
import { memo, useCallback, useMemo, useState } from 'react';
|
||||
|
||||
const MemoChart = memo(Chart);
|
||||
|
||||
|
||||
@@ -127,31 +127,38 @@ function DistributionBarChartComponent({
|
||||
[chartData.labels, colors, horizontal, stacked],
|
||||
);
|
||||
|
||||
const handleTooltip = useCallback(({ tooltip }: { tooltip: any }) => {
|
||||
const { opacity, labelColors, dataPoints } = tooltip;
|
||||
const point = dataPoints?.[0];
|
||||
const nextTooltip = opacity
|
||||
? {
|
||||
title: (point?.label ?? '').toString(),
|
||||
color: labelColors?.[0]?.backgroundColor,
|
||||
value: `${formatLongNumber(
|
||||
Number(horizontal ? point?.raw?.x ?? point?.raw ?? 0 : point?.raw?.y ?? point?.raw ?? 0),
|
||||
)}${point?.dataset?.label ? ` ${point.dataset.label}` : ''}`,
|
||||
const handleTooltip = useCallback(
|
||||
({ tooltip }: { tooltip: any }) => {
|
||||
const { opacity, labelColors, dataPoints } = tooltip;
|
||||
const point = dataPoints?.[0];
|
||||
const nextTooltip = opacity
|
||||
? {
|
||||
title: (point?.label ?? '').toString(),
|
||||
color: labelColors?.[0]?.backgroundColor,
|
||||
value: `${formatLongNumber(
|
||||
Number(
|
||||
horizontal
|
||||
? (point?.raw?.x ?? point?.raw ?? 0)
|
||||
: (point?.raw?.y ?? point?.raw ?? 0),
|
||||
),
|
||||
)}${point?.dataset?.label ? ` ${point.dataset.label}` : ''}`,
|
||||
}
|
||||
: null;
|
||||
|
||||
setTooltip(prev => {
|
||||
if (
|
||||
prev?.title === nextTooltip?.title &&
|
||||
prev?.color === nextTooltip?.color &&
|
||||
prev?.value === nextTooltip?.value
|
||||
) {
|
||||
return prev;
|
||||
}
|
||||
: null;
|
||||
|
||||
setTooltip(prev => {
|
||||
if (
|
||||
prev?.title === nextTooltip?.title &&
|
||||
prev?.color === nextTooltip?.color &&
|
||||
prev?.value === nextTooltip?.value
|
||||
) {
|
||||
return prev;
|
||||
}
|
||||
|
||||
return nextTooltip;
|
||||
});
|
||||
}, [horizontal]);
|
||||
return nextTooltip;
|
||||
});
|
||||
},
|
||||
[horizontal],
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -54,29 +54,29 @@
|
||||
background: var(--text-muted);
|
||||
}
|
||||
|
||||
:global([data-theme='dark']) .good {
|
||||
:global([data-theme="dark"]) .good {
|
||||
color: #86efac;
|
||||
background: rgba(22, 163, 74, 0.15);
|
||||
}
|
||||
|
||||
:global([data-theme='dark']) .good .dot {
|
||||
:global([data-theme="dark"]) .good .dot {
|
||||
background: #4ade80;
|
||||
}
|
||||
|
||||
:global([data-theme='dark']) .warning {
|
||||
:global([data-theme="dark"]) .warning {
|
||||
color: #fde047;
|
||||
background: rgba(202, 138, 4, 0.15);
|
||||
}
|
||||
|
||||
:global([data-theme='dark']) .warning .dot {
|
||||
:global([data-theme="dark"]) .warning .dot {
|
||||
background: #facc15;
|
||||
}
|
||||
|
||||
:global([data-theme='dark']) .danger {
|
||||
:global([data-theme="dark"]) .danger {
|
||||
color: #fca5a5;
|
||||
background: rgba(220, 38, 38, 0.15);
|
||||
}
|
||||
|
||||
:global([data-theme='dark']) .danger .dot {
|
||||
:global([data-theme="dark"]) .danger .dot {
|
||||
background: #f87171;
|
||||
}
|
||||
@@ -2,13 +2,7 @@ import { Button, Icon } from '@umami/react-zen';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { Check, Copy } from '@/components/icons';
|
||||
|
||||
export function CopyButton({
|
||||
value,
|
||||
label = 'Copy',
|
||||
}: {
|
||||
value: string;
|
||||
label?: string;
|
||||
}) {
|
||||
export function CopyButton({ value, label = 'Copy' }: { value: string; label?: string }) {
|
||||
const [copied, setCopied] = useState(false);
|
||||
const timeoutRef = useRef<number | null>(null);
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ export function DataGrid({
|
||||
return stored === 'table' || stored === 'cards' ? stored : null;
|
||||
});
|
||||
|
||||
const displayMode: DisplayMode | undefined = isMobile ? 'cards' : userDisplayMode ?? undefined;
|
||||
const displayMode: DisplayMode | undefined = isMobile ? 'cards' : (userDisplayMode ?? undefined);
|
||||
|
||||
const handleToggleDisplayMode = () => {
|
||||
const next: DisplayMode = displayMode === 'cards' ? 'table' : 'cards';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Icon, Row, Text } from '@umami/react-zen';
|
||||
import Link, { type LinkProps } from '@/components/common/Link';
|
||||
import type { ReactNode } from 'react';
|
||||
import Link, { type LinkProps } from '@/components/common/Link';
|
||||
import { ExternalLink as LinkIcon } from '@/components/icons';
|
||||
|
||||
export function ExternalLink({
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Icon, Row, Text } from '@umami/react-zen';
|
||||
import Link from '@/components/common/Link';
|
||||
import { type HTMLAttributes, type ReactNode, useState } from 'react';
|
||||
import Link from '@/components/common/Link';
|
||||
import { useMessages, useNavigation } from '@/components/hooks';
|
||||
import { ExternalLink } from '@/components/icons';
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Button, type ButtonProps } from '@umami/react-zen';
|
||||
import Link from '@/components/common/Link';
|
||||
import type { ReactNode } from 'react';
|
||||
import Link from '@/components/common/Link';
|
||||
import { useLocale } from '@/components/hooks';
|
||||
|
||||
export interface LinkButtonProps extends ButtonProps {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Column, Heading, Row, Text } from '@umami/react-zen';
|
||||
import Link from '@/components/common/Link';
|
||||
import { IconLabel } from '@/components/common/IconLabel';
|
||||
import Link from '@/components/common/Link';
|
||||
|
||||
interface NavMenuData {
|
||||
id: string;
|
||||
|
||||
@@ -11,13 +11,7 @@ export interface PagerProps {
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function Pager({
|
||||
page,
|
||||
pageSize,
|
||||
count,
|
||||
isCapped,
|
||||
onPageChange,
|
||||
}: PagerProps) {
|
||||
export function Pager({ page, pageSize, count, isCapped, onPageChange }: PagerProps) {
|
||||
const { t, labels } = useMessages();
|
||||
const maxPage = pageSize && count ? Math.ceil(+count / +pageSize) : 0;
|
||||
const lastPage = page === maxPage;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
'use client';
|
||||
|
||||
import type { ReactNode } from 'react';
|
||||
import { Icon } from '@umami/react-zen';
|
||||
import { ChevronDown, ChevronUp } from '@/components/icons';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useNavigation } from '@/components/hooks';
|
||||
import { ChevronDown, ChevronUp } from '@/components/icons';
|
||||
|
||||
type SortDirection = 'asc' | 'desc';
|
||||
|
||||
@@ -13,11 +13,7 @@ export interface SortableLabelProps {
|
||||
defaultDirection?: SortDirection;
|
||||
}
|
||||
|
||||
export function SortableLabel({
|
||||
label,
|
||||
sortKey,
|
||||
defaultDirection = 'asc',
|
||||
}: SortableLabelProps) {
|
||||
export function SortableLabel({ label, sortKey, defaultDirection = 'asc' }: SortableLabelProps) {
|
||||
const { router, query, updateParams } = useNavigation();
|
||||
const isActive = query.orderBy === sortKey;
|
||||
const isDescending = query.sortDescending === 'true';
|
||||
|
||||
@@ -41,16 +41,16 @@ export * from './queries/useReplaysQuery';
|
||||
export * from './queries/useReportQuery';
|
||||
export * from './queries/useReportsQuery';
|
||||
export * from './queries/useResultQuery';
|
||||
export * from './queries/useRevenueSessionsQuery';
|
||||
export * from './queries/useRevenueMetricsQuery';
|
||||
export * from './queries/useRevenueChartQuery';
|
||||
export * from './queries/useRevenueMetricsQuery';
|
||||
export * from './queries/useRevenueSessionsQuery';
|
||||
export * from './queries/useRevenueStatsQuery';
|
||||
export * from './queries/useSavedReplaysQuery';
|
||||
export * from './queries/useSessionActivityQuery';
|
||||
export * from './queries/useSessionDataPropertiesQuery';
|
||||
export * from './queries/useSessionDataPivotQuery';
|
||||
export * from './queries/useSessionDataQuery';
|
||||
export * from './queries/useSessionDataActivityStatsQuery';
|
||||
export * from './queries/useSessionDataPivotQuery';
|
||||
export * from './queries/useSessionDataPropertiesQuery';
|
||||
export * from './queries/useSessionDataQuery';
|
||||
export * from './queries/useSessionDataValuesQuery';
|
||||
export * from './queries/useSessionReplaysQuery';
|
||||
export * from './queries/useShareTokenQuery';
|
||||
|
||||
@@ -3,10 +3,7 @@ import { useApi } from '../useApi';
|
||||
import { useModified } from '../useModified';
|
||||
import { usePagedQuery } from '../usePagedQuery';
|
||||
|
||||
export function useLinkSharesQuery(
|
||||
{ linkId }: { linkId: string },
|
||||
options?: ReactQueryOptions,
|
||||
) {
|
||||
export function useLinkSharesQuery({ linkId }: { linkId: string }, options?: ReactQueryOptions) {
|
||||
const { modified } = useModified('shares');
|
||||
const { get } = useApi();
|
||||
|
||||
|
||||
@@ -3,10 +3,7 @@ import { useApi } from '../useApi';
|
||||
import { useModified } from '../useModified';
|
||||
import { usePagedQuery } from '../usePagedQuery';
|
||||
|
||||
export function usePixelSharesQuery(
|
||||
{ pixelId }: { pixelId: string },
|
||||
options?: ReactQueryOptions,
|
||||
) {
|
||||
export function usePixelSharesQuery({ pixelId }: { pixelId: string }, options?: ReactQueryOptions) {
|
||||
const { modified } = useModified('shares');
|
||||
const { get } = useApi();
|
||||
|
||||
|
||||
@@ -20,7 +20,17 @@ export function usePropertyArraySeriesQuery(
|
||||
return useQuery<EventDataSeriesPoint[]>({
|
||||
queryKey: [
|
||||
`websites:${source}-data:array-series`,
|
||||
{ websiteId, propertyName, eventName, propertyFilters, startAt, endAt, unit, timezone, ...params },
|
||||
{
|
||||
websiteId,
|
||||
propertyName,
|
||||
eventName,
|
||||
propertyFilters,
|
||||
startAt,
|
||||
endAt,
|
||||
unit,
|
||||
timezone,
|
||||
...params,
|
||||
},
|
||||
],
|
||||
queryFn: () =>
|
||||
get(
|
||||
|
||||
@@ -21,7 +21,18 @@ export function usePropertyNumericSeriesQuery(
|
||||
return useQuery<any>({
|
||||
queryKey: [
|
||||
`websites:${source}-data:numeric-series`,
|
||||
{ websiteId, propertyName, metric, eventName, propertyFilters, startAt, endAt, unit, timezone, ...params },
|
||||
{
|
||||
websiteId,
|
||||
propertyName,
|
||||
metric,
|
||||
eventName,
|
||||
propertyFilters,
|
||||
startAt,
|
||||
endAt,
|
||||
unit,
|
||||
timezone,
|
||||
...params,
|
||||
},
|
||||
],
|
||||
queryFn: () =>
|
||||
get(
|
||||
|
||||
@@ -20,7 +20,17 @@ export function usePropertySeriesQuery(
|
||||
return useQuery<EventDataSeriesPoint[]>({
|
||||
queryKey: [
|
||||
`websites:${source}-data:property-series`,
|
||||
{ websiteId, propertyName, eventName, propertyFilters, startAt, endAt, unit, timezone, ...params },
|
||||
{
|
||||
websiteId,
|
||||
propertyName,
|
||||
eventName,
|
||||
propertyFilters,
|
||||
startAt,
|
||||
endAt,
|
||||
unit,
|
||||
timezone,
|
||||
...params,
|
||||
},
|
||||
],
|
||||
queryFn: () =>
|
||||
get(
|
||||
|
||||
@@ -21,7 +21,18 @@ export function usePropertyValuesQuery(
|
||||
return useQuery<any>({
|
||||
queryKey: [
|
||||
`websites:${source}-data:values`,
|
||||
{ websiteId, propertyName, dataType, eventName, propertyFilters, startAt, endAt, unit, timezone, ...params },
|
||||
{
|
||||
websiteId,
|
||||
propertyName,
|
||||
dataType,
|
||||
eventName,
|
||||
propertyFilters,
|
||||
startAt,
|
||||
endAt,
|
||||
unit,
|
||||
timezone,
|
||||
...params,
|
||||
},
|
||||
],
|
||||
queryFn: () =>
|
||||
get(
|
||||
|
||||
@@ -35,7 +35,10 @@ export function useRevenueStatsQuery(
|
||||
const filters = useFilterParameters({ includePagination: false });
|
||||
|
||||
return useQuery<RevenueStatsData>({
|
||||
queryKey: ['websites:revenue:stats', { websiteId, currency, compare, startAt, endAt, ...filters }],
|
||||
queryKey: [
|
||||
'websites:revenue:stats',
|
||||
{ websiteId, currency, compare, startAt, endAt, ...filters },
|
||||
],
|
||||
queryFn: () =>
|
||||
get(`/websites/${websiteId}/revenue/stats`, {
|
||||
currency,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { ReactQueryOptions } from '@/lib/types';
|
||||
import { serializePropertyFilters } from '@/lib/params';
|
||||
import type { PropertyFilter } from '@/lib/types';
|
||||
import type { PropertyFilter, ReactQueryOptions } from '@/lib/types';
|
||||
import { useApi } from '../useApi';
|
||||
import { useDateParameters } from '../useDateParameters';
|
||||
import { useFilterParameters } from '../useFilterParameters';
|
||||
|
||||
@@ -3,7 +3,11 @@ import { FILTER_COLUMNS } from '@/lib/constants';
|
||||
import { useShare } from './context/useShare';
|
||||
import { useNavigation } from './useNavigation';
|
||||
|
||||
export function useFilterParameters({ includePagination = true }: { includePagination?: boolean } = {}) {
|
||||
export function useFilterParameters({
|
||||
includePagination = true,
|
||||
}: {
|
||||
includePagination?: boolean;
|
||||
} = {}) {
|
||||
const { query } = useNavigation();
|
||||
const share = useShare();
|
||||
const allowFilter = share?.parameters?.allowFilter !== false;
|
||||
|
||||
@@ -27,7 +27,7 @@ export function useSubscription(teamId?: string | null) {
|
||||
|
||||
const ownSubscription: Subscription = user?.subscription || defaultSubscription;
|
||||
const teamSubscription: Subscription | null = teamId
|
||||
? user?.teams?.find((t: any) => t.id === teamId)?.subscription ?? null
|
||||
? (user?.teams?.find((t: any) => t.id === teamId)?.subscription ?? null)
|
||||
: null;
|
||||
|
||||
const subscription: Subscription = teamSubscription || ownSubscription;
|
||||
|
||||
@@ -68,7 +68,12 @@ export function DialogButton({
|
||||
|
||||
if (isOpen !== undefined) {
|
||||
return (
|
||||
<Modal isOpen={isOpen} onOpenChange={onOpenChange} isDismissable placement={isMobile ? 'fullscreen' : 'center'}>
|
||||
<Modal
|
||||
isOpen={isOpen}
|
||||
onOpenChange={onOpenChange}
|
||||
isDismissable
|
||||
placement={isMobile ? 'fullscreen' : 'center'}
|
||||
>
|
||||
{dialog}
|
||||
</Modal>
|
||||
);
|
||||
@@ -79,9 +84,7 @@ export function DialogButton({
|
||||
<Button {...props}>
|
||||
<IconLabel icon={icon} label={label} />
|
||||
</Button>
|
||||
<Modal placement={isMobile ? 'fullscreen' : 'center'}>
|
||||
{dialog}
|
||||
</Modal>
|
||||
<Modal placement={isMobile ? 'fullscreen' : 'center'}>{dialog}</Modal>
|
||||
</DialogTrigger>
|
||||
);
|
||||
}
|
||||
@@ -163,7 +163,11 @@ const FilterItem = ({ name, label, operator, value, onRemove }) => {
|
||||
theme="dark"
|
||||
>
|
||||
<Row alignItems="center" gap="4">
|
||||
<Row alignItems="center" gap="2" style={{ maxWidth: 'min(500px, calc(100vw - 10rem))', minWidth: 0, overflow: 'hidden' }}>
|
||||
<Row
|
||||
alignItems="center"
|
||||
gap="2"
|
||||
style={{ maxWidth: 'min(500px, calc(100vw - 10rem))', minWidth: 0, overflow: 'hidden' }}
|
||||
>
|
||||
<Text color="primary" weight="bold">
|
||||
{label}
|
||||
</Text>
|
||||
|
||||
@@ -115,7 +115,12 @@ export function FilterEditForm({ websiteId, onChange, onClose }: FilterEditFormP
|
||||
</TabPanel>
|
||||
</Tabs>
|
||||
</Column>
|
||||
<Row alignItems="center" justifyContent="space-between" gap style={isMobile ? { paddingBottom: '16px' } : undefined}>
|
||||
<Row
|
||||
alignItems="center"
|
||||
justifyContent="space-between"
|
||||
gap
|
||||
style={isMobile ? { paddingBottom: '16px' } : undefined}
|
||||
>
|
||||
<Button onPress={handleReset}>{t(labels.reset)}</Button>
|
||||
<Row alignItems="center" justifyContent="flex-end" gridColumn="span 2" gap>
|
||||
<Button onPress={onClose}>{t(labels.cancel)}</Button>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Empty } from '@/components/common/Empty';
|
||||
import { useMessages, useWebsiteValuesQuery } from '@/components/hooks';
|
||||
import { ComboBox, type ComboBoxProps, ListItem, Loading, useDebounce } from '@umami/react-zen';
|
||||
import { endOfDay, subMonths } from 'date-fns';
|
||||
import { type SetStateAction, useMemo, useState } from 'react';
|
||||
import { Empty } from '@/components/common/Empty';
|
||||
import { useMessages, useWebsiteValuesQuery } from '@/components/hooks';
|
||||
|
||||
export interface LookupFieldProps extends Omit<ComboBoxProps, 'onChange'> {
|
||||
websiteId: string;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { Button, Icon, Row } from '@umami/react-zen';
|
||||
import type { ReactNode } from 'react';
|
||||
import { Monitor, Moon, Sun } from '@/components/icons';
|
||||
|
||||
export type ThemeMode = 'light' | 'dark' | 'system';
|
||||
|
||||
@@ -42,4 +42,4 @@ export function ActiveUsers({
|
||||
}
|
||||
|
||||
return <Link href={`/websites/${websiteId}/realtime`}>{content}</Link>;
|
||||
}
|
||||
}
|
||||
@@ -9,4 +9,3 @@
|
||||
.card.selected {
|
||||
box-shadow: 0 0 0 1px var(--text-primary);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -100,21 +100,21 @@ export function SimpleShareEditForm({
|
||||
<TextField autoComplete="off" autoFocus />
|
||||
</FormField>
|
||||
<Row gap="6">
|
||||
<FormField label={t(labels.filters)} name="allowFilter">
|
||||
<Switch
|
||||
isSelected={watch('allowFilter')}
|
||||
onChange={value => setValue('allowFilter', value, { shouldDirty: true })}
|
||||
>
|
||||
{t(labels.filtersEnabled)}
|
||||
</Switch>
|
||||
</FormField>
|
||||
<FormField label={t(labels.theme)} name="theme">
|
||||
<ThemeModeSelector
|
||||
value={watch('theme')}
|
||||
includeSystem
|
||||
onChange={value => setValue('theme', value, { shouldDirty: true })}
|
||||
/>
|
||||
</FormField>
|
||||
<FormField label={t(labels.filters)} name="allowFilter">
|
||||
<Switch
|
||||
isSelected={watch('allowFilter')}
|
||||
onChange={value => setValue('allowFilter', value, { shouldDirty: true })}
|
||||
>
|
||||
{t(labels.filtersEnabled)}
|
||||
</Switch>
|
||||
</FormField>
|
||||
<FormField label={t(labels.theme)} name="theme">
|
||||
<ThemeModeSelector
|
||||
value={watch('theme')}
|
||||
includeSystem
|
||||
onChange={value => setValue('theme', value, { shouldDirty: true })}
|
||||
/>
|
||||
</FormField>
|
||||
</Row>
|
||||
<Row justifyContent="flex-end" paddingTop="3" gap="3">
|
||||
{onClose && (
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { DataColumn, DataTable, type DataTableProps, Row } from '@umami/react-zen';
|
||||
import { ShareDeleteButton } from '@/app/(main)/websites/[websiteId]/settings/ShareDeleteButton';
|
||||
import { CopyButton } from '@/components/common/CopyButton';
|
||||
import { ExternalLink } from '@/components/common/ExternalLink';
|
||||
import { useConfig, useMessages, useMobile } from '@/components/hooks';
|
||||
import { DataColumn, DataTable, type DataTableProps, Row } from '@umami/react-zen';
|
||||
import { SimpleShareEditButton } from './SimpleShareEditButton';
|
||||
|
||||
export function SimpleSharesTable(props: DataTableProps) {
|
||||
|
||||
Reference in new issue
Block a user