OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.
fix(dashboard): add weekly interval #154
Carl-Gerhard Lindesvärdaf7146f5558d
diff --git a/apps/dashboard/src/components/overview/overview-interval.tsx b/apps/dashboard/src/components/overview/overview-interval.tsxindex 6ed7ebbf7..7705f0b01 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.tsxindex 1754f03ca..b39208426 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.tsindex 1e3030547..5118752cb 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.tsindex 6c996717c..7048cc73e 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;