From af7146f5558d2ddd4dbe6f9fde49dbad48ce6a64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Gerhard=20Lindesva=CC=88rd?= Date: Wed, 14 May 2025 22:28:14 +0200 Subject: [PATCH] fix(dashboard): add weekly interval #154 --- .../src/components/overview/overview-interval.tsx | 4 ++++ apps/dashboard/src/components/report/ReportInterval.tsx | 9 +++++++++ apps/dashboard/src/hooks/useFormatDateInterval.ts | 8 ++++++++ packages/common/src/fill-series.ts | 7 +++++++ 4 files changed, 28 insertions(+) diff --git a/apps/dashboard/src/components/overview/overview-interval.tsx b/apps/dashboard/src/components/overview/overview-interval.tsx index 6ed7ebbf..7705f0b0 100644 --- a/apps/dashboard/src/components/overview/overview-interval.tsx +++ b/apps/dashboard/src/components/overview/overview-interval.tsx @@ -37,6 +37,10 @@ export function OverviewInterval() { value: 'day', label: 'Day', }, + { + value: 'week', + label: 'Week', + }, { value: 'month', label: 'Month', diff --git a/apps/dashboard/src/components/report/ReportInterval.tsx b/apps/dashboard/src/components/report/ReportInterval.tsx index 1754f03c..b3920842 100644 --- a/apps/dashboard/src/components/report/ReportInterval.tsx +++ b/apps/dashboard/src/components/report/ReportInterval.tsx @@ -62,6 +62,15 @@ export function ReportInterval({ value: 'day', label: 'Day', }, + { + value: 'week', + label: 'Week', + disabled: + range === 'today' || + range === 'lastHour' || + range === '30min' || + range === '7d', + }, { value: 'month', label: 'Month', diff --git a/apps/dashboard/src/hooks/useFormatDateInterval.ts b/apps/dashboard/src/hooks/useFormatDateInterval.ts index 1e303054..5118752c 100644 --- a/apps/dashboard/src/hooks/useFormatDateInterval.ts +++ b/apps/dashboard/src/hooks/useFormatDateInterval.ts @@ -13,6 +13,14 @@ export function formatDateInterval(interval: IInterval, date: Date): string { return new Intl.DateTimeFormat('en-GB', { month: 'short' }).format(date); } + if (interval === 'week') { + return new Intl.DateTimeFormat('en-GB', { + weekday: 'short', + day: '2-digit', + month: '2-digit', + }).format(date); + } + if (interval === 'day') { return new Intl.DateTimeFormat('en-GB', { weekday: 'short', diff --git a/packages/common/src/fill-series.ts b/packages/common/src/fill-series.ts index 6c996717..7048cc73 100644 --- a/packages/common/src/fill-series.ts +++ b/packages/common/src/fill-series.ts @@ -3,12 +3,14 @@ import { addHours, addMinutes, addMonths, + addWeeks, format, parseISO, startOfDay, startOfHour, startOfMinute, startOfMonth, + startOfWeek, } from 'date-fns'; import { NOT_SET_VALUE } from '@openpanel/constants'; @@ -39,6 +41,8 @@ function roundDate(date: Date, interval: IInterval): Date { return startOfHour(date); case 'day': return startOfDay(date); + case 'week': + return startOfWeek(date); case 'month': return startOfMonth(date); default: @@ -125,6 +129,9 @@ export function completeSerie( case 'day': currentDate = addDays(currentDate, 1); break; + case 'week': + currentDate = addWeeks(currentDate, 1); + break; case 'month': currentDate = addMonths(currentDate, 1); break;