mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
fix compare screens
This commit is contained in:
parent
f70f98fed0
commit
4d06b0ca5b
3 changed files with 12 additions and 17 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
import { useMemo } from 'react';
|
|
||||||
import { LoadingPanel } from '@/components/common/LoadingPanel';
|
import { LoadingPanel } from '@/components/common/LoadingPanel';
|
||||||
import { PageviewsChart } from '@/components/metrics/PageviewsChart';
|
|
||||||
import { useWebsitePageviewsQuery } from '@/components/hooks/queries/useWebsitePageviewsQuery';
|
|
||||||
import { useDateRange } from '@/components/hooks';
|
import { useDateRange } from '@/components/hooks';
|
||||||
|
import { useWebsitePageviewsQuery } from '@/components/hooks/queries/useWebsitePageviewsQuery';
|
||||||
|
import { PageviewsChart } from '@/components/metrics/PageviewsChart';
|
||||||
|
import { useMemo } from 'react';
|
||||||
|
|
||||||
export function WebsiteChart({
|
export function WebsiteChart({
|
||||||
websiteId,
|
websiteId,
|
||||||
|
|
@ -15,7 +15,7 @@ export function WebsiteChart({
|
||||||
const { startDate, endDate, unit, value } = dateRange;
|
const { startDate, endDate, unit, value } = dateRange;
|
||||||
const { data, isLoading, isFetching, error } = useWebsitePageviewsQuery({
|
const { data, isLoading, isFetching, error } = useWebsitePageviewsQuery({
|
||||||
websiteId,
|
websiteId,
|
||||||
compare: compareMode ? dateCompare?.['value'] : undefined,
|
compare: compareMode ? dateCompare?.compare : undefined,
|
||||||
});
|
});
|
||||||
const { pageviews, sessions, compare } = (data || {}) as any;
|
const { pageviews, sessions, compare } = (data || {}) as any;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
import { useState } from 'react';
|
|
||||||
import { Grid, Heading, Column, Row, Select, ListItem } from '@umami/react-zen';
|
|
||||||
import { useDateRange, useMessages, useNavigation } from '@/components/hooks';
|
|
||||||
import { MetricsTable } from '@/components/metrics/MetricsTable';
|
|
||||||
import { Panel } from '@/components/common/Panel';
|
|
||||||
import { DateDisplay } from '@/components/common/DateDisplay';
|
import { DateDisplay } from '@/components/common/DateDisplay';
|
||||||
|
import { Panel } from '@/components/common/Panel';
|
||||||
|
import { useDateRange, useMessages, useNavigation } from '@/components/hooks';
|
||||||
import { ChangeLabel } from '@/components/metrics/ChangeLabel';
|
import { ChangeLabel } from '@/components/metrics/ChangeLabel';
|
||||||
import { getCompareDate } from '@/lib/date';
|
import { MetricsTable } from '@/components/metrics/MetricsTable';
|
||||||
import { formatNumber } from '@/lib/format';
|
import { formatNumber } from '@/lib/format';
|
||||||
|
import { Column, Grid, Heading, ListItem, Row, Select } from '@umami/react-zen';
|
||||||
|
import { useState } from 'react';
|
||||||
|
|
||||||
export function CompareTables({ websiteId }: { websiteId: string }) {
|
export function CompareTables({ websiteId }: { websiteId: string }) {
|
||||||
const [data, setData] = useState([]);
|
const [data, setData] = useState([]);
|
||||||
|
|
@ -17,11 +16,7 @@ export function CompareTables({ websiteId }: { websiteId: string }) {
|
||||||
updateParams,
|
updateParams,
|
||||||
query: { view = 'path' },
|
query: { view = 'path' },
|
||||||
} = useNavigation();
|
} = useNavigation();
|
||||||
const { startDate, endDate } = getCompareDate(
|
const { startDate, endDate } = dateCompare;
|
||||||
dateCompare,
|
|
||||||
dateRange.startDate,
|
|
||||||
dateRange.endDate,
|
|
||||||
);
|
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
startAt: startDate.getTime(),
|
startAt: startDate.getTime(),
|
||||||
|
|
|
||||||
|
|
@ -289,13 +289,13 @@ export function minDate(...args: any[]) {
|
||||||
|
|
||||||
export function getCompareDate(compare: string, startDate: Date, endDate: Date) {
|
export function getCompareDate(compare: string, startDate: Date, endDate: Date) {
|
||||||
if (compare === 'yoy') {
|
if (compare === 'yoy') {
|
||||||
return { startDate: subYears(startDate, 1), endDate: subYears(endDate, 1) };
|
return { compare, startDate: subYears(startDate, 1), endDate: subYears(endDate, 1) };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compare === 'prev') {
|
if (compare === 'prev') {
|
||||||
const diff = differenceInMinutes(endDate, startDate);
|
const diff = differenceInMinutes(endDate, startDate);
|
||||||
|
|
||||||
return { startDate: subMinutes(startDate, diff), endDate: subMinutes(endDate, diff) };
|
return { compare, startDate: subMinutes(startDate, diff), endDate: subMinutes(endDate, diff) };
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue