Skip to content

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

fix: function metrics chart truncation logic

TzeYiing01fa4cb2384b
diff --git a/studio/components/ui/Charts/AreaChart.tsx b/studio/components/ui/Charts/AreaChart.tsx
index f83fcf91625..22f722967ec 100644
--- a/studio/components/ui/Charts/AreaChart.tsx
+++ b/studio/components/ui/Charts/AreaChart.tsx
@@ -47,7 +47,7 @@ const AreaChart: React.FC<AreaChartProps> = ({
const resolvedHighlightedLabel =
(focusDataIndex !== null &&
data &&
- data[focusDataIndex] &&
+ data[focusDataIndex] !== undefined &&
day(data[focusDataIndex][xAxisKey]).format(customDateFormat)) ||
highlightedLabel
diff --git a/studio/pages/project/[ref]/functions/[functionSlug]/index.tsx b/studio/pages/project/[ref]/functions/[functionSlug]/index.tsx
index 2e677cc2f81..c52f69067ff 100644
--- a/studio/pages/project/[ref]/functions/[functionSlug]/index.tsx
+++ b/studio/pages/project/[ref]/functions/[functionSlug]/index.tsx
@@ -1,4 +1,4 @@
-import dayjs from 'dayjs'
+import dayjs, { Dayjs } from 'dayjs'
import { useMemo, useState } from 'react'
import { useRouter } from 'next/router'
import { Button } from 'ui'
@@ -27,10 +27,10 @@ const CHART_INTERVALS: ChartIntervals[] = [
startUnit: 'minute',
format: 'MMM D, h:mm:ssa',
},
- { key: '15min', label: '15 min', startValue: 15, startUnit: 'minute' },
- { key: '1hr', label: '1 hour', startValue: 1, startUnit: 'hour' },
- { key: '1day', label: '1 day', startValue: 1, startUnit: 'day' },
- { key: '7day', label: '7 days', startValue: 7, startUnit: 'day' },
+ { key: '15min', label: '15 min', startValue: 15, startUnit: 'minute', format: 'MMM D, h:mma' },
+ { key: '1hr', label: '1 hour', startValue: 1, startUnit: 'hour', format: 'MMM D, h:mma' },
+ { key: '1day', label: '1 day', startValue: 1, startUnit: 'hour', format: 'MMM D, h:mma' },
+ { key: '7day', label: '7 days', startValue: 7, startUnit: 'day', format: 'MMM D' },
]
const PageLayout: NextPageWithLayout = () => {
@@ -54,18 +54,24 @@ const PageLayout: NextPageWithLayout = () => {
}))
}, [data?.result])
- const startDate = dayjs().subtract(
- selectedInterval.startValue,
- selectedInterval.startUnit as dayjs.ManipulateType
- )
+ console.log(data)
+
+ const [startDate, endDate]: [Dayjs, Dayjs] = useMemo(() => {
+ const start = dayjs()
+ .subtract(selectedInterval.startValue, selectedInterval.startUnit as dayjs.ManipulateType)
+ .startOf(selectedInterval.startUnit as dayjs.ManipulateType)
+ const end = dayjs().startOf(selectedInterval.startUnit as dayjs.ManipulateType)
+ return [start, end]
+ }, [selectedInterval])
+ console.log(startDate.toISOString(), endDate.toISOString())
const chartData = useFillTimeseriesSorted(
normalizedData,
'timestamp',
['avg_execution_time', 'count'],
0,
startDate.toISOString(),
- dayjs().toISOString()
+ endDate.toISOString()
)
const canReadFunction = checkPermissions(PermissionAction.FUNCTIONS_READ, functionSlug as string)
@@ -111,17 +117,24 @@ const PageLayout: NextPageWithLayout = () => {
tooltip="Average execution time of function invocations"
data={chartData}
isLoading={isChartLoading}
- renderer={(props) => (
- <AreaChart
- className="w-full"
- xAxisKey="timestamp"
- customDateFormat={selectedInterval.format}
- yAxisKey="avg_execution_time"
- data={props.data}
- format="ms"
- highlightedValue={meanBy(props.data, 'avg_execution_time')}
- />
- )}
+ renderer={(props) => {
+ const latest = normalizedData[normalizedData.length - 1]
+ let highlightedValue
+ if (latest) {
+ highlightedValue = latest['avg_execution_time']
+ }
+ return (
+ <AreaChart
+ className="w-full"
+ xAxisKey="timestamp"
+ customDateFormat={selectedInterval.format}
+ yAxisKey="avg_execution_time"
+ data={props.data}
+ format="ms"
+ highlightedValue={highlightedValue}
+ />
+ )
+ }}
/>
<ReportWidget
title="Invocations"