mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 22:27:16 +01:00
Convert local time to timezone.
This commit is contained in:
parent
490e446481
commit
a4d8afe516
6 changed files with 28 additions and 55 deletions
|
|
@ -66,7 +66,7 @@ export function BarChart(props: BarChartProps) {
|
|||
},
|
||||
},
|
||||
};
|
||||
}, [colors]);
|
||||
}, [colors, unit, stacked, renderXLabel, renderYLabel]);
|
||||
|
||||
const handleTooltip = ({ tooltip }: { tooltip: any }) => {
|
||||
const { opacity } = tooltip;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,29 @@
|
|||
import useApi from './useApi';
|
||||
import { UseQueryOptions } from '@tanstack/react-query';
|
||||
import { useDateRange, useNavigation, useTimezone } from 'components/hooks';
|
||||
import { zonedTimeToUtc } from 'date-fns-tz';
|
||||
|
||||
export function useWebsiteEvents(
|
||||
websiteId: string,
|
||||
params?: { [key: string]: any },
|
||||
options?: Omit<UseQueryOptions, 'queryKey' | 'queryFn'>,
|
||||
) {
|
||||
const { get, useQuery } = useApi();
|
||||
const [dateRange] = useDateRange(websiteId);
|
||||
const { startDate, endDate, unit, offset } = dateRange;
|
||||
const { timezone } = useTimezone();
|
||||
const {
|
||||
query: { url, event },
|
||||
} = useNavigation();
|
||||
|
||||
const params = {
|
||||
startAt: +zonedTimeToUtc(startDate, timezone),
|
||||
endAt: +zonedTimeToUtc(endDate, timezone),
|
||||
unit,
|
||||
offset,
|
||||
timezone,
|
||||
url,
|
||||
event,
|
||||
};
|
||||
|
||||
return useQuery({
|
||||
queryKey: ['events', { ...params }],
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { zonedTimeToUtc } from 'date-fns-tz';
|
||||
import { useApi, useDateRange, useNavigation, useTimezone } from 'components/hooks';
|
||||
|
||||
export function useWebsitePageviews(websiteId: string, options?: { [key: string]: string }) {
|
||||
|
|
@ -10,8 +11,8 @@ export function useWebsitePageviews(websiteId: string, options?: { [key: string]
|
|||
} = useNavigation();
|
||||
|
||||
const params = {
|
||||
startAt: +startDate,
|
||||
endAt: +endDate,
|
||||
startAt: +zonedTimeToUtc(startDate, timezone),
|
||||
endAt: +zonedTimeToUtc(endDate, timezone),
|
||||
unit,
|
||||
timezone,
|
||||
url,
|
||||
|
|
|
|||
|
|
@ -3,39 +3,19 @@ import { Loading } from 'react-basics';
|
|||
import { colord } from 'colord';
|
||||
import BarChart from 'components/charts/BarChart';
|
||||
import { getDateArray } from 'lib/date';
|
||||
import {
|
||||
useLocale,
|
||||
useDateRange,
|
||||
useTimezone,
|
||||
useNavigation,
|
||||
useWebsiteEvents,
|
||||
} from 'components/hooks';
|
||||
import { useLocale, useDateRange, useWebsiteEvents } from 'components/hooks';
|
||||
import { CHART_COLORS } from 'lib/constants';
|
||||
import { renderDateLabels } from 'lib/charts';
|
||||
|
||||
export interface EventsChartProps {
|
||||
websiteId: string;
|
||||
className?: string;
|
||||
token?: string;
|
||||
}
|
||||
|
||||
export function EventsChart({ websiteId, className, token }: EventsChartProps) {
|
||||
const [{ startDate, endDate, unit, offset }] = useDateRange(websiteId);
|
||||
export function EventsChart({ websiteId, className }: EventsChartProps) {
|
||||
const [{ startDate, endDate, unit }] = useDateRange(websiteId);
|
||||
const { locale } = useLocale();
|
||||
const { timezone } = useTimezone();
|
||||
const {
|
||||
query: { url, event },
|
||||
} = useNavigation();
|
||||
const { data, isLoading } = useWebsiteEvents(websiteId, {
|
||||
startAt: +startDate,
|
||||
endAt: +endDate,
|
||||
unit,
|
||||
timezone,
|
||||
url,
|
||||
event,
|
||||
token,
|
||||
offset,
|
||||
});
|
||||
const { data, isLoading } = useWebsiteEvents(websiteId);
|
||||
|
||||
const chartData = useMemo(() => {
|
||||
if (!data) return [];
|
||||
|
|
|
|||
|
|
@ -66,8 +66,8 @@ async function clickhouseQuery(
|
|||
order by t
|
||||
`,
|
||||
params,
|
||||
).then(a => {
|
||||
return Object.values(a).map(a => {
|
||||
).then(result => {
|
||||
return Object.values(result).map(a => {
|
||||
return { x: a.x, y: Number(a.y) };
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue