mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## 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)
199 lines
7.0 KiB
TypeScript
199 lines
7.0 KiB
TypeScript
import { createFileRoute } from '@tanstack/react-router'
|
|
import { useParams } from 'common'
|
|
import { ArrowRightIcon, RefreshCwIcon } from 'lucide-react'
|
|
import { useEffect, useRef, useState } from 'react'
|
|
import { Button } from 'ui'
|
|
|
|
import { OBSERVABILITY_DOCS_HREFS } from '@/components/interfaces/Observability/Observability.constants'
|
|
import ReportFilterBar from '@/components/interfaces/Reports/ReportFilterBar'
|
|
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'
|
|
import ReportStickyNav from '@/components/interfaces/Reports/ReportStickyNav'
|
|
import { SharedAPIReport } from '@/components/interfaces/Reports/SharedAPIReport/SharedAPIReport'
|
|
import { useSharedAPIReport } from '@/components/interfaces/Reports/SharedAPIReport/SharedAPIReport.constants'
|
|
import {
|
|
DatePickerValue,
|
|
LogsDatePicker,
|
|
} from '@/components/interfaces/Settings/Logs/Logs.DatePickers'
|
|
import UpgradePrompt from '@/components/interfaces/Settings/Logs/UpgradePrompt'
|
|
import { DocsButton } from '@/components/ui/DocsButton'
|
|
import { ObservabilityLink } from '@/components/ui/ObservabilityLink'
|
|
import { ShortcutTooltip } from '@/components/ui/ShortcutTooltip'
|
|
import { useRefreshHandler, useReportDateRange } from '@/hooks/misc/useReportDateRange'
|
|
import { useFormatDateTime } from '@/lib/datetime'
|
|
import { useDatabaseSelectorStateSnapshot } from '@/state/database-selector'
|
|
import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
|
|
import { useShortcut } from '@/state/shortcuts/useShortcut'
|
|
|
|
export const Route = createFileRoute('/project/$ref/observability/postgrest')({
|
|
component: PostgRESTReport,
|
|
staticData: {
|
|
observabilityLayoutTitle: 'PostgREST',
|
|
},
|
|
})
|
|
|
|
function PostgRESTReport() {
|
|
return (
|
|
<ReportPadding>
|
|
<PostgrestReport />
|
|
</ReportPadding>
|
|
)
|
|
}
|
|
|
|
const REPORT_TITLE = 'Data API'
|
|
|
|
const PostgrestReport = () => {
|
|
const { db, chart } = useParams()
|
|
const {
|
|
selectedDateRange,
|
|
datePickerValue,
|
|
datePickerHelpers,
|
|
showUpgradePrompt,
|
|
setShowUpgradePrompt,
|
|
handleDatePickerChange: handleDatePickerChangeFromHook,
|
|
} = useReportDateRange(REPORT_DATERANGE_HELPER_LABELS.LAST_60_MINUTES)
|
|
const formatDateTime = useFormatDateTime()
|
|
|
|
const {
|
|
data,
|
|
error,
|
|
isLoading,
|
|
refetch,
|
|
isRefetching,
|
|
filters,
|
|
addFilter,
|
|
removeFilters,
|
|
isLoadingData,
|
|
sql,
|
|
} = useSharedAPIReport({
|
|
filterBy: 'postgrest',
|
|
start: selectedDateRange?.period_start?.date,
|
|
end: selectedDateRange?.period_end?.date,
|
|
})
|
|
|
|
const state = useDatabaseSelectorStateSnapshot()
|
|
const [showDatePicker, setShowDatePicker] = useState(false)
|
|
|
|
const hasStateSyncedFromUrlRef = useRef(false)
|
|
useEffect(() => {
|
|
if (hasStateSyncedFromUrlRef.current) return
|
|
hasStateSyncedFromUrlRef.current = true
|
|
|
|
if (db !== undefined) {
|
|
setTimeout(() => {
|
|
// [Joshen] Adding a timeout here to support navigation from settings to reports
|
|
// Both are rendering different instances of ProjectLayout which is where the
|
|
// DatabaseSelectorContextProvider lies in (unless we reckon shifting the provider up one more level is better)
|
|
state.setSelectedDatabaseId(db)
|
|
}, 100)
|
|
}
|
|
if (chart !== undefined) {
|
|
setTimeout(() => {
|
|
const el = document.getElementById(chart)
|
|
if (el) el.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
|
}, 200)
|
|
}
|
|
}, [state, db, chart])
|
|
|
|
const handleDatePickerChange = (values: DatePickerValue) => {
|
|
handleDatePickerChangeFromHook(values)
|
|
}
|
|
|
|
const onRefreshReport = useRefreshHandler(
|
|
datePickerValue,
|
|
datePickerHelpers,
|
|
handleDatePickerChange,
|
|
refetch
|
|
)
|
|
|
|
useShortcut(SHORTCUT_IDS.OBSERVABILITY_REFRESH, onRefreshReport, {
|
|
enabled: !isRefetching,
|
|
})
|
|
useShortcut(SHORTCUT_IDS.OBSERVABILITY_TOGGLE_DATE_PICKER, () => {
|
|
setShowDatePicker((open) => !open)
|
|
})
|
|
|
|
return (
|
|
<>
|
|
<ReportHeader showDatabaseSelector={false} title={REPORT_TITLE} />
|
|
<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={isRefetching}
|
|
icon={<RefreshCwIcon className={isRefetching ? 'animate-spin' : ''} />}
|
|
className="w-7"
|
|
onClick={onRefreshReport}
|
|
/>
|
|
</ShortcutTooltip>
|
|
<LogsDatePicker
|
|
onSubmit={handleDatePickerChange}
|
|
value={datePickerValue}
|
|
helpers={datePickerHelpers}
|
|
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="postgrestReportDateRange"
|
|
/>
|
|
{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.dataApi}
|
|
topic={REPORT_TITLE}
|
|
className="ml-auto"
|
|
/>
|
|
</div>
|
|
<ReportFilterBar
|
|
filters={filters}
|
|
onAddFilter={addFilter}
|
|
onRemoveFilters={removeFilters}
|
|
isLoading={isLoadingData || isRefetching}
|
|
hideDatepicker={true}
|
|
datepickerHelpers={datePickerHelpers}
|
|
selectedProduct={'postgrest'}
|
|
showDatabaseSelector={false}
|
|
/>
|
|
</div>
|
|
}
|
|
>
|
|
<div className="relative mt-8">
|
|
<SharedAPIReport
|
|
data={data}
|
|
error={error}
|
|
isLoading={isLoading}
|
|
isRefetching={isRefetching}
|
|
sql={sql}
|
|
/>
|
|
</div>
|
|
</ReportStickyNav>
|
|
<div className="py-8">
|
|
<ObservabilityLink />
|
|
</div>
|
|
</>
|
|
)
|
|
}
|