The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat: update realtime report (#40252)
Filipe Cabaço038249088a70
diff --git a/apps/studio/components/interfaces/Reports/v2/ReportChartUpsell.tsx b/apps/studio/components/interfaces/Reports/v2/ReportChartUpsell.tsxindex 15fd4fb0173..4077b6548c9 100644--- a/apps/studio/components/interfaces/Reports/v2/ReportChartUpsell.tsx+++ b/apps/studio/components/interfaces/Reports/v2/ReportChartUpsell.tsx@@ -38,7 +38,7 @@ export const ReportChartUpsell = ({ report, orgSlug }: ReportsChartUpsellProps)const demoData = isHoveringUpgrade ? exponentialChartData.current : demoChartData.currentreturn (- <Card className={cn('h-[260px] relative')}>+ <Card className={cn('h-[280px] relative')}><div className="z-10 flex flex-col items-center justify-center space-y-2 h-full absolute top-0 left-0 w-full bg-surface-100/70 backdrop-blur-md"><h2 className="text-sm">{report.label}</h2><p className="text-sm text-foreground-light">diff --git a/apps/studio/components/interfaces/Reports/v2/ReportChartV2.tsx b/apps/studio/components/interfaces/Reports/v2/ReportChartV2.tsxindex d1ab6e80ac1..ef21606cd2c 100644--- a/apps/studio/components/interfaces/Reports/v2/ReportChartV2.tsx+++ b/apps/studio/components/interfaces/Reports/v2/ReportChartV2.tsx@@ -1,9 +1,10 @@import { useQuery } from '@tanstack/react-query'import { Loader2 } from 'lucide-react'-import { useEffect, useState } from 'react'+import { useState } from 'react'-import { ComposedChart } from 'components/ui/Charts/ComposedChart'import type { ChartHighlightAction } from 'components/ui/Charts/ChartHighlightActions'+import { ComposedChart } from 'components/ui/Charts/ComposedChart'+import { useChartHighlight } from 'components/ui/Charts/useChartHighlight'import type { AnalyticsInterval } from 'data/analytics/constants'import type { ReportConfig } from 'data/reports/v2/reports.types'import { useFillTimeseriesSorted } from 'hooks/analytics/useFillTimeseriesSorted'@@ -11,7 +12,6 @@ import { useCurrentOrgPlan } from 'hooks/misc/useCurrentOrgPlan'import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'import { Card, CardContent, cn } from 'ui'import { ReportChartUpsell } from './ReportChartUpsell'-import { useChartHighlight } from 'components/ui/Charts/useChartHighlight'export interface ReportChartV2Props {report: ReportConfig@@ -20,6 +20,10 @@ export interface ReportChartV2Props {endDate: stringinterval: AnalyticsIntervalupdateDateRange: (from: string, to: string) => void+ /**+ * Group ID used to invalidate React Query caches+ */+ queryGroup?: stringclassName?: stringsyncId?: stringfilters?: any@@ -63,6 +67,7 @@ export const ReportChartV2 = ({syncId,filters,highlightActions,+ queryGroup,}: ReportChartV2Props) => {const { data: org } = useSelectedOrganizationQuery()const { plan: orgPlan } = useCurrentOrgPlan()@@ -82,7 +87,7 @@ export const ReportChartV2 = ({'projects',projectRef,'report-v2',- { reportId: report.id, startDate, endDate, interval, filters },+ { reportId: report.id, queryGroup, startDate, endDate, interval, filters },],queryFn: async () => {return await report.dataProvider(projectRef, startDate, endDate, interval, filters)@@ -95,7 +100,10 @@ export const ReportChartV2 = ({const chartData = queryResult?.data || []const dynamicAttributes = queryResult?.attributes || []- const headerTotal = computePeriodTotal(chartData, dynamicAttributes)+ const showSumAsDefaultHighlight = report.showSumAsDefaultHighlight ?? true+ const headerTotal = showSumAsDefaultHighlight+ ? computePeriodTotal(chartData, dynamicAttributes)+ : undefined/*** Depending on the source the timestamp key could be 'timestamp' or 'period_start'@@ -140,7 +148,7 @@ export const ReportChartV2 = ({Error loading chart data</p>) : (- <div className="w-full">+ <div className="w-full relative"><ComposedChartchartId={report.id}attributes={dynamicAttributes}@@ -166,6 +174,7 @@ export const ReportChartV2 = ({syncId={syncId}sql={queryResult?.query}highlightActions={highlightActions}+ showNewBadge={report.showNewBadge}/></div>)}diff --git a/apps/studio/components/ui/Charts/ChartHeader.tsx b/apps/studio/components/ui/Charts/ChartHeader.tsxindex 94df3ecdab9..527f8bf4972 100644--- a/apps/studio/components/ui/Charts/ChartHeader.tsx+++ b/apps/studio/components/ui/Charts/ChartHeader.tsx@@ -17,6 +17,7 @@ import { formatBytes } from 'lib/helpers'import { numberFormatter } from './Charts.utils'import { useChartHoverState } from './useChartHoverState'import { InfoTooltip } from 'ui-patterns/info-tooltip'+import { Badge } from 'ui'export interface ChartHeaderProps {title?: string@@ -46,6 +47,7 @@ export interface ChartHeaderProps {attributes?: any[]sql?: stringtitleTooltip?: string+ showNewBadge?: boolean}export const ChartHeader = ({@@ -76,6 +78,7 @@ export const ChartHeader = ({attributes,sql,titleTooltip,+ showNewBadge,}: ChartHeaderProps) => {const { hoveredIndex, isHovered, isCurrentChart, setHover, clearHover } = useChartHoverState(syncId || 'default'@@ -230,7 +233,10 @@ export const ChartHeader = ({)}><div className="flex flex-col">- {title && chartTitle}+ <div className="flex items-center gap-2">+ {title && chartTitle}+ {showNewBadge && <Badge variant="success">New</Badge>}+ </div><div className="h-4">{hasHighlightedValue && highlighted}{!hideHighlightedLabel && label}diff --git a/apps/studio/components/ui/Charts/ComposedChart.tsx b/apps/studio/components/ui/Charts/ComposedChart.tsxindex acbcfc62db5..f2983d0fe21 100644--- a/apps/studio/components/ui/Charts/ComposedChart.tsx+++ b/apps/studio/components/ui/Charts/ComposedChart.tsx@@ -19,7 +19,7 @@ import {import { CategoricalChartState } from 'recharts/types/chart/types'import { cn } from 'ui'import { ChartHeader } from './ChartHeader'-import { ChartHighlightActions, ChartHighlightAction } from './ChartHighlightActions'+import { ChartHighlightAction, ChartHighlightActions } from './ChartHighlightActions'import {CHART_COLORS,DateTimeFormats,@@ -68,6 +68,7 @@ export interface ComposedChartProps<D = Datum> extends CommonChartProps<D> {docsUrl?: stringsql?: stringhighlightActions?: ChartHighlightAction[]+ showNewBadge?: boolean}export function ComposedChart({@@ -110,6 +111,7 @@ export function ComposedChart({sql,highlightActions,titleTooltip,+ showNewBadge,}: ComposedChartProps) {const { resolvedTheme } = useTheme()const { hoveredIndex, syncTooltip, setHover, clearHover } = useChartHoverState(@@ -303,6 +305,7 @@ export function ComposedChart({if (data.length === 0) {return (<NoDataPlaceholder+ hideTotalPlaceholder={highlightedValue === undefined}message={emptyStateMessage}description="It may take up to 24 hours for data to refresh"size={size}@@ -319,6 +322,7 @@ export function ComposedChart({<ChartHeaderhideHighlightedValue={hideHighlightedValue}title={title}+ showNewBadge={showNewBadge}format={format}hideHighlightedLabel={hideHighlightedLabel}hideHighlightArea={hideHighlightArea}diff --git a/apps/studio/components/ui/Charts/NoDataPlaceholder.tsx b/apps/studio/components/ui/Charts/NoDataPlaceholder.tsxindex 3cf4e0d6f9d..0c9c6fe9d82 100644--- a/apps/studio/components/ui/Charts/NoDataPlaceholder.tsx+++ b/apps/studio/components/ui/Charts/NoDataPlaceholder.tsx@@ -14,6 +14,7 @@ interface NoDataPlaceholderProps {size: Parameters<typeof useChartSize>[0]isFullHeight?: booleantitleTooltip?: string+ hideTotalPlaceholder?: boolean}const NoDataPlaceholder = ({attribute,@@ -24,6 +25,7 @@ const NoDataPlaceholder = ({size,isFullHeight = false,titleTooltip,+ hideTotalPlaceholder = false,}: NoDataPlaceholderProps) => {const { minHeight } = useChartSize(size)@@ -33,7 +35,7 @@ const NoDataPlaceholder = ({<ChartHeadertitle={attribute}format={format}- highlightedValue={0}+ highlightedValue={hideTotalPlaceholder ? undefined : 0}titleTooltip={titleTooltip}/>)}diff --git a/apps/studio/data/analytics/infra-monitoring-query.ts b/apps/studio/data/analytics/infra-monitoring-query.tsindex 57acc306bb8..b7604bbeefd 100644--- a/apps/studio/data/analytics/infra-monitoring-query.ts+++ b/apps/studio/data/analytics/infra-monitoring-query.ts@@ -14,6 +14,15 @@ export type InfraMonitoringAttribute =| 'disk_io_consumption'| 'pg_stat_database_num_backends'| 'supavisor_connections_active'+ | 'realtime_connections_connected'+ | 'realtime_channel_events'+ | 'realtime_channel_db_events'+ | 'realtime_channel_presence_events'+ | 'realtime_channel_joins'+ | 'realtime_authorization_rls_execution_time'+ | 'realtime_payload_size'+ | 'realtime_sum_connections_connected'+ | 'realtime_replication_connection_lag'export type InfraMonitoringVariables = {projectRef?: stringdiff --git a/apps/studio/data/reports/realtime-charts.ts b/apps/studio/data/reports/realtime-charts.tsdeleted file mode 100644index b03b6577007..00000000000--- a/apps/studio/data/reports/realtime-charts.ts+++ /dev/null@@ -1,85 +0,0 @@-export const getRealtimeReportAttributes = (isFreePlan: boolean) => [- {- id: 'client-to-realtime-connections',- label: 'Realtime connections',- valuePrecision: 2,- hide: false,- showTooltip: false,- showLegend: false,- showMaxValue: false,- hideChartType: false,- defaultChartStyle: 'bar',- titleTooltip: '',- attributes: [- {- attribute: 'realtime_connections_connected',- provider: 'infra-monitoring',- label: 'Connections',- },- ],- },- {- id: 'channel-events',- label: 'Channel Events',- valuePrecision: 2,- hide: false,- showTooltip: true,- showLegend: true,- showMaxValue: false,- hideChartType: false,- defaultChartStyle: 'bar',- attributes: [- {- attribute: 'realtime_channel_events',- provider: 'infra-monitoring',- label: 'Broadcast',- },- {- attribute: 'realtime_channel_db_events',- provider: 'infra-monitoring',- label: 'Postgres Changes',- },- {- attribute: 'realtime_channel_presence_events',- provider: 'infra-monitoring',- label: 'Presence',- },- ],- },- // {- // id: 'channel-presence-events',- // label: 'Channel Presence Events',- // valuePrecision: 2,- // hide: false,- // showTooltip: false,- // showLegend: false,- // showMaxValue: false,- // hideChartType: false,- // defaultChartStyle: 'bar',- // attributes: [- // {- // attribute: 'realtime_channel_presence_events',- // provider: 'infra-monitoring',- // label: 'Presence',- // },- // ],- // },- {- id: 'realtime_rate_of_channel_joins',- label: 'Rate of Channel Joins',- valuePrecision: 2,- hide: false,- showTooltip: false,- showLegend: false,- showMaxValue: false,- hideChartType: false,- defaultChartStyle: 'bar',- attributes: [- {- attribute: 'realtime_channel_joins',- provider: 'infra-monitoring',- label: 'Presence',- },- ],- },-]diff --git a/apps/studio/data/reports/v2/realtime.config.ts b/apps/studio/data/reports/v2/realtime.config.tsnew file mode 100644index 00000000000..3d7c4422817--- /dev/null+++ b/apps/studio/data/reports/v2/realtime.config.ts@@ -0,0 +1,306 @@+import type { AnalyticsData, AnalyticsInterval } from 'data/analytics/constants'+import { getInfraMonitoring, InfraMonitoringAttribute } from 'data/analytics/infra-monitoring-query'+import { ReportConfig } from './reports.types'++async function runInfraMonitoringQuery(+ projectRef: string,+ attribute: InfraMonitoringAttribute,+ startDate: string,+ endDate: string,+ interval: AnalyticsInterval,+ databaseIdentifier?: string+): Promise<AnalyticsData> {+ const data = await getInfraMonitoring({+ projectRef,+ attribute,+ startDate,+ endDate,+ interval,+ databaseIdentifier,+ })++ return data+}++export const realtimeReports = ({+ projectRef,+ startDate,+ endDate,+ interval,+ databaseIdentifier,+}: {+ projectRef: string+ startDate: string+ endDate: string+ interval: AnalyticsInterval+ databaseIdentifier?: string+}): ReportConfig[] => [+ {+ id: 'client-to-realtime-connections',+ label: 'Connections',+ valuePrecision: 0,+ hide: false,+ showTooltip: false,+ showLegend: false,+ showMaxValue: false,+ hideChartType: false,+ defaultChartStyle: 'line',+ titleTooltip: '',+ availableIn: ['free', 'pro', 'team', 'enterprise'],+ dataProvider: async () => {+ const data = await runInfraMonitoringQuery(+ projectRef,+ 'realtime_connections_connected',+ startDate,+ endDate,+ interval,+ databaseIdentifier+ )++ const transformedData = (data?.data ?? []).map((p) => {+ const valueAsNumber = Number(p.realtime_connections_connected)+ return {+ ...p,+ realtime_connections_connected: Number.isNaN(valueAsNumber) ? 0 : valueAsNumber,+ }+ })++ const attributes = [+ {+ attribute: 'realtime_connections_connected',+ label: 'Connections',+ },+ ]++ return { data: transformedData, attributes }+ },+ },+ {+ id: 'channel-events',+ label: 'Channel Events',+ valuePrecision: 0,+ hide: false,+ showTooltip: true,+ showLegend: false,+ showMaxValue: false,+ hideChartType: false,+ defaultChartStyle: 'line',+ titleTooltip: '',+ availableIn: ['free', 'pro', 'team', 'enterprise'],+ dataProvider: async () => {+ const { data } = await runInfraMonitoringQuery(+ projectRef,+ 'realtime_channel_events',+ startDate,+ endDate,+ interval,+ databaseIdentifier+ )++ const transformedData = data?.map((p) => ({+ ...p,+ realtime_channel_events: Number(p.realtime_channel_events) || 0,+ }))++ const attributes = [+ {+ attribute: 'realtime_channel_events',+ label: 'Events',+ },+ ]++ return { data: transformedData || [], attributes }+ },+ },+ {+ id: 'realtime_rate_of_channel_joins',+ label: 'Rate of Channel Joins',+ valuePrecision: 2,+ hide: false,+ showSumAsDefaultHighlight: false,+ showTooltip: false,+ showLegend: false,+ showMaxValue: false,+ hideChartType: false,+ defaultChartStyle: 'line',+ titleTooltip: '',+ availableIn: ['free', 'pro', 'team', 'enterprise'],+ dataProvider: async () => {+ const data = await runInfraMonitoringQuery(+ projectRef,+ 'realtime_channel_joins',+ startDate,+ endDate,+ interval,+ databaseIdentifier+ )++ const attributes = [+ {+ attribute: 'realtime_channel_joins',+ label: 'Channel Joins',+ },+ ]++ return { data: data?.data || [], attributes }+ },+ },+ {+ id: 'realtime_payload_size',+ label: 'Broadcast Payload Size',+ valuePrecision: 2,+ showNewBadge: true,+ hide: false,+ showSumAsDefaultHighlight: false,+ showTooltip: true,+ showLegend: false,+ showMaxValue: false,+ hideChartType: false,+ defaultChartStyle: 'line',+ titleTooltip: 'Size of broadcast payloads sent through realtime.',+ availableIn: ['free', 'pro', 'team', 'enterprise'],+ YAxisProps: {+ width: 50,+ tickFormatter: (value: number) => `${value}B`,+ },+ format: (value: unknown) => `${Number(value).toFixed(2)}B`,+ dataProvider: async () => {+ const data = await runInfraMonitoringQuery(+ projectRef,+ 'realtime_payload_size',+ startDate,+ endDate,+ interval,+ databaseIdentifier+ )++ const attributes = [+ {+ attribute: 'realtime_payload_size',+ label: 'Payload Size (bytes)',+ },+ ]++ return { data: data?.data || [], attributes }+ },+ },+ {+ id: 'realtime_sum_connections_connected',+ label: 'Connected Clients',+ valuePrecision: 0,+ hide: false,+ showNewBadge: true,+ showTooltip: true,+ showLegend: false,+ showMaxValue: true,+ hideChartType: false,+ defaultChartStyle: 'line',+ titleTooltip: 'Total number of connected realtime clients.',+ availableIn: ['free', 'pro', 'team', 'enterprise'],+ dataProvider: async () => {+ const data = await runInfraMonitoringQuery(+ projectRef,+ 'realtime_sum_connections_connected',+ startDate,+ endDate,+ interval,+ databaseIdentifier+ )++ const transformedData = (data?.data ?? []).map((p) => {+ const valueAsNumber = Number(p.realtime_sum_connections_connected)+ return {+ ...p,+ realtime_sum_connections_connected: Number.isNaN(valueAsNumber) ? 0 : valueAsNumber,+ }+ })++ const attributes = [+ {+ attribute: 'realtime_sum_connections_connected',+ label: 'Connected Clients',+ },+ ]++ return { data: transformedData, attributes }+ },+ },+ {+ id: 'realtime_replication_connection_lag',+ label: 'Replication Connection Lag',+ valuePrecision: 2,+ showNewBadge: true,+ hide: false,+ showSumAsDefaultHighlight: false,+ showTooltip: true,+ showLegend: false,+ showMaxValue: false,+ hideChartType: false,+ defaultChartStyle: 'line',+ titleTooltip: 'Time between database commit and broadcast when using broadcast from database.',+ availableIn: ['pro', 'team', 'enterprise'],+ YAxisProps: {+ width: 50,+ tickFormatter: (value: number) => `${value}ms`,+ },+ format: (value: unknown) => `${Number(value).toFixed(2)}ms`,+ dataProvider: async () => {+ const data = await runInfraMonitoringQuery(+ projectRef,+ 'realtime_replication_connection_lag',+ startDate,+ endDate,+ interval,+ databaseIdentifier+ )++ const attributes = [+ {+ attribute: 'realtime_replication_connection_lag',+ label: 'Replication Lag (ms)',+ },+ ]++ return { data: data?.data || [], attributes }+ },+ },+ {+ id: 'realtime_authorization_rls_execution_time',+ label: 'RLS Execution Time',+ valuePrecision: 2,+ showNewBadge: true,+ hide: false,+ showSumAsDefaultHighlight: false,+ showTooltip: true,+ showLegend: false,+ showMaxValue: false,+ hideChartType: false,+ defaultChartStyle: 'line',+ titleTooltip: 'Execution time of RLS (Row Level Security) checks for realtime authorization.',+ availableIn: ['pro', 'team', 'enterprise'],+ YAxisProps: {+ width: 50,+ tickFormatter: (value: number) => `${value}ms`,+ },+ format: (value: unknown) => `${Number(value).toFixed(2)}ms`,+ dataProvider: async () => {+ const data = await runInfraMonitoringQuery(+ projectRef,+ 'realtime_authorization_rls_execution_time',+ startDate,+ endDate,+ interval,+ databaseIdentifier+ )++ const attributes = [+ {+ attribute: 'realtime_authorization_rls_execution_time',+ label: 'RLS Execution Time (ms)',+ },+ ]++ return { data: data?.data || [], attributes }+ },+ },+]diff --git a/apps/studio/data/reports/v2/reports.types.ts b/apps/studio/data/reports/v2/reports.types.tsindex 28377e0e1e3..81cbf00036a 100644--- a/apps/studio/data/reports/v2/reports.types.ts+++ b/apps/studio/data/reports/v2/reports.types.ts@@ -24,10 +24,16 @@ export interface ReportDataProvider<FiltersType> {export interface ReportConfig<FiltersType = any> {id: stringlabel: string+ /**+ * dataProvider should handle *fetching* and *transforming* the data to the components.+ * Avoid transforming data inside components.+ * Functions can be extracted to helpers for transforming the data, which will make it easier to test.+ */dataProvider: ReportDataProvider<FiltersType>valuePrecision: numberhide: booleanhideHighlightedValue?: boolean+ showSumAsDefaultHighlight?: booleanshowTooltip: booleanshowLegend: booleanshowMaxValue: boolean@@ -39,4 +45,5 @@ export interface ReportConfig<FiltersType = any> {YAxisProps?: YAxisPropsxAxisKey?: stringyAxisKey?: string+ showNewBadge?: boolean}diff --git a/apps/studio/pages/project/[ref]/reports/realtime.tsx b/apps/studio/pages/project/[ref]/reports/realtime.tsxindex d61c0259e1a..79d6920a993 100644--- a/apps/studio/pages/project/[ref]/reports/realtime.tsx+++ b/apps/studio/pages/project/[ref]/reports/realtime.tsx@@ -2,31 +2,26 @@ import { useQueryClient } from '@tanstack/react-query'import { useParams } from 'common'import dayjs from 'dayjs'import { ArrowRight, RefreshCw } from 'lucide-react'-import { useEffect, useState } from 'react'+import { useEffect, useMemo, useRef, useState } from 'react'import ReportFilterBar from 'components/interfaces/Reports/ReportFilterBar'import ReportHeader from 'components/interfaces/Reports/ReportHeader'import ReportPadding from 'components/interfaces/Reports/ReportPadding'-import {- DatePickerValue,- LogsDatePicker,-} from 'components/interfaces/Settings/Logs/Logs.DatePickers'+import { ReportChartV2 } from 'components/interfaces/Reports/v2/ReportChartV2'+import { LogsDatePicker } from 'components/interfaces/Settings/Logs/Logs.DatePickers'import DefaultLayout from 'components/layouts/DefaultLayout'import ReportsLayout from 'components/layouts/ReportsLayout/ReportsLayout'import { ButtonTooltip } from 'components/ui/ButtonTooltip'-import { LazyComposedChartHandler } from 'components/ui/Charts/ComposedChartHandler'import { useDatabaseSelectorStateSnapshot } from 'state/database-selector'import { REPORT_DATERANGE_HELPER_LABELS } from 'components/interfaces/Reports/Reports.constants'import ReportStickyNav from 'components/interfaces/Reports/ReportStickyNav'import UpgradePrompt from 'components/interfaces/Settings/Logs/UpgradePrompt'-import { analyticsKeys } from 'data/analytics/keys'-import { getRealtimeReportAttributes } from 'data/reports/realtime-charts'import { useReportDateRange } from 'hooks/misc/useReportDateRange'import { SharedAPIReport } from 'components/interfaces/Reports/SharedAPIReport/SharedAPIReport'import { useSharedAPIReport } from 'components/interfaces/Reports/SharedAPIReport/SharedAPIReport.constants'-import type { MultiAttribute } from 'components/ui/Charts/ComposedChart.utils'+import { realtimeReports } from 'data/reports/v2/realtime.config'import type { NextPageWithLayout } from 'types'const RealtimeReport: NextPageWithLayout = () => {@@ -57,9 +52,7 @@ const RealtimeUsage = () => {datePickerHelpers,showUpgradePrompt,setShowUpgradePrompt,- handleDatePickerChange: handleDatePickerChangeFromHook,- isOrgPlanLoading,- orgPlan,+ handleDatePickerChange,} = useReportDateRange(REPORT_DATERANGE_HELPER_LABELS.LAST_60_MINUTES)const queryClient = useQueryClient()const {@@ -79,38 +72,34 @@ const RealtimeUsage = () => {end: selectedDateRange?.period_end?.date,})+ const chartSyncId = `realtime-${ref}`+const state = useDatabaseSelectorStateSnapshot()- const isFreePlan = !isOrgPlanLoading && orgPlan?.id === 'free'- const REALTIME_REPORT_ATTRIBUTES = getRealtimeReportAttributes(isFreePlan)+ const reportConfig = useMemo(() => {+ return realtimeReports({+ projectRef: ref!,+ startDate: selectedDateRange?.period_start?.date ?? '',+ endDate: selectedDateRange?.period_end?.date ?? '',+ interval: selectedDateRange?.interval ?? 'minute',+ databaseIdentifier: state.selectedDatabaseId,+ })+ }, [ref, selectedDateRange, state.selectedDatabaseId])const onRefreshReport = async () => {if (!selectedDateRange) return- // [Joshen] Since we can't track individual loading states for each chart- // so for now we mock a loading state that only lasts for a secondsetIsRefreshing(true)-- const { period_start, period_end, interval } = selectedDateRange- REALTIME_REPORT_ATTRIBUTES.forEach((attr) => {- queryClient.invalidateQueries({- queryKey: analyticsKeys.infraMonitoring(ref, {- attribute: attr?.id,- startDate: period_start.date,- endDate: period_end.date,- interval,- databaseIdentifier: state.selectedDatabaseId,- }),- })- })-+ queryClient.invalidateQueries(['projects', ref, 'report-v2', { queryGroup: 'realtime' }])refetch()-setTimeout(() => setIsRefreshing(false), 1000)}- // [Joshen] Empty dependency array as we only want this running once+ const urlStateHasSyncedRef = useRef(false)useEffect(() => {+ if (urlStateHasSyncedRef.current) return+ urlStateHasSyncedRef.current = true+if (db !== undefined) {setTimeout(() => {// [Joshen] Adding a timeout here to support navigation from settings to reports@@ -125,11 +114,7 @@ const RealtimeUsage = () => {if (el) el.scrollIntoView({ behavior: 'smooth', block: 'center' })}, 200)}- }, [])-- const handleDatePickerChange = (values: DatePickerValue) => {- const promptShown = handleDatePickerChangeFromHook(values)- }+ }, [db, chart, state])const updateDateRange: UpdateDateRange = (from: string, to: string) => {updateDateRangeFromHook(from, to)@@ -179,19 +164,24 @@ const RealtimeUsage = () => {</div>}>- {selectedDateRange &&- REALTIME_REPORT_ATTRIBUTES.filter((chart) => !chart.hide).map((chart) => (- <LazyComposedChartHandler- key={chart.id}- {...chart}- attributes={chart.attributes as MultiAttribute[]}- interval={selectedDateRange.interval}- startDate={selectedDateRange?.period_start?.date}- endDate={selectedDateRange?.period_end?.date}- updateDateRange={updateDateRange}- defaultChartStyle={chart.defaultChartStyle as 'line' | 'bar' | 'stackedAreaLine'}- />- ))}+ <div className="mt-8 grid md:grid-cols-2 gap-4">+ {selectedDateRange &&+ reportConfig+ .filter((report) => !report.hide)+ .map((report) => (+ <ReportChartV2+ key={`${report.id}`}+ queryGroup="realtime"+ report={report}+ projectRef={ref!}+ interval={selectedDateRange.interval}+ startDate={selectedDateRange?.period_start?.date}+ endDate={selectedDateRange?.period_end?.date}+ updateDateRange={updateDateRange}+ syncId={chartSyncId}+ />+ ))}+ </div><div className=""><div className="mb-4"><h5 className="text-foreground mb-2">Realtime API Gateway</h5>