import { useFlag } from 'common' import { CheckIcon, ChevronsUpDown, Globe } from 'lucide-react' import { useId, useMemo, useState } from 'react' import { Button, Card, CardContent, cn, 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 { findTimezoneByIana, 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 timezonePickerEnabled = useFlag('timezonePicker') const { timezone, storedTimezone, setTimezone, isAutoDetected } = useTimezone() const track = useTrack() const [open, setOpen] = useState(false) const listboxId = useId() // 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(() => findTimezoneByIana(timezone)?.text ?? timezone, [timezone]) if (!timezonePickerEnabled) return null 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 ( Timezone Choose how dates and times in logs and other dashboard surfaces are displayed. No timezones found handleSelect('')} >
Auto detect {browserTimezone}
{TIMEZONES_BY_IANA.map((entry) => { const ianaName = entry.utc[0] const isSelected = !isAutoDetected && storedTimezone === ianaName return ( handleSelect(ianaName)} > {entry.text} ) })}
) }