mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem The time-range dropdown above the request charts on the project home page resets on every visit, so users who prefer a different range have to re-select it each time. Resolves FE-2828. <img width="819" height="353" alt="Screenshot 2026-10-16 at 10 42 05" src="https://github.com/user-attachments/assets/cb8d467b-e709-43b0-9ae4-b02ebccf5faf" /> ## Solution Persist the selection in localStorage, keyed per project (`home-chart-interval-${ref}`), in both usage section variants (`ProjectUsageSection` and `ProjectUsageSectionDeltas`, chosen by the `newHomepageUsageDeltas` flag). - New `resolveChartInterval` helper validates the stored value against the known keys and the plan's log retention, falling back to the plan default for corrupt values or after a plan downgrade. Unit tested. - Removed the `useEffect` in `ProjectUsageSection` that reset the interval on retention change, since it would overwrite the saved value. - Moved `getDaysRequired` into `logs.utils.ts` so the dropdown and the helper share the retention check. Manually verified with the flag on and off: reload keeps the selection, and each project keeps its own.
32 lines
652 B
TypeScript
32 lines
652 B
TypeScript
import type { ChartIntervals } from '@/types'
|
|
|
|
export const CHART_INTERVALS: ChartIntervals[] = [
|
|
{
|
|
key: '1hr',
|
|
label: 'Last 60 minutes',
|
|
startValue: 1,
|
|
startUnit: 'hour',
|
|
format: 'MMM D, h:mma',
|
|
},
|
|
{
|
|
key: '1day',
|
|
label: 'Last 24 hours',
|
|
startValue: 24,
|
|
startUnit: 'hour',
|
|
format: 'MMM D, ha',
|
|
},
|
|
{
|
|
key: '7day',
|
|
label: 'Last 7 days',
|
|
startValue: 7,
|
|
startUnit: 'day',
|
|
format: 'MMM D',
|
|
},
|
|
]
|
|
|
|
export function getDaysRequired(startValue: number, startUnit: string): number {
|
|
if (startUnit === 'day') return startValue
|
|
if (startUnit === 'hour') return startValue / 24
|
|
return 0
|
|
}
|