Files
supabase/apps/studio/routes/project/$ref/observability/edge-functions.tsx
Maksym Ionutsa 028d329417 Fix/studio observability timezone labels (#54198)
## Problem

Observability date labels ignore the timezone set in the profile. They
always show the browser timezone or UTC. The header range label (for
example "Nov 27, 12:40pm → 12:50pm") uses bare `dayjs()`. The Data API
charts (Total Requests, Error Counts, Response Speed, Network Traffic)
pass `displayDateInUtc`, so the first and last timestamps under each
chart always show UTC.

## Solution

- Format the header range label with `useFormatDateTime()` on the
Database, Auth, Storage, Realtime, PostgREST and Edge Functions
observability pages.
- Remove `displayDateInUtc` from the four Data API charts in
`ApiRenderers.tsx`.
- Use `text-xs` for the date labels in `BarChart`, so they match
`ComposedChart` and `StackedBarChart`. This is a separate commit.

## Review instructions

1. Open Observability, Database, and set a timezone in your profile that
differs from your browser.
2. Check that the range label next to the date picker and the tooltip
show the same timezone.
3. Open Observability, Data API. Check that the labels under each chart
follow the profile timezone and use the same font size as the Database
charts.

<details>
<summary>Screenshots</summary>

<img width="1124" height="844" alt="CleanShot 2026-11-27 at 13 37 14@2x"
src="https://github.com/user-attachments/assets/e3d29c77-317a-4489-aa4c-1fbf4783cb57"
/>


font in Data API
<img width="318" height="72" alt="CleanShot 2026-11-27 at 13 40 19@2x"
src="https://github.com/user-attachments/assets/06e4d12f-245f-4d4e-9dc9-b7f2f7879e52"
/>
font in Database
<img width="342" height="66" alt="CleanShot 2026-11-27 at 13 41 08@2x"
src="https://github.com/user-attachments/assets/de200eb2-4351-471d-a220-bacea142b0d9"
/>


</details>


## Checklist

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [x] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill (not applicable, no docs
changes)
2026-11-27 16:39:47 +01:00

292 lines
10 KiB
TypeScript

import { useQueryClient } from '@tanstack/react-query'
import { createFileRoute } from '@tanstack/react-router'
import { useFlag, useParams } from 'common'
import { ArrowRightIcon, RefreshCwIcon } from 'lucide-react'
import { parseAsJson, useQueryState } from 'nuqs'
import { useMemo, useState } from 'react'
import { Button } from 'ui'
import { OBSERVABILITY_DOCS_HREFS } from '@/components/interfaces/Observability/Observability.constants'
import { ReportHeader } from '@/components/interfaces/Reports/ReportHeader'
import { ReportPadding } from '@/components/interfaces/Reports/ReportPadding'
import {
EDGE_FUNCTION_REGIONS,
REPORT_DATERANGE_HELPER_LABELS,
} from '@/components/interfaces/Reports/Reports.constants'
import ReportStickyNav from '@/components/interfaces/Reports/ReportStickyNav'
import { ReportChartV2 } from '@/components/interfaces/Reports/v2/ReportChartV2'
import {
numericFilterSchema,
ReportsNumericFilter,
} from '@/components/interfaces/Reports/v2/ReportsNumericFilter'
import {
ReportsSelectFilter,
selectFilterSchema,
} from '@/components/interfaces/Reports/v2/ReportsSelectFilter'
import { LogsDatePicker } from '@/components/interfaces/Settings/Logs/Logs.DatePickers'
import UpgradePrompt from '@/components/interfaces/Settings/Logs/UpgradePrompt'
import { ReportSettings } from '@/components/ui/Charts/ReportSettings'
import { useChartHoverState } from '@/components/ui/Charts/useChartHoverState'
import { DocsButton } from '@/components/ui/DocsButton'
import { ObservabilityLink } from '@/components/ui/ObservabilityLink'
import { RegionFlag } from '@/components/ui/RegionFlag'
import { ShortcutTooltip } from '@/components/ui/ShortcutTooltip'
import { useEdgeFunctionsQuery } from '@/data/edge-functions/edge-functions-query'
import { edgeFunctionReports } from '@/data/reports/v2/edge-functions.config'
import { useRefreshHandler, useReportDateRange } from '@/hooks/misc/useReportDateRange'
import { useFormatDateTime } from '@/lib/datetime'
import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
import { useShortcut } from '@/state/shortcuts/useShortcut'
export const Route = createFileRoute('/project/$ref/observability/edge-functions')({
component: EdgeFunctionsReportV2,
staticData: {
observabilityLayoutTitle: 'Edge Functions',
},
})
function EdgeFunctionsReportV2() {
return (
<ReportPadding>
<EdgeFunctionsUsage />
</ReportPadding>
)
}
const REPORT_TITLE = 'Edge Functions'
const EdgeFunctionsUsage = () => {
const { ref } = useParams()
const useOtel = useFlag('otelReports')
const { data: functions } = useEdgeFunctionsQuery({
projectRef: ref,
})
const chartSyncId = `edge-functions-${ref}`
useChartHoverState(chartSyncId)
// Filters
const [statusCodeFilter, setStatusCodeFilter] = useQueryState(
'status_code',
parseAsJson(numericFilterSchema.parse)
)
const [regionFilter, setRegionFilter] = useQueryState(
'region',
parseAsJson(selectFilterSchema.parse)
)
const [executionTimeFilter, setExecutionTimeFilter] = useQueryState(
'execution_time',
parseAsJson(numericFilterSchema.parse)
)
const [functionFilter, setFunctionFilter] = useQueryState(
'functions',
parseAsJson(selectFilterSchema.parse)
)
const {
selectedDateRange,
updateDateRange,
datePickerValue,
datePickerHelpers,
showUpgradePrompt,
setShowUpgradePrompt,
handleDatePickerChange,
} = useReportDateRange(REPORT_DATERANGE_HELPER_LABELS.LAST_60_MINUTES)
const formatDateTime = useFormatDateTime()
const queryClient = useQueryClient()
const [isRefreshing, setIsRefreshing] = useState(false)
const [showDatePicker, setShowDatePicker] = useState(false)
const reportConfig = useMemo(() => {
return edgeFunctionReports({
projectRef: ref!,
functions: functions ?? [],
startDate: selectedDateRange?.period_start?.date ?? '',
endDate: selectedDateRange?.period_end?.date ?? '',
interval: selectedDateRange?.interval ?? 'minute',
filters: {
functions: functionFilter ?? [],
status_code: statusCodeFilter,
region: regionFilter ?? [],
execution_time: executionTimeFilter,
},
useOtel,
})
}, [
ref,
functions,
selectedDateRange,
functionFilter,
statusCodeFilter,
regionFilter,
executionTimeFilter,
useOtel,
])
const onRefreshReport = useRefreshHandler(
datePickerValue,
datePickerHelpers,
handleDatePickerChange,
async () => {
if (!selectedDateRange) return
setIsRefreshing(true)
queryClient.invalidateQueries({ queryKey: ['projects', ref, 'report-v2'] })
setTimeout(() => setIsRefreshing(false), 1000)
}
)
useShortcut(SHORTCUT_IDS.OBSERVABILITY_REFRESH, onRefreshReport, {
enabled: !isRefreshing,
})
useShortcut(SHORTCUT_IDS.OBSERVABILITY_TOGGLE_DATE_PICKER, () => {
setShowDatePicker((open) => !open)
})
return (
<>
<ReportHeader title={REPORT_TITLE} showDatabaseSelector={false} />
<ReportStickyNav
content={
<div className="flex flex-col gap-2 w-full">
<div className="w-full flex items-center gap-2 flex-wrap">
<ShortcutTooltip
shortcutId={SHORTCUT_IDS.OBSERVABILITY_REFRESH}
label="Refresh report"
side="bottom"
>
<Button
disabled={isRefreshing}
icon={<RefreshCwIcon className={isRefreshing ? 'animate-spin' : ''} />}
className="w-7"
onClick={onRefreshReport}
/>
</ShortcutTooltip>
<ReportSettings chartId="edge-functions-charts" />
<LogsDatePicker
value={datePickerValue}
helpers={datePickerHelpers}
onSubmit={handleDatePickerChange}
open={showDatePicker}
onOpenChange={setShowDatePicker}
shortcutId={SHORTCUT_IDS.OBSERVABILITY_TOGGLE_DATE_PICKER}
/>
<UpgradePrompt
show={showUpgradePrompt}
setShowUpgradePrompt={setShowUpgradePrompt}
title="Report date range"
description="Report data can be stored for a maximum of 3 months depending on the plan that your project is on."
source="edgeFunctionsReportDateRange"
/>
{selectedDateRange && (
<div className="order-last flex w-full flex-wrap items-center gap-x-2 text-xs xl:order-none xl:w-auto">
<p className="text-foreground-light">
{formatDateTime(selectedDateRange.period_start.date, 'MMM D, h:mma')}
</p>
<p className="text-foreground-light">
<ArrowRightIcon size={12} />
</p>
<p className="text-foreground-light">
{formatDateTime(selectedDateRange.period_end.date, 'MMM D, h:mma')}
</p>
</div>
)}
<DocsButton
href={OBSERVABILITY_DOCS_HREFS.edgeFunctions}
topic={REPORT_TITLE}
className="ml-auto"
/>
</div>
<div className="w-full flex items-center gap-2 flex-wrap">
<ReportsSelectFilter
label="Function"
options={
functions?.map((fn: { name: string; id: string }) => ({
label: fn.name,
value: fn.id,
})) ?? []
}
value={functionFilter ?? []}
onChange={setFunctionFilter}
isLoading={isRefreshing}
showSearch
/>
<ReportsNumericFilter
label="Status Code"
value={statusCodeFilter}
onChange={setStatusCodeFilter}
defaultOperator="="
isLoading={isRefreshing}
/>
<ReportsNumericFilter
label="Execution Time"
value={executionTimeFilter}
onChange={setExecutionTimeFilter}
placeholder="Enter time in ms"
min={0}
max={99999}
defaultOperator=">="
isLoading={isRefreshing}
/>
<ReportsSelectFilter
label="Region"
options={EDGE_FUNCTION_REGIONS.map((region) => ({
value: region.key,
label: (
<div className="flex items-center gap-x-2">
<RegionFlag className="w-4" region={region.key} />
<div className="flex flex-wrap gap-x-2 items-center">
<span className="text-foreground text-xs">{region.label}</span>
<span className="text-foreground-lighter text-xs">{region.key}</span>
</div>
</div>
),
}))}
value={regionFilter ?? []}
onChange={setRegionFilter}
showSearch
/>
</div>
</div>
}
>
<div className="mt-8 grid @4xl:grid-cols-2 gap-4 pb-8">
{selectedDateRange &&
reportConfig
.filter((report) => !report.hide)
.map((report) => (
<ReportChartV2
key={`${report.id}`}
report={report}
projectRef={ref!}
interval={selectedDateRange.interval}
startDate={selectedDateRange?.period_start?.date}
endDate={selectedDateRange?.period_end?.date}
updateDateRange={updateDateRange}
syncId={chartSyncId}
filters={{
functions: functionFilter,
status_code: statusCodeFilter,
region: regionFilter,
execution_time: executionTimeFilter,
}}
/>
))}
</div>
</ReportStickyNav>
<div className="pb-8">
<ObservabilityLink />
</div>
</>
)
}