Files
supabase/apps/studio/routes/project/$ref/observability/storage.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

211 lines
8.1 KiB
TypeScript

import { createFileRoute } from '@tanstack/react-router'
import { ArrowRightIcon, ExternalLinkIcon, RefreshCwIcon } from 'lucide-react'
import { useState } from 'react'
import { Button } from 'ui'
import { OBSERVABILITY_DOCS_HREFS } from '@/components/interfaces/Observability/Observability.constants'
import {
NetworkTrafficRenderer,
ResponseSpeedChartRenderer,
TopApiRoutesRenderer,
TotalRequestsChartRenderer,
} from '@/components/interfaces/Reports/renderers/ApiRenderers'
import {
CacheHitRateChartRenderer,
TopCacheMissesRenderer,
} from '@/components/interfaces/Reports/renderers/StorageRenderers'
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 ReportWidget from '@/components/interfaces/Reports/ReportWidget'
import { 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 { useStorageReport } from '@/data/reports/storage-report-query'
import { useRefreshHandler, useReportDateRange } from '@/hooks/misc/useReportDateRange'
import { DOCS_URL } from '@/lib/constants'
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/storage')({
component: StorageReport,
staticData: {
observabilityLayoutTitle: 'Storage',
},
})
const REPORT_TITLE = 'Storage'
function StorageReport() {
const {
datePickerHelpers,
datePickerValue,
handleDatePickerChange,
showUpgradePrompt,
setShowUpgradePrompt,
selectedDateRange,
} = useReportDateRange(REPORT_DATERANGE_HELPER_LABELS.LAST_60_MINUTES)
const formatDateTime = useFormatDateTime()
const report = useStorageReport(selectedDateRange)
const { data, error, filters, isLoading, params, removeFilters, addFilter, refresh } = report
const onRefreshReport = useRefreshHandler(
datePickerValue,
datePickerHelpers,
handleDatePickerChange,
refresh
)
const [showDatePicker, setShowDatePicker] = useState(false)
useShortcut(SHORTCUT_IDS.OBSERVABILITY_REFRESH, onRefreshReport, {
enabled: !report.isLoading,
})
useShortcut(SHORTCUT_IDS.OBSERVABILITY_TOGGLE_DATE_PICKER, () => {
setShowDatePicker((open) => !open)
})
return (
<ReportPadding>
<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={report.isLoading}
icon={<RefreshCwIcon className={report.isLoading ? '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}
/>
{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>
)}
<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="storageReportDateRange"
/>
<DocsButton
href={OBSERVABILITY_DOCS_HREFS.storage}
topic={REPORT_TITLE}
className="ml-auto"
/>
</div>
<ReportFilterBar
onRemoveFilters={removeFilters}
onDatepickerChange={handleDatePickerChange}
datepickerFrom={params.totalRequests.iso_timestamp_start}
datepickerTo={params.totalRequests.iso_timestamp_end}
onAddFilter={addFilter}
isLoading={isLoading}
filters={filters}
selectedProduct="storage"
hideDatepicker={true}
datepickerHelpers={datePickerHelpers}
initialDatePickerValue={datePickerValue}
className="w-full"
showDatabaseSelector={false}
/>
</div>
}
>
<div className="mt-8 grid @4xl:grid-cols-2 gap-4">
<ReportWidget
isLoading={isLoading}
params={params.totalRequests}
title="Total Requests"
data={data.totalRequests || []}
error={error.totalRequest}
renderer={TotalRequestsChartRenderer}
append={TopApiRoutesRenderer}
appendProps={{ data: data.topRoutes || [], params: params.topRoutes }}
/>
<ReportWidget
isLoading={isLoading}
params={params.responseSpeed}
title="Response Speed"
tooltip="Average response speed of a request (in ms)"
data={data.responseSpeed || []}
error={error.responseSpeed}
renderer={ResponseSpeedChartRenderer}
appendProps={{ data: data.topSlowRoutes || [], params: params.topSlowRoutes }}
append={TopApiRoutesRenderer}
/>
<ReportWidget
isLoading={isLoading}
params={params.networkTraffic}
error={error.networkTraffic}
title="Network Traffic"
tooltip="Ingress is measured from request logs."
data={data.networkTraffic || []}
renderer={NetworkTrafficRenderer}
/>
<ReportWidget
isLoading={isLoading}
params={params.cacheHitRate}
title="Request Caching"
tooltip={
<div>
The number of storage requests that are cached at the edge level. A higher number of
hits is better.{' '}
<span className="flex items-center gap-1 text-foreground-lighter">
<a
href={`${DOCS_URL}/guides/storage/cdn/fundamentals`}
target="_blank"
rel="noreferrer"
>
Read More
</a>
<ExternalLinkIcon className="w-3 h-3" />
</span>
</div>
}
data={data.cacheHitRate || []}
renderer={CacheHitRateChartRenderer}
append={TopCacheMissesRenderer}
appendProps={{ data: data.topCacheMisses || [] }}
/>
</div>
</ReportStickyNav>
<div className="py-8">
<ObservabilityLink />
</div>
</ReportPadding>
)
}