Merge branch 'dev' of https://github.com/umami-software/umami into dev
This commit is contained in:
commit
6c2155d496
157 files changed
+1389
-643
No files matched your search
@@ -41,7 +41,7 @@ export function DataGrid({
|
||||
const { data, error, isLoading, isFetching } = query;
|
||||
const { router, updateParams, query: queryParams } = useNavigation();
|
||||
const [search, setSearch] = useState(queryParams?.search || data?.search || '');
|
||||
const showPager = allowPaging && data && data.count > data.pageSize;
|
||||
const showPager = allowPaging && data && data.count > 0;
|
||||
const { isMobile } = useMobile();
|
||||
const displayMode = isMobile ? 'cards' : undefined;
|
||||
|
||||
@@ -62,46 +62,47 @@ export function DataGrid({
|
||||
const child = data ? (typeof children === 'function' ? children(data) : children) : null;
|
||||
|
||||
return (
|
||||
<Column gap="4" minHeight="300px">
|
||||
{allowSearch && (
|
||||
<Row alignItems="center" justifyContent="space-between" wrap="wrap" gap>
|
||||
<SearchField
|
||||
value={search}
|
||||
onSearch={handleSearch}
|
||||
delay={searchDelay || DEFAULT_SEARCH_DELAY}
|
||||
autoFocus={autoFocus}
|
||||
placeholder={t(labels.search)}
|
||||
/>
|
||||
{renderActions?.()}
|
||||
</Row>
|
||||
)}
|
||||
<LoadingPanel
|
||||
data={data?.data}
|
||||
isLoading={isLoading}
|
||||
isFetching={isFetching}
|
||||
error={error}
|
||||
renderEmpty={renderEmpty}
|
||||
>
|
||||
{data && (
|
||||
<>
|
||||
<Column gap="4" minHeight="300px" justifyContent="space-between">
|
||||
<Column gap="4">
|
||||
{allowSearch && (
|
||||
<Row alignItems="center" justifyContent="space-between" wrap="wrap" gap>
|
||||
<SearchField
|
||||
value={search}
|
||||
onSearch={handleSearch}
|
||||
delay={searchDelay || DEFAULT_SEARCH_DELAY}
|
||||
autoFocus={autoFocus}
|
||||
placeholder={t(labels.search)}
|
||||
/>
|
||||
{renderActions?.()}
|
||||
</Row>
|
||||
)}
|
||||
<LoadingPanel
|
||||
data={data?.data}
|
||||
isLoading={isLoading}
|
||||
isFetching={isFetching}
|
||||
error={error}
|
||||
renderEmpty={renderEmpty}
|
||||
>
|
||||
{data && (
|
||||
<Column>
|
||||
{isValidElement(child)
|
||||
? cloneElement(child as ReactElement<any>, { displayMode })
|
||||
: child}
|
||||
</Column>
|
||||
{showPager && (
|
||||
<Row marginTop="6">
|
||||
<Pager
|
||||
page={data.page}
|
||||
pageSize={data.pageSize}
|
||||
count={data.count}
|
||||
onPageChange={handlePageChange}
|
||||
/>
|
||||
</Row>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</LoadingPanel>
|
||||
)}
|
||||
</LoadingPanel>
|
||||
</Column>
|
||||
{showPager && (
|
||||
<Row marginTop="4">
|
||||
<Pager
|
||||
page={data.page}
|
||||
pageSize={data.pageSize}
|
||||
count={data.count}
|
||||
isCapped={data.isCapped}
|
||||
onPageChange={handlePageChange}
|
||||
/>
|
||||
</Row>
|
||||
)}
|
||||
</Column>
|
||||
);
|
||||
}
|
||||
@@ -6,15 +6,23 @@ export interface PagerProps {
|
||||
page: string | number;
|
||||
pageSize: string | number;
|
||||
count: string | number;
|
||||
isCapped?: boolean;
|
||||
onPageChange: (nextPage: number) => void;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function Pager({ page, pageSize, count, 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;
|
||||
const firstPage = page === 1;
|
||||
const showNavigation = maxPage > 1 || isCapped;
|
||||
|
||||
if (count === 0 || !maxPage) {
|
||||
return null;
|
||||
@@ -28,32 +36,40 @@ export function Pager({ page, pageSize, count, onPageChange }: PagerProps) {
|
||||
}
|
||||
};
|
||||
|
||||
if (maxPage === 1) {
|
||||
return null;
|
||||
}
|
||||
const displayCount = isCapped ? `10,000+` : (+count).toLocaleString();
|
||||
|
||||
return (
|
||||
<Row alignItems="center" justifyContent="space-between" gap="3" flexGrow={1}>
|
||||
<Text>{t(labels.numberOfRecords, { x: count.toLocaleString() })}</Text>
|
||||
<Row alignItems="center" justifyContent="flex-end" gap="3">
|
||||
<Text>
|
||||
{t(labels.pageOf, {
|
||||
current: page.toLocaleString(),
|
||||
total: maxPage.toLocaleString(),
|
||||
})}
|
||||
</Text>
|
||||
<Row gap="1">
|
||||
<Button variant="outline" onPress={() => handlePageChange(-1)} isDisabled={firstPage}>
|
||||
<Icon size="sm" rotate={180}>
|
||||
<ChevronRight />
|
||||
</Icon>
|
||||
</Button>
|
||||
<Button variant="outline" onPress={() => handlePageChange(1)} isDisabled={lastPage}>
|
||||
<Icon size="sm">
|
||||
<ChevronRight />
|
||||
</Icon>
|
||||
</Button>
|
||||
</Row>
|
||||
<Row alignItems="center" justifyContent="space-between" gap="3" flexGrow={1} wrap="wrap">
|
||||
<Text color="muted">{t(labels.numberOfRecords, { x: displayCount })}</Text>
|
||||
<Row
|
||||
alignItems="center"
|
||||
justifyContent="flex-end"
|
||||
gap="3"
|
||||
wrap="nowrap"
|
||||
style={{ whiteSpace: 'nowrap' }}
|
||||
>
|
||||
{showNavigation && (
|
||||
<>
|
||||
<Text color="muted">
|
||||
{t(labels.pageOf, {
|
||||
current: page.toLocaleString(),
|
||||
total: maxPage.toLocaleString(),
|
||||
})}
|
||||
</Text>
|
||||
<Row gap="1">
|
||||
<Button variant="outline" onPress={() => handlePageChange(-1)} isDisabled={firstPage}>
|
||||
<Icon size="sm" rotate={180}>
|
||||
<ChevronRight />
|
||||
</Icon>
|
||||
</Button>
|
||||
<Button variant="outline" onPress={() => handlePageChange(1)} isDisabled={lastPage}>
|
||||
<Icon size="sm">
|
||||
<ChevronRight />
|
||||
</Icon>
|
||||
</Button>
|
||||
</Row>
|
||||
</>
|
||||
)}
|
||||
</Row>
|
||||
</Row>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
'use client';
|
||||
|
||||
import type { ReactNode } from 'react';
|
||||
import { Icon } from '@umami/react-zen';
|
||||
import { ChevronDown, ChevronUp } from '@/components/icons';
|
||||
import { useNavigation } from '@/components/hooks';
|
||||
|
||||
type SortDirection = 'asc' | 'desc';
|
||||
|
||||
export interface SortableLabelProps {
|
||||
label: ReactNode;
|
||||
sortKey: string;
|
||||
defaultDirection?: SortDirection;
|
||||
}
|
||||
|
||||
export function SortableLabel({
|
||||
label,
|
||||
sortKey,
|
||||
defaultDirection = 'asc',
|
||||
}: SortableLabelProps) {
|
||||
const { router, query, updateParams } = useNavigation();
|
||||
const isActive = query.orderBy === sortKey;
|
||||
const isDescending = query.sortDescending === 'true';
|
||||
const direction = isActive ? (isDescending ? 'desc' : 'asc') : undefined;
|
||||
const activeColor = 'var(--text-primary)';
|
||||
|
||||
const getNextDirection = (): SortDirection => {
|
||||
if (!isActive) {
|
||||
return defaultDirection;
|
||||
}
|
||||
|
||||
return direction === 'desc' ? 'asc' : 'desc';
|
||||
};
|
||||
|
||||
const handleSort = () => {
|
||||
const nextDirection = getNextDirection();
|
||||
|
||||
router.push(
|
||||
updateParams({
|
||||
orderBy: sortKey,
|
||||
sortDescending: nextDirection === 'desc' ? 'true' : undefined,
|
||||
page: 1,
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleSort}
|
||||
className="inline-flex appearance-none items-center gap-1 border-0 bg-transparent p-0 text-inherit"
|
||||
aria-pressed={isActive}
|
||||
>
|
||||
<span>{label}</span>
|
||||
<span
|
||||
aria-hidden
|
||||
style={{
|
||||
display: 'inline-flex',
|
||||
flexDirection: 'column',
|
||||
gap: 0,
|
||||
lineHeight: 0,
|
||||
color: 'var(--text-muted)',
|
||||
opacity: 0.8,
|
||||
}}
|
||||
>
|
||||
<span
|
||||
style={{
|
||||
color: direction === 'asc' ? activeColor : undefined,
|
||||
opacity: direction === 'asc' ? 1 : 0.55,
|
||||
transform: 'scale(0.9)',
|
||||
transformOrigin: 'center',
|
||||
}}
|
||||
>
|
||||
<Icon size="sm" color={direction === 'asc' ? undefined : 'muted'}>
|
||||
<ChevronUp />
|
||||
</Icon>
|
||||
</span>
|
||||
<span
|
||||
style={{
|
||||
color: direction === 'desc' ? activeColor : undefined,
|
||||
opacity: direction === 'desc' ? 1 : 0.55,
|
||||
marginTop: '-6px',
|
||||
transform: 'scale(0.9)',
|
||||
transformOrigin: 'center',
|
||||
}}
|
||||
>
|
||||
<Icon size="sm" color={direction === 'desc' ? undefined : 'muted'}>
|
||||
<ChevronDown />
|
||||
</Icon>
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { MAX_PAGING_RESULTS } from '@/lib/constants';
|
||||
import { serializeEventPropertyFilters } from '@/lib/params';
|
||||
import type { EventPropertyFilter, ReactQueryOptions } from '@/lib/types';
|
||||
import { useApi } from '../useApi';
|
||||
@@ -28,6 +29,7 @@ export function useEventDataPivotQuery(
|
||||
timezone,
|
||||
...serializeEventPropertyFilters(eventFilters),
|
||||
...params,
|
||||
maxResults: MAX_PAGING_RESULTS,
|
||||
}),
|
||||
enabled: !!(websiteId && eventName),
|
||||
...options,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { MAX_PAGING_RESULTS } from '@/lib/constants';
|
||||
import { useApi } from '../useApi';
|
||||
import { useDateParameters } from '../useDateParameters';
|
||||
import { useFilterParameters } from '../useFilterParameters';
|
||||
@@ -24,7 +25,7 @@ export function useReplaysQuery(websiteId: string, params?: Record<string, strin
|
||||
...filters,
|
||||
...pageParams,
|
||||
...params,
|
||||
pageSize: 20,
|
||||
maxResults: MAX_PAGING_RESULTS,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { MAX_PAGING_RESULTS } from '@/lib/constants';
|
||||
import { useApi } from '../useApi';
|
||||
import { useDateParameters } from '../useDateParameters';
|
||||
import { useFilterParameters } from '../useFilterParameters';
|
||||
@@ -29,7 +30,7 @@ export function useRevenueSessionsQuery(
|
||||
...filters,
|
||||
...pageParams,
|
||||
...params,
|
||||
pageSize: 20,
|
||||
maxResults: MAX_PAGING_RESULTS,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -11,7 +11,6 @@ export function useSavedReplaysQuery(websiteId: string) {
|
||||
queryFn: pageParams => {
|
||||
return get(`/websites/${websiteId}/replays/saved`, {
|
||||
...pageParams,
|
||||
pageSize: 20,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { MAX_PAGING_RESULTS } from '@/lib/constants';
|
||||
import { serializePropertyFilters } from '@/lib/params';
|
||||
import type { PropertyFilter, ReactQueryOptions } from '@/lib/types';
|
||||
import { useApi } from '../useApi';
|
||||
@@ -28,6 +29,7 @@ export function useSessionDataPivotQuery(
|
||||
propertyName,
|
||||
...serializePropertyFilters(propertyFilters),
|
||||
...params,
|
||||
maxResults: MAX_PAGING_RESULTS,
|
||||
}),
|
||||
enabled: !!(websiteId && propertyName),
|
||||
...options,
|
||||
|
||||
@@ -8,7 +8,7 @@ import { useFilterParameters } from '../useFilterParameters';
|
||||
export function useSessionDataPropertiesQuery(
|
||||
websiteId: string,
|
||||
params?: {
|
||||
selectedPropertyName?: string;
|
||||
propertyName?: string;
|
||||
propertyFilters?: PropertyFilter[];
|
||||
},
|
||||
options?: ReactQueryOptions,
|
||||
@@ -16,14 +16,14 @@ export function useSessionDataPropertiesQuery(
|
||||
const { get, useQuery } = useApi();
|
||||
const { startAt, endAt, unit, timezone } = useDateParameters();
|
||||
const filters = useFilterParameters({ includePagination: false });
|
||||
const { selectedPropertyName, propertyFilters = [] } = params || {};
|
||||
const { propertyName, propertyFilters = [] } = params || {};
|
||||
|
||||
return useQuery<any>({
|
||||
queryKey: [
|
||||
'websites:session-data:properties',
|
||||
{
|
||||
websiteId,
|
||||
selectedPropertyName,
|
||||
propertyName,
|
||||
propertyFilters,
|
||||
startAt,
|
||||
endAt,
|
||||
@@ -38,7 +38,7 @@ export function useSessionDataPropertiesQuery(
|
||||
endAt,
|
||||
unit,
|
||||
timezone,
|
||||
selectedPropertyName,
|
||||
propertyName,
|
||||
...serializePropertyFilters(propertyFilters),
|
||||
...filters,
|
||||
}),
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import { useApi } from '../useApi';
|
||||
import { useModified } from '../useModified';
|
||||
import { usePagedQuery } from '../usePagedQuery';
|
||||
|
||||
export function useUserTeamsQuery(userId: string) {
|
||||
const { get, useQuery } = useApi();
|
||||
const { get } = useApi();
|
||||
const { modified } = useModified(`teams`);
|
||||
|
||||
return useQuery({
|
||||
return usePagedQuery({
|
||||
queryKey: ['teams', { userId, modified }],
|
||||
queryFn: () => {
|
||||
return get(`/users/${userId}/teams`);
|
||||
queryFn: params => {
|
||||
return get(`/users/${userId}/teams`, params);
|
||||
},
|
||||
enabled: !!userId,
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { MAX_PAGING_RESULTS } from '@/lib/constants';
|
||||
import type { ReactQueryOptions } from '@/lib/types';
|
||||
import { useApi } from '../useApi';
|
||||
import { useDateParameters } from '../useDateParameters';
|
||||
@@ -32,6 +33,7 @@ export function useWebsiteEventsQuery(
|
||||
...filters,
|
||||
...pageParams,
|
||||
eventType: EVENT_TYPES[params.view],
|
||||
maxResults: MAX_PAGING_RESULTS,
|
||||
}),
|
||||
enabled: !!websiteId,
|
||||
...options,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { MAX_PAGING_RESULTS } from '@/lib/constants';
|
||||
import { useApi } from '../useApi';
|
||||
import { useDateParameters } from '../useDateParameters';
|
||||
import { useFilterParameters } from '../useFilterParameters';
|
||||
@@ -27,7 +28,7 @@ export function useWebsiteSessionsQuery(
|
||||
...filters,
|
||||
...pageParams,
|
||||
...params,
|
||||
pageSize: 20,
|
||||
maxResults: MAX_PAGING_RESULTS,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,27 +1,32 @@
|
||||
import { useMemo } from 'react';
|
||||
import { FILTER_COLUMNS } from '@/lib/constants';
|
||||
import { useShare } from './context/useShare';
|
||||
import { useNavigation } from './useNavigation';
|
||||
|
||||
export function useFilterParameters({ includePagination = true }: { includePagination?: boolean } = {}) {
|
||||
const { query } = useNavigation();
|
||||
const share = useShare();
|
||||
const allowFilter = share?.parameters?.allowFilter !== false;
|
||||
|
||||
return useMemo(() => {
|
||||
const filterParams: Record<string, any> = {};
|
||||
|
||||
for (const key of Object.keys(query)) {
|
||||
const baseName = key.replace(/\d+$/, '');
|
||||
if (FILTER_COLUMNS[baseName]) {
|
||||
filterParams[key] = query[key];
|
||||
if (allowFilter) {
|
||||
for (const key of Object.keys(query)) {
|
||||
const baseName = key.replace(/\d+$/, '');
|
||||
if (FILTER_COLUMNS[baseName]) {
|
||||
filterParams[key] = query[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const params = {
|
||||
...filterParams,
|
||||
search: query.search,
|
||||
segment: query.segment,
|
||||
cohort: query.cohort,
|
||||
excludeBounce: query.excludeBounce,
|
||||
match: query.match,
|
||||
segment: allowFilter ? query.segment : undefined,
|
||||
cohort: allowFilter ? query.cohort : undefined,
|
||||
excludeBounce: allowFilter ? query.excludeBounce : undefined,
|
||||
match: allowFilter ? query.match : undefined,
|
||||
} as Record<string, any>;
|
||||
|
||||
if (includePagination) {
|
||||
@@ -30,5 +35,5 @@ export function useFilterParameters({ includePagination = true }: { includePagin
|
||||
}
|
||||
|
||||
return params;
|
||||
}, [query, includePagination]);
|
||||
}, [allowFilter, includePagination, query]);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { FILTER_COLUMNS, OPERATORS } from '@/lib/constants';
|
||||
import { safeDecodeURIComponent } from '@/lib/url';
|
||||
import { useShare } from './context/useShare';
|
||||
import { useFields } from './useFields';
|
||||
import { useMessages } from './useMessages';
|
||||
import { useNavigation } from './useNavigation';
|
||||
@@ -10,6 +11,8 @@ export function useFilters() {
|
||||
const { query } = useNavigation();
|
||||
const { fields } = useFields();
|
||||
const operatorLabels = useOperatorLabels();
|
||||
const share = useShare();
|
||||
const allowFilter = share?.parameters?.allowFilter !== false;
|
||||
|
||||
const operators = [
|
||||
{ name: 'eq', type: 'string', label: t(labels.is) },
|
||||
@@ -56,30 +59,32 @@ export function useFilters() {
|
||||
uuid: [OPERATORS.equals],
|
||||
};
|
||||
|
||||
const filters = Object.keys(query).reduce((arr, key) => {
|
||||
const baseName = key.replace(/\d+$/, '');
|
||||
if (FILTER_COLUMNS[baseName]) {
|
||||
let operator = 'eq';
|
||||
let value = safeDecodeURIComponent(query[key]);
|
||||
const label = fields.find(({ name }) => name === baseName)?.label;
|
||||
const filters = allowFilter
|
||||
? Object.keys(query).reduce((arr, key) => {
|
||||
const baseName = key.replace(/\d+$/, '');
|
||||
if (FILTER_COLUMNS[baseName]) {
|
||||
let operator = 'eq';
|
||||
let value = safeDecodeURIComponent(query[key]);
|
||||
const label = fields.find(({ name }) => name === baseName)?.label;
|
||||
|
||||
const match = value.match(/^([a-z]+)\.(.*)/);
|
||||
const match = value.match(/^([a-z]+)\.(.*)/);
|
||||
|
||||
if (match) {
|
||||
operator = match[1];
|
||||
value = match[2];
|
||||
}
|
||||
if (match) {
|
||||
operator = match[1];
|
||||
value = match[2];
|
||||
}
|
||||
|
||||
return arr.concat({
|
||||
name: key,
|
||||
type: baseName,
|
||||
operator,
|
||||
value,
|
||||
label,
|
||||
});
|
||||
}
|
||||
return arr;
|
||||
}, []);
|
||||
return arr.concat({
|
||||
name: key,
|
||||
type: baseName,
|
||||
operator,
|
||||
value,
|
||||
label,
|
||||
});
|
||||
}
|
||||
return arr;
|
||||
}, [])
|
||||
: [];
|
||||
|
||||
const getFilters = (type: string) => {
|
||||
return (
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useNavigation } from './useNavigation';
|
||||
|
||||
export function usePageParameters() {
|
||||
const {
|
||||
query: { page, pageSize, search },
|
||||
query: { page, pageSize, search, orderBy, sortDescending },
|
||||
} = useNavigation();
|
||||
|
||||
return useMemo(() => {
|
||||
@@ -11,6 +11,8 @@ export function usePageParameters() {
|
||||
page,
|
||||
pageSize,
|
||||
search,
|
||||
orderBy,
|
||||
sortDescending,
|
||||
};
|
||||
}, [page, pageSize, search]);
|
||||
}, [orderBy, page, pageSize, search, sortDescending]);
|
||||
}
|
||||
@@ -15,13 +15,13 @@ export function usePagedQuery<TData = any, TError = Error>({
|
||||
queryFn: (params?: object) => Promise<PageResult<TData>> | PageResult<TData>;
|
||||
}): UseQueryResult<PageResult<TData>, TError> {
|
||||
const {
|
||||
query: { page, search },
|
||||
query: { page, search, orderBy, sortDescending },
|
||||
} = useNavigation();
|
||||
const { useQuery } = useApi();
|
||||
|
||||
return useQuery<PageResult<TData>, TError>({
|
||||
queryKey: [...queryKey, page, search] as const,
|
||||
queryFn: () => queryFn({ page, search }),
|
||||
queryKey: [...queryKey, page, search, orderBy, sortDescending] as const,
|
||||
queryFn: () => queryFn({ page, search, orderBy, sortDescending }),
|
||||
...options,
|
||||
});
|
||||
}
|
||||
@@ -42,7 +42,7 @@ export function DialogButton({
|
||||
height,
|
||||
minWidth,
|
||||
minHeight,
|
||||
maxHeight: 'calc(100dvh - 40px)',
|
||||
maxHeight: 'min(80dvh, calc(100dvh - 40px))',
|
||||
overflowY: 'auto',
|
||||
padding: '32px',
|
||||
};
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { Button, Icon, Row } from '@umami/react-zen';
|
||||
import { Monitor, Moon, Sun } from '@/components/icons';
|
||||
|
||||
export type ThemeMode = 'light' | 'dark' | 'system';
|
||||
|
||||
export function ThemeModeSelector({
|
||||
value,
|
||||
onChange,
|
||||
includeSystem = false,
|
||||
}: {
|
||||
value?: ThemeMode;
|
||||
onChange: (value: ThemeMode) => void;
|
||||
includeSystem?: boolean;
|
||||
}) {
|
||||
const options: { id: ThemeMode; icon: ReactNode; label: string }[] = [
|
||||
{ id: 'light', icon: <Sun />, label: 'Light' },
|
||||
...(includeSystem ? [{ id: 'system' as const, icon: <Monitor />, label: 'System' }] : []),
|
||||
{ id: 'dark', icon: <Moon />, label: 'Dark' },
|
||||
];
|
||||
|
||||
return (
|
||||
<Row gap>
|
||||
{options.map(({ id, icon, label }) => (
|
||||
<Button
|
||||
key={id}
|
||||
variant={value === id ? 'primary' : undefined}
|
||||
onPress={() => onChange(id)}
|
||||
aria-label={label}
|
||||
>
|
||||
<Icon>{icon}</Icon>
|
||||
</Button>
|
||||
))}
|
||||
</Row>
|
||||
);
|
||||
}
|
||||
@@ -190,6 +190,7 @@ export const labels: Record<string, string> = {
|
||||
type: 'label.type',
|
||||
filter: 'label.filter',
|
||||
filters: 'label.filters',
|
||||
filtersEnabled: 'label.filters-enabled',
|
||||
propertyFilter: 'label.property-filter',
|
||||
activityByProperty: 'label.activity-by-property',
|
||||
breakdown: 'label.breakdown',
|
||||
|
||||
@@ -48,15 +48,6 @@ export function PropertyNumericChart({
|
||||
const avgRows = useMemo(() => (avgQuery.data as { t: string; y: number }[] | undefined) ?? [], [avgQuery.data]);
|
||||
const stats = statsQuery.data;
|
||||
|
||||
const formatMetricValue = useCallback(
|
||||
(n: number) =>
|
||||
Number(n).toLocaleString(locale, {
|
||||
maximumFractionDigits: 2,
|
||||
minimumFractionDigits: Number.isInteger(Number(n)) ? 0 : 2,
|
||||
}),
|
||||
[locale],
|
||||
);
|
||||
|
||||
const chartData: any = useMemo(() => {
|
||||
if (!sumQuery.data && !avgQuery.data) return;
|
||||
|
||||
@@ -109,10 +100,10 @@ export function PropertyNumericChart({
|
||||
>
|
||||
<MetricsBar padding="2">
|
||||
<MetricCard label={t(labels.total)} value={stats?.total ?? 0} formatValue={formatLongNumber} />
|
||||
<MetricCard label={t(labels.average)} value={stats?.average ?? 0} formatValue={formatMetricValue} />
|
||||
<MetricCard label="Median" value={stats?.median ?? 0} formatValue={formatMetricValue} />
|
||||
<MetricCard label={t(labels.max)} value={stats?.max ?? 0} formatValue={formatMetricValue} />
|
||||
<MetricCard label={t(labels.min)} value={stats?.min ?? 0} formatValue={formatMetricValue} />
|
||||
<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} />
|
||||
</MetricsBar>
|
||||
</LoadingPanel>
|
||||
<LoadingPanel
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
import { Button, Column, Form, FormField, FormSubmitButton, Row, TextField } from '@umami/react-zen';
|
||||
import {
|
||||
Button,
|
||||
Column,
|
||||
Form,
|
||||
FormField,
|
||||
FormSubmitButton,
|
||||
Row,
|
||||
Switch,
|
||||
TextField,
|
||||
} from '@umami/react-zen';
|
||||
import { useState } from 'react';
|
||||
import { useApi, useMessages, useModified } from '@/components/hooks';
|
||||
import { ThemeModeSelector } from '@/components/input/ThemeModeSelector';
|
||||
|
||||
export function SimpleShareCreateForm({
|
||||
createPath,
|
||||
@@ -15,15 +25,19 @@ export function SimpleShareCreateForm({
|
||||
const { touch } = useModified();
|
||||
const { t, labels, getErrorMessage } = useMessages();
|
||||
const [isPending, setIsPending] = useState(false);
|
||||
const [error, setError] = useState<unknown>(null);
|
||||
const [error, setError] = useState<any>(null);
|
||||
|
||||
const handleSubmit = async (data: { name: string }) => {
|
||||
const handleSubmit = async (data: { name: string; allowFilter?: boolean; theme?: string }) => {
|
||||
setIsPending(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
await post(createPath, {
|
||||
name: data.name,
|
||||
parameters: {
|
||||
allowFilter: data.allowFilter ?? true,
|
||||
theme: data.theme === 'system' ? undefined : data.theme,
|
||||
},
|
||||
});
|
||||
|
||||
touch('shares');
|
||||
@@ -36,22 +50,45 @@ export function SimpleShareCreateForm({
|
||||
};
|
||||
|
||||
return (
|
||||
<Form onSubmit={handleSubmit} error={getErrorMessage(error)} defaultValues={{ name: '' }}>
|
||||
<Column gap="4">
|
||||
<FormField label={t(labels.name)} name="name" rules={{ required: t(labels.required) }}>
|
||||
<TextField autoComplete="off" autoFocus />
|
||||
</FormField>
|
||||
<Row justifyContent="flex-end" gap="3">
|
||||
{onCancel && (
|
||||
<Button isDisabled={isPending} onPress={onCancel}>
|
||||
{t(labels.cancel)}
|
||||
</Button>
|
||||
)}
|
||||
<FormSubmitButton variant="primary" isDisabled={isPending}>
|
||||
{t(labels.add)}
|
||||
</FormSubmitButton>
|
||||
</Row>
|
||||
</Column>
|
||||
<Form
|
||||
onSubmit={handleSubmit}
|
||||
error={getErrorMessage(error)}
|
||||
defaultValues={{ name: '', allowFilter: true, theme: 'system' }}
|
||||
>
|
||||
{({ watch, setValue }) => (
|
||||
<Column gap="4">
|
||||
<FormField label={t(labels.name)} name="name" rules={{ required: t(labels.required) }}>
|
||||
<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>
|
||||
</Row>
|
||||
<Row justifyContent="flex-end" gap="3">
|
||||
{onCancel && (
|
||||
<Button isDisabled={isPending} onPress={onCancel}>
|
||||
{t(labels.cancel)}
|
||||
</Button>
|
||||
)}
|
||||
<FormSubmitButton variant="primary" isDisabled={isPending}>
|
||||
{t(labels.add)}
|
||||
</FormSubmitButton>
|
||||
</Row>
|
||||
</Column>
|
||||
)}
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
@@ -7,10 +7,12 @@ import {
|
||||
Label,
|
||||
Loading,
|
||||
Row,
|
||||
Switch,
|
||||
TextField,
|
||||
} from '@umami/react-zen';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useApi, useConfig, useMessages, useModified } from '@/components/hooks';
|
||||
import { ThemeModeSelector } from '@/components/input/ThemeModeSelector';
|
||||
|
||||
export function SimpleShareEditForm({
|
||||
shareId,
|
||||
@@ -49,7 +51,7 @@ export function SimpleShareEditForm({
|
||||
loadShare();
|
||||
}, [get, modified, shareId]);
|
||||
|
||||
const handleSubmit = async (data: { name: string }) => {
|
||||
const handleSubmit = async (data: { name: string; allowFilter?: boolean; theme?: string }) => {
|
||||
setIsPending(true);
|
||||
setError(null);
|
||||
|
||||
@@ -57,7 +59,11 @@ export function SimpleShareEditForm({
|
||||
await post(`/share/id/${shareId}`, {
|
||||
name: data.name,
|
||||
slug: share.slug,
|
||||
parameters: share.parameters || {},
|
||||
parameters: {
|
||||
...(share.parameters || {}),
|
||||
allowFilter: data.allowFilter ?? true,
|
||||
theme: data.theme === 'system' ? undefined : data.theme,
|
||||
},
|
||||
});
|
||||
|
||||
touch('shares');
|
||||
@@ -78,27 +84,50 @@ export function SimpleShareEditForm({
|
||||
<Form
|
||||
onSubmit={handleSubmit}
|
||||
error={getErrorMessage(error)}
|
||||
defaultValues={{ name: share?.name || '' }}
|
||||
defaultValues={{
|
||||
name: share?.name || '',
|
||||
allowFilter: share?.parameters?.allowFilter ?? true,
|
||||
theme: share?.parameters?.theme || 'system',
|
||||
}}
|
||||
>
|
||||
<Column gap="6">
|
||||
<Column>
|
||||
<Label>{t(labels.shareUrl)}</Label>
|
||||
<TextField value={getUrl(share?.slug || '')} isReadOnly allowCopy />
|
||||
{({ watch, setValue }) => (
|
||||
<Column gap="6">
|
||||
<Column>
|
||||
<Label>{t(labels.shareUrl)}</Label>
|
||||
<TextField value={getUrl(share?.slug || '')} isReadOnly allowCopy />
|
||||
</Column>
|
||||
<FormField label={t(labels.name)} name="name" rules={{ required: t(labels.required) }}>
|
||||
<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>
|
||||
</Row>
|
||||
<Row justifyContent="flex-end" paddingTop="3" gap="3">
|
||||
{onClose && (
|
||||
<Button isDisabled={isPending} onPress={onClose}>
|
||||
{t(labels.cancel)}
|
||||
</Button>
|
||||
)}
|
||||
<FormSubmitButton variant="primary" isDisabled={isPending}>
|
||||
{t(labels.save)}
|
||||
</FormSubmitButton>
|
||||
</Row>
|
||||
</Column>
|
||||
<FormField label={t(labels.name)} name="name" rules={{ required: t(labels.required) }}>
|
||||
<TextField autoComplete="off" autoFocus />
|
||||
</FormField>
|
||||
<Row justifyContent="flex-end" paddingTop="3" gap="3">
|
||||
{onClose && (
|
||||
<Button isDisabled={isPending} onPress={onClose}>
|
||||
{t(labels.cancel)}
|
||||
</Button>
|
||||
)}
|
||||
<FormSubmitButton variant="primary" isDisabled={isPending}>
|
||||
{t(labels.save)}
|
||||
</FormSubmitButton>
|
||||
</Row>
|
||||
</Column>
|
||||
)}
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user