mirror of
https://github.com/umami-software/umami.git
synced 2026-02-05 21:27:20 +01:00
Updated events/sessions pages. Added DateDistance component.
This commit is contained in:
parent
8b64029409
commit
5b300f1ff5
13 changed files with 44 additions and 35 deletions
|
|
@ -21,7 +21,7 @@ const dateFormats = {
|
|||
};
|
||||
|
||||
export interface BarChartProps extends ChartProps {
|
||||
unit: string;
|
||||
unit?: string;
|
||||
stacked?: boolean;
|
||||
currency?: string;
|
||||
renderXLabel?: (label: string, index: number, values: any[]) => string;
|
||||
|
|
|
|||
17
src/components/common/DateDistance.tsx
Normal file
17
src/components/common/DateDistance.tsx
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import { Tooltip, TooltipTrigger, Text, Focusable } from '@umami/react-zen';
|
||||
import { formatDistanceToNow } from 'date-fns';
|
||||
import { useLocale, useTimezone } from '@/components/hooks';
|
||||
|
||||
export function DateDistance({ date }: { date: Date }) {
|
||||
const { formatTimezoneDate } = useTimezone();
|
||||
const { dateLocale } = useLocale();
|
||||
|
||||
return (
|
||||
<TooltipTrigger delay={0}>
|
||||
<Focusable>
|
||||
<Text>{formatDistanceToNow(date, { addSuffix: true, locale: dateLocale })}</Text>
|
||||
</Focusable>
|
||||
<Tooltip>{formatTimezoneDate(date.toISOString(), 'PPPpp')}</Tooltip>
|
||||
</TooltipTrigger>
|
||||
);
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ import { useApi } from '../useApi';
|
|||
import { useFilterParams } from '../useFilterParams';
|
||||
import { ReactQueryOptions } from '@/lib/types';
|
||||
|
||||
export function useResultQuery<T>(
|
||||
export function useResultQuery<T = any>(
|
||||
type: string,
|
||||
params?: { [key: string]: any },
|
||||
options?: ReactQueryOptions<T>,
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
import { useApi } from '../useApi';
|
||||
import { usePagedQuery } from '../usePagedQuery';
|
||||
import { useModified } from '../useModified';
|
||||
|
||||
export function useTeamsQuery(userId: string) {
|
||||
const { get } = useApi();
|
||||
const { get, useQuery } = useApi();
|
||||
const { modified } = useModified(`teams`);
|
||||
|
||||
return usePagedQuery({
|
||||
return useQuery({
|
||||
queryKey: ['teams', { userId, modified }],
|
||||
queryFn: (params: any) => {
|
||||
return get(`/users/${userId}/teams`, params);
|
||||
|
|
|
|||
|
|
@ -5,12 +5,11 @@ import { ReactQueryOptions } from '@/lib/types';
|
|||
|
||||
export function useWebsiteEventsQuery(websiteId: string, options?: ReactQueryOptions<any>) {
|
||||
const { get } = useApi();
|
||||
const params = useFilterParams(websiteId);
|
||||
const filterParams = useFilterParams(websiteId);
|
||||
|
||||
return usePagedQuery({
|
||||
queryKey: ['websites:events', { websiteId, ...params }],
|
||||
queryFn: pageParams =>
|
||||
get(`/websites/${websiteId}/events`, { ...params, ...pageParams, pageSize: 20 }),
|
||||
queryKey: ['websites:events', { websiteId, ...filterParams }],
|
||||
queryFn: () => get(`/websites/${websiteId}/events`, { ...filterParams, pageSize: 20 }),
|
||||
enabled: !!websiteId,
|
||||
...options,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -22,14 +22,19 @@ export function useFilterParams(websiteId: string) {
|
|||
event,
|
||||
tag,
|
||||
hostname,
|
||||
page,
|
||||
pageSize,
|
||||
search,
|
||||
},
|
||||
} = useNavigation();
|
||||
|
||||
return {
|
||||
// Date range
|
||||
startAt: +toUtc(startDate),
|
||||
endAt: +toUtc(endDate),
|
||||
unit,
|
||||
timezone,
|
||||
// Filters
|
||||
path,
|
||||
referrer,
|
||||
title,
|
||||
|
|
@ -44,5 +49,9 @@ export function useFilterParams(websiteId: string) {
|
|||
event,
|
||||
tag,
|
||||
hostname,
|
||||
// Paging
|
||||
page,
|
||||
pageSize,
|
||||
search,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ export function usePagedQuery<T = any>({
|
|||
const { query: queryParams } = useNavigation();
|
||||
const [params, setParams] = useState<PageParams>({
|
||||
search: '',
|
||||
page: +queryParams?.page || 1,
|
||||
page: queryParams?.page || '1',
|
||||
});
|
||||
|
||||
const { useQuery } = useApi();
|
||||
|
|
@ -25,7 +25,7 @@ export function usePagedQuery<T = any>({
|
|||
return {
|
||||
result: data as PageResult<T>,
|
||||
query,
|
||||
filterParams: params,
|
||||
params,
|
||||
setParams,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue