mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Context This is largely just a mechanical change here: Opting to use lucide icons with the `Icon` suffix across all icon imports within `studio` - so that it’s clearer which components are icons + reduces the possibility of name collision with our own components - e.g <User /> vs <UserIcon /> Also added a eslint rule for this: <img width="1069" height="167" alt="image" src="https://github.com/user-attachments/assets/7f36f443-5ca2-4bf6-8d22-86e774513bfc" /> And updated `AGENTS.md` as such: ``` Icons come from `lucide-react`, always imported with the `Icon` suffix (`import { CheckIcon, Trash2Icon } from 'lucide-react'`) — never the bare names (`Check`) or `Check as CheckIcon` aliases (lint-enforced). ```
163 lines
6.0 KiB
TypeScript
163 lines
6.0 KiB
TypeScript
import { CheckIcon, GlobeIcon } from 'lucide-react'
|
|
import { useId, useMemo, useState } from 'react'
|
|
import {
|
|
Card,
|
|
CardContent,
|
|
cn,
|
|
ComboboxTrigger,
|
|
Command,
|
|
CommandEmpty,
|
|
CommandGroup,
|
|
CommandInput,
|
|
CommandItem,
|
|
CommandList,
|
|
Popover,
|
|
PopoverContent,
|
|
PopoverTrigger,
|
|
ScrollArea,
|
|
} from 'ui'
|
|
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
|
|
import {
|
|
PageSection,
|
|
PageSectionContent,
|
|
PageSectionDescription,
|
|
PageSectionMeta,
|
|
PageSectionSummary,
|
|
PageSectionTitle,
|
|
} from 'ui-patterns/PageSection'
|
|
|
|
import {
|
|
getTimezoneLabel,
|
|
getTimezoneLabelByIana,
|
|
TIMEZONES_BY_IANA,
|
|
} from '@/lib/constants/timezones'
|
|
import { useTimezone } from '@/lib/datetime'
|
|
import { guessLocalTimezone } from '@/lib/dayjs'
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
|
|
const AUTO_OPTION_VALUE = '__auto__'
|
|
|
|
export const TimezoneSettings = () => {
|
|
const track = useTrack()
|
|
const listboxId = useId()
|
|
const [open, setOpen] = useState(false)
|
|
const { timezone, storedTimezone, setTimezone, isAutoDetected } = useTimezone()
|
|
|
|
// Browser timezone is captured once and stays stable even when the user has
|
|
// overridden the dashboard timezone — that's the value the "Auto detect"
|
|
// option will revert to.
|
|
const browserTimezone = useMemo(() => guessLocalTimezone(), [])
|
|
|
|
const triggerLabel = useMemo(() => getTimezoneLabelByIana(timezone), [timezone])
|
|
|
|
const handleSelect = (nextStored: string) => {
|
|
setTimezone(nextStored)
|
|
const resolvedNext = nextStored || guessLocalTimezone()
|
|
track('timezone_picker_clicked', {
|
|
previousTimezone: timezone,
|
|
nextTimezone: resolvedNext,
|
|
isAutoDetected: nextStored === '',
|
|
source: 'account_preferences',
|
|
})
|
|
setOpen(false)
|
|
}
|
|
|
|
return (
|
|
<PageSection>
|
|
<PageSectionMeta>
|
|
<PageSectionSummary>
|
|
<PageSectionTitle>Timezone</PageSectionTitle>
|
|
<PageSectionDescription>
|
|
Choose how dates and times in logs and other dashboard surfaces are displayed.
|
|
</PageSectionDescription>
|
|
</PageSectionSummary>
|
|
</PageSectionMeta>
|
|
<PageSectionContent>
|
|
<Card>
|
|
<CardContent>
|
|
<FormItemLayout
|
|
isReactForm={false}
|
|
label="Display timezone"
|
|
layout="flex-row-reverse"
|
|
description={
|
|
isAutoDetected
|
|
? `Auto detected from your browser (${browserTimezone}).`
|
|
: 'Pick "Auto detect" to follow your browser timezone again.'
|
|
}
|
|
>
|
|
<Popover open={open} onOpenChange={setOpen}>
|
|
<PopoverTrigger asChild>
|
|
<ComboboxTrigger
|
|
aria-expanded={open}
|
|
aria-controls={listboxId}
|
|
data-state={open ? 'open' : 'closed'}
|
|
size="small"
|
|
>
|
|
<span className="flex min-w-0 items-center gap-2">
|
|
<GlobeIcon aria-hidden="true" className="h-4 w-4 shrink-0" />
|
|
<span className="truncate">
|
|
{isAutoDetected ? `Auto detect (${timezone})` : triggerLabel}
|
|
</span>
|
|
</span>
|
|
</ComboboxTrigger>
|
|
</PopoverTrigger>
|
|
<PopoverContent id={listboxId} className="w-[--radix-popover-trigger-width] p-0">
|
|
<Command>
|
|
<CommandInput placeholder="Search timezone..." className="h-9" />
|
|
<CommandList>
|
|
<CommandEmpty>No timezones found</CommandEmpty>
|
|
<CommandGroup>
|
|
<ScrollArea className="h-72">
|
|
<CommandItem
|
|
key={AUTO_OPTION_VALUE}
|
|
value={`Auto detect ${browserTimezone}`}
|
|
onSelect={() => handleSelect('')}
|
|
>
|
|
<div className="flex flex-col">
|
|
<span>Auto detect</span>
|
|
<span className="text-xs text-foreground-lighter">
|
|
{browserTimezone}
|
|
</span>
|
|
</div>
|
|
<CheckIcon
|
|
className={cn(
|
|
'ml-auto h-4 w-4',
|
|
isAutoDetected ? 'opacity-100' : 'opacity-0'
|
|
)}
|
|
/>
|
|
</CommandItem>
|
|
{TIMEZONES_BY_IANA.map((entry) => {
|
|
const ianaName = entry.utc[0]
|
|
const isSelected = !isAutoDetected && storedTimezone === ianaName
|
|
return (
|
|
<CommandItem
|
|
key={ianaName}
|
|
// CommandItem matches against the `value` prop for the input filter — include
|
|
// both the human label and the IANA name so search works for either.
|
|
value={`${getTimezoneLabel(entry)} ${ianaName}`}
|
|
onSelect={() => handleSelect(ianaName)}
|
|
>
|
|
{getTimezoneLabel(entry)}
|
|
<CheckIcon
|
|
className={cn(
|
|
'ml-auto h-4 w-4',
|
|
isSelected ? 'opacity-100' : 'opacity-0'
|
|
)}
|
|
/>
|
|
</CommandItem>
|
|
)
|
|
})}
|
|
</ScrollArea>
|
|
</CommandGroup>
|
|
</CommandList>
|
|
</Command>
|
|
</PopoverContent>
|
|
</Popover>
|
|
</FormItemLayout>
|
|
</CardContent>
|
|
</Card>
|
|
</PageSectionContent>
|
|
</PageSection>
|
|
)
|
|
}
|