The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat(reports): support new database report granularity FE-2221 (#41228)
Jordi Enrice1004193179d
diff --git a/apps/studio/hooks/misc/useReportDateRange.ts b/apps/studio/hooks/misc/useReportDateRange.tsindex 41913a3f6c1..1f035362f98 100644--- a/apps/studio/hooks/misc/useReportDateRange.ts+++ b/apps/studio/hooks/misc/useReportDateRange.ts@@ -46,7 +46,8 @@ export const useReportDateRange = (defaultHelper:| REPORT_DATERANGE_HELPER_LABELS| string- | ReportsDatetimeHelper = REPORT_DATERANGE_HELPER_LABELS.LAST_60_MINUTES+ | ReportsDatetimeHelper = REPORT_DATERANGE_HELPER_LABELS.LAST_60_MINUTES,+ useV2Granularity = false) => {const { plan: orgPlan, isLoading: isOrgPlanLoading } = useCurrentOrgPlan()const [showUpgradePrompt, setShowUpgradePrompt] = useState(false)@@ -175,9 +176,15 @@ export const useReportDateRange = (return getDefaultHelper().helper.text}, [timestampStartValue, timestampEndValue, helperTextValue, getDefaultHelper])- const handleIntervalGranularity = useCallback((from: string, to: string) => {+ const handleIntervalGranularity = (from: string, to: string) => {const diffInDays = dayjs(to).diff(from, 'day', true)const diffInHours = dayjs(to).diff(from, 'hour', true)++ if (useV2Granularity) {+ if (diffInHours <= 24) return '1m'+ if (diffInDays <= 7) return '10m'+ }+const conditions = {'1m': diffInHours < 1.1, // less than 1.1 hours'5m': diffInHours < 3.1, // less than 3.1 hours@@ -199,7 +206,7 @@ export const useReportDateRange = (default:return '1h'}- }, [])+ }// Derive selectedDateRange from current valuesconst selectedDateRange: ReportDateRange = useMemo(@@ -208,7 +215,7 @@ export const useReportDateRange = (period_end: { date: timestampEnd, time_period: 'today' },interval: handleIntervalGranularity(timestampStart, timestampEnd),}),- [timestampStart, timestampEnd, handleIntervalGranularity]+ [timestampStart, timestampEnd, useV2Granularity])const updateDateRange = useCallback(diff --git a/apps/studio/pages/project/[ref]/observability/database.tsx b/apps/studio/pages/project/[ref]/observability/database.tsxindex dbec6f5350d..b764af90670 100644--- a/apps/studio/pages/project/[ref]/observability/database.tsx+++ b/apps/studio/pages/project/[ref]/observability/database.tsx@@ -6,7 +6,7 @@ import Link from 'next/link'import { useEffect, useRef, useState } from 'react'import { toast } from 'sonner'-import { useParams } from 'common'+import { useFlag, useParams } from 'common'import ReportHeader from 'components/interfaces/Reports/ReportHeader'import ReportPadding from 'components/interfaces/Reports/ReportPadding'import { REPORT_DATERANGE_HELPER_LABELS } from 'components/interfaces/Reports/Reports.constants'@@ -67,6 +67,7 @@ const DatabaseUsage = () => {const { db, chart, ref } = useParams()const { data: project } = useSelectedProjectQuery()const { data: org } = useSelectedOrganizationQuery()+ const reportGranularityV2 = useFlag('reportGranularityV2')const {selectedDateRange,@@ -78,7 +79,7 @@ const DatabaseUsage = () => {showUpgradePrompt,setShowUpgradePrompt,handleDatePickerChange,- } = useReportDateRange(REPORT_DATERANGE_HELPER_LABELS.LAST_60_MINUTES)+ } = useReportDateRange(REPORT_DATERANGE_HELPER_LABELS.LAST_60_MINUTES, reportGranularityV2)const state = useDatabaseSelectorStateSnapshot()const queryClient = useQueryClient()