Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix(observability): use 30m step for 7-day dashboard to preserve spikes FE-2813 (#43998)

Jordi Enric4336c8cf5a63
diff --git a/apps/studio/hooks/misc/useReportDateRange.ts b/apps/studio/hooks/misc/useReportDateRange.ts
index 4a5f4d23f2c..63c50248dc6 100644
--- a/apps/studio/hooks/misc/useReportDateRange.ts
+++ b/apps/studio/hooks/misc/useReportDateRange.ts
@@ -12,6 +12,17 @@ import { useCurrentOrgPlan } from 'hooks/misc/useCurrentOrgPlan'
import { createParser, useQueryState } from 'nuqs'
import { useCallback, useMemo, useState } from 'react'
+export const getIntervalGranularity = (from: string, to: string): AnalyticsInterval => {
+ const diffInDays = dayjs(to).diff(from, 'day', true)
+ const diffInHours = dayjs(to).diff(from, 'hour', true)
+
+ if (diffInHours <= 1) return '1m'
+ if (diffInHours <= 12) return '2m'
+ if (diffInHours <= 24) return '10m'
+ if (diffInDays <= 7) return '30m'
+ return '1d'
+}
+
export const DATERANGE_LIMITS: { [key: string]: number } = {
free: 1,
pro: 7,
@@ -186,23 +197,12 @@ export const useReportDateRange = (
return getDefaultHelper().helper.text
}, [timestampStartValue, timestampEndValue, helperTextValue, getDefaultHelper])
- const handleIntervalGranularity = (from: string, to: string): AnalyticsInterval => {
- const diffInDays = dayjs(to).diff(from, 'day', true)
- const diffInHours = dayjs(to).diff(from, 'hour', true)
-
- if (diffInHours <= 1) return '1m'
- if (diffInHours <= 12) return '2m'
- if (diffInHours <= 24) return '10m'
- if (diffInDays <= 7) return '1h'
- return '1d'
- }
-
// Derive selectedDateRange from current values
const selectedDateRange: ReportDateRange = useMemo(
() => ({
period_start: { date: timestampStart, time_period: '1d' },
period_end: { date: timestampEnd, time_period: 'today' },
- interval: handleIntervalGranularity(timestampStart, timestampEnd),
+ interval: getIntervalGranularity(timestampStart, timestampEnd),
}),
[timestampStart, timestampEnd]
)