Files
supabase/apps/studio/components/interfaces/QuerySources/LogsTimeRangeSubMenu.tsx
Danny WhiteandJoshen Lim 8fcd5e7f65 feat(studio): add Warehouse report date controls (#53494)
## Problem

The Warehouse report only shows the last hour.

## Solution

Add date selection and refresh using the shared report controls. Respect
the organisation’s log retention limits and the metrics API’s 30-day
maximum.

| After |
| --- |
| <img width="1688" height="1050" alt="CleanShot 2026-11-18 at 11 35
24@2x"
src="https://github.com/user-attachments/assets/88267bf8-1054-480b-ac26-c0c2b58386bc"
/> |
| _The new controls._ |
| <img width="2420" height="1028" alt="CleanShot 2026-11-18 at 11 47
52@2x"
src="https://github.com/user-attachments/assets/383c06a0-5470-4748-b9a6-fe80647a1399"
/> |
| _The standard retention upgrade prompt follow tapping either of these
on a Pro plan._ |

## Review instructions

1. Open the [Studio staging
preview](https://studio-staging-git-dnywh-warehouse-metrics-range-supabase.vercel.app)
and select a staging project with Warehouse access.
2. Open **Observability > Warehouse**, or
`/project/<ref>/observability/warehouse`
([example](https://studio-staging-git-dnywh-warehouse-metrics-range-supabase.vercel.app/dashboard/project/yirnfrgkxmnqgexikhfc/observability/warehouse)).
Change Last 60 minutes to Last 24 hours and check that the chart or
no-data state reflects the selected period.
3. Refresh the report. Check that the selected period stays selected.
4. On a paid staging organisation, select a period beyond its log
retention (for example, Last 14 days with 7-day retention). Check that
the retention upgrade prompt appears and the current period stays
selected.

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2026-11-19 15:08:18 +11:00

87 lines
3.0 KiB
TypeScript

import dayjs from 'dayjs'
import { CheckIcon, LockIcon } from 'lucide-react'
import {
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuSub,
DropdownMenuSubContent,
DropdownMenuSubTrigger,
} from 'ui'
import { datePickerValueToLogTimeRange, logTimeRangesEqual } from './LogTimeRange.utils'
import { EXPLORER_DATEPICKER_HELPERS } from '@/components/interfaces/Settings/Logs/Logs.constants'
import { isStartOutsideRetention } from '@/components/interfaces/Settings/Logs/Logs.utils'
import type { TimeRange } from '@/data/content/notebooks/notebook-schema'
import { useCheckEntitlements } from '@/hooks/misc/useCheckEntitlements'
export const LogsTimeRangeSubMenu = ({
range,
onRangeChange,
onOpenCustomRange,
onShowUpgrade,
}: {
range: TimeRange
onRangeChange: (range: TimeRange) => void
onOpenCustomRange: () => void
onShowUpgrade: () => void
}) => {
const { getEntitlementNumericValue } = useCheckEntitlements('log.retention_days')
const entitledToLogDays = getEntitlementNumericValue()
const isCustomRange = range._tag === 'absolute_time_range'
const presets = EXPLORER_DATEPICKER_HELPERS.map((helper) => ({
helper,
range: datePickerValueToLogTimeRange({
from: helper.calcFrom(),
to: helper.calcTo(),
isHelper: true,
text: helper.text,
}),
}))
const selectedPreset = presets.find((preset) => logTimeRangesEqual(range, preset.range))
return (
<DropdownMenuSub>
<DropdownMenuSubTrigger>
<div className="flex flex-col">
<span>Time range</span>
<span className="text-foreground-lighter text-xs">
{isCustomRange
? `${dayjs(range.start).format('DD MMM, HH:mm')} - ${dayjs(range.end).format('DD MMM, HH:mm')}`
: (selectedPreset?.helper.text ?? 'Custom range')}
</span>
</div>
</DropdownMenuSubTrigger>
<DropdownMenuSubContent className="w-52">
{presets.map(({ helper, range: presetRange }) => {
const isSelected = !isCustomRange && logTimeRangesEqual(range, presetRange)
const isLocked = isStartOutsideRetention(helper.calcFrom(), entitledToLogDays)
return (
<DropdownMenuItem
key={helper.text}
className="justify-between"
onClick={() => {
if (isLocked) return onShowUpgrade()
onRangeChange(presetRange)
}}
>
<span>{helper.text}</span>
{isLocked ? (
<LockIcon size={14} className="text-foreground-lighter" />
) : (
isSelected && <CheckIcon size={14} />
)}
</DropdownMenuItem>
)
})}
<DropdownMenuSeparator />
<DropdownMenuItem className="justify-between" onClick={onOpenCustomRange}>
<span>Custom range…</span>
{isCustomRange && <CheckIcon size={14} />}
</DropdownMenuItem>
</DropdownMenuSubContent>
</DropdownMenuSub>
)
}