refactor(webui): improve visual consistency (#5249)

This commit is contained in:
chengyongru authored and GitHub committed 2026-08-05 13:24:45 +08:00
1 parent a54d5d14cb
commit 9098ffd38f
33 files changed
+578 -646

No files matched your search

+35 -423
View File
@@ -109,6 +109,7 @@ import {
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover";
import { SegmentedControl } from "@/components/ui/segmented-control";
import { Textarea } from "@/components/ui/textarea";
import { isLoopbackHost } from "@/lib/network";
import {
@@ -144,7 +145,6 @@ import {
updateModelConfiguration,
updateNetworkSafetySettings,
updateProviderSettings,
updateSettings,
updateTranscriptionSettings,
updateWebSearchSettings,
} from "@/lib/api";
@@ -349,30 +349,6 @@ const SETTINGS_SEARCH_INPUT_CLASS = cn(
"focus-visible:ring-0 focus-visible:ring-offset-0",
);
const FALLBACK_TIMEZONES = [
"UTC",
"Asia/Shanghai",
"Asia/Hong_Kong",
"Asia/Tokyo",
"Asia/Seoul",
"Asia/Singapore",
"Asia/Taipei",
"Asia/Dubai",
"Asia/Kolkata",
"Europe/London",
"Europe/Paris",
"Europe/Berlin",
"Europe/Amsterdam",
"America/New_York",
"America/Chicago",
"America/Denver",
"America/Los_Angeles",
"America/Toronto",
"America/Sao_Paulo",
"Australia/Sydney",
"Pacific/Auckland",
];
interface CustomMcpForm {
name: string;
transport: CustomMcpTransport;
@@ -426,7 +402,6 @@ interface SettingsViewProps {
onModelNameChange: (modelName: string | null) => void;
onSettingsChange?: (payload: SettingsPayload) => void;
skills?: SkillSummary[];
onWorkspaceSettingsChange?: () => void | Promise<void>;
onSectionChange?: (section: SettingsSectionKey) => void;
onLogout?: () => void;
onRestart?: () => void;
@@ -631,7 +606,6 @@ export function SettingsView({
onModelNameChange,
onSettingsChange,
skills = [],
onWorkspaceSettingsChange,
onSectionChange,
onLogout,
onRestart,
@@ -841,7 +815,9 @@ export function SettingsView({
if (!cancelled && showLoading) setError((err as Error).message);
})
.finally(() => {
if (!cancelled) setLoading(false);
if (!cancelled) {
setLoading(false);
}
});
return () => {
cancelled = true;
@@ -1082,11 +1058,6 @@ export function SettingsView({
);
}, [form, settings]);
const runtimeDirty = useMemo(() => {
if (!settings) return false;
return form.timezone !== settings.agent.timezone;
}, [form, settings]);
const imageGenerationDirty = useMemo(() => {
if (!settings) return false;
return (
@@ -1399,27 +1370,6 @@ export function SettingsView({
}
};
const saveRuntimeSettings = async () => {
if (!settings || !runtimeDirty || saving) return;
setSaving(true);
try {
const payload = await updateSettings(token, {
timezone: form.timezone,
});
applyPayload(payload);
if (payload.requires_restart) {
setPendingRestartSections((prev) => ({ ...prev, runtime: true }));
}
await onWorkspaceSettingsChange?.();
await maybeRestartHostEngine(payload);
setError(null);
} catch (err) {
setError((err as Error).message);
} finally {
setSaving(false);
}
};
const saveImageGenerationSettings = async () => {
if (!settings || !imageGenerationDirty || imageGenerationSaving) return;
setImageGenerationSaving(true);
@@ -2276,11 +2226,7 @@ export function SettingsView({
return (
<RuntimeSettings
form={form}
setForm={setForm}
settings={settings}
dirty={runtimeDirty}
saving={saving}
onSave={saveRuntimeSettings}
onRestart={restartViaSettingsSurface}
isRestarting={isRestarting || hostEngineApplying}
requiresRestartPending={pendingRestartSections.runtime}
@@ -2902,10 +2848,7 @@ function AppearanceSettings({
<section>
<SettingsSectionTitle>{t("settings.sections.interface")}</SettingsSectionTitle>
<SettingsGroup>
<SettingsRow
title={t("settings.rows.theme")}
description={t("settings.help.theme")}
>
<SettingsRow title={t("settings.rows.theme")}>
<button
type="button"
onClick={onToggleTheme}
@@ -2932,10 +2875,7 @@ function AppearanceSettings({
</button>
</SettingsRow>
<SettingsRow
title={t("settings.rows.language")}
description={t("settings.help.language")}
>
<SettingsRow title={t("settings.rows.language")}>
<LanguageSwitcher />
</SettingsRow>
</SettingsGroup>
@@ -2944,10 +2884,7 @@ function AppearanceSettings({
<section>
<SettingsSectionTitle>{tx("settings.sections.localPreferences", "Local preferences")}</SettingsSectionTitle>
<SettingsGroup>
<SettingsRow
title={tx("settings.rows.density", "Density")}
description={tx("settings.help.density", "Stored only in this browser.")}
>
<SettingsRow title={tx("settings.rows.density", "Density")}>
<SegmentedControl
value={localPrefs.density}
options={[
@@ -2959,10 +2896,7 @@ function AppearanceSettings({
}
/>
</SettingsRow>
<SettingsRow
title={tx("settings.rows.activityMode", "Activity detail")}
description={tx("settings.help.activityMode", "Choose how much agent activity chrome to show by default.")}
>
<SettingsRow title={tx("settings.rows.activityMode", "Activity detail")}>
<SegmentedControl
value={localPrefs.activityMode}
options={[
@@ -2974,10 +2908,7 @@ function AppearanceSettings({
}
/>
</SettingsRow>
<SettingsRow
title={tx("settings.rows.fileEditDisplay", "File edit display")}
description={tx("settings.help.fileEditDisplay", "Choose whether file edit activity opens as line counts or a diff.")}
>
<SettingsRow title={tx("settings.rows.fileEditDisplay", "File edit display")}>
<SegmentedControl
value={localPrefs.fileEditDisplayMode}
options={[
@@ -2993,10 +2924,7 @@ function AppearanceSettings({
}
/>
</SettingsRow>
<SettingsRow
title={tx("settings.rows.codeWrap", "Code wrapping")}
description={tx("settings.help.codeWrap", "Keep long code lines readable on smaller screens.")}
>
<SettingsRow title={tx("settings.rows.codeWrap", "Code wrapping")}>
<ToggleButton
checked={localPrefs.codeWrap}
onChange={(codeWrap) => onChangeLocalPrefs((prev) => ({ ...prev, codeWrap }))}
@@ -3004,10 +2932,7 @@ function AppearanceSettings({
label={localPrefs.codeWrap ? tx("settings.values.on", "On") : tx("settings.values.off", "Off")}
/>
</SettingsRow>
<SettingsRow
title={tx("settings.rows.brandLogos", "Brand logos")}
description={tx("settings.help.brandLogos", "Show third-party provider and CLI logos in Settings.")}
>
<SettingsRow title={tx("settings.rows.brandLogos", "Brand logos")}>
<ToggleButton
checked={localPrefs.brandLogos}
onChange={(brandLogos) => onChangeLocalPrefs((prev) => ({ ...prev, brandLogos }))}
@@ -4854,10 +4779,7 @@ function ImageGenerationSettings({
<section>
<SettingsSectionTitle>{tx("settings.sections.imageGeneration", "Image generation")}</SettingsSectionTitle>
<SettingsGroup>
<SettingsRow
title={tx("settings.rows.imageGeneration", "Image generation")}
description={tx("settings.help.imageGeneration", "Expose generate_image in chats when a configured image provider is available.")}
>
<SettingsRow title={tx("settings.rows.imageGeneration", "Image generation")}>
<ToggleButton
checked={form.enabled}
onChange={(enabled) => onChangeForm((prev) => ({ ...prev, enabled }))}
@@ -4865,10 +4787,7 @@ function ImageGenerationSettings({
label={form.enabled ? tx("settings.values.on", "On") : tx("settings.values.off", "Off")}
/>
</SettingsRow>
<SettingsRow
title={tx("settings.rows.imageProvider", "Image provider")}
description={tx("settings.help.imageProvider", "Choose the registry provider used by generate_image.")}
>
<SettingsRow title={tx("settings.rows.imageProvider", "Image provider")}>
<ProviderPicker
providers={settings.image_generation.providers}
value={form.provider}
@@ -4905,10 +4824,7 @@ function ImageGenerationSettings({
<section>
<SettingsSectionTitle>{tx("settings.sections.imageDefaults", "Defaults")}</SettingsSectionTitle>
<SettingsGroup>
<SettingsRow
title={tx("settings.rows.imageModel", "Image model")}
description={tx("settings.help.imageModel", "Model name sent to the selected image provider.")}
>
<SettingsRow title={tx("settings.rows.imageModel", "Image model")}>
<ModelIdPicker
token={token}
settings={settings}
@@ -4928,10 +4844,7 @@ function ImageGenerationSettings({
onChange={(model) => onChangeForm((prev) => ({ ...prev, model }))}
/>
</SettingsRow>
<SettingsRow
title={tx("settings.rows.defaultAspectRatio", "Default aspect")}
description={tx("settings.help.defaultAspectRatio", "Used when the prompt does not choose an aspect ratio.")}
>
<SettingsRow title={tx("settings.rows.defaultAspectRatio", "Default aspect")}>
<ProviderPicker
providers={aspectOptions}
value={form.defaultAspectRatio}
@@ -4941,10 +4854,7 @@ function ImageGenerationSettings({
}
/>
</SettingsRow>
<SettingsRow
title={tx("settings.rows.defaultImageSize", "Default size")}
description={tx("settings.help.defaultImageSize", "Size hint sent to providers that support it.")}
>
<SettingsRow title={tx("settings.rows.defaultImageSize", "Default size")}>
<ProviderPicker
providers={sizeOptions}
value={form.defaultImageSize}
@@ -4954,10 +4864,7 @@ function ImageGenerationSettings({
}
/>
</SettingsRow>
<SettingsRow
title={tx("settings.rows.maxImagesPerTurn", "Max images per turn")}
description={tx("settings.help.maxImagesPerTurn", "Upper bound for one generate_image request.")}
>
<SettingsRow title={tx("settings.rows.maxImagesPerTurn", "Max images per turn")}>
<NumberInput
value={form.maxImagesPerTurn}
min={1}
@@ -5038,10 +4945,7 @@ function TranscriptionSettings({
label={form.enabled ? tx("settings.values.on", "On") : tx("settings.values.off", "Off")}
/>
</SettingsRow>
<SettingsRow
title={tx("settings.rows.transcriptionProvider", "Provider")}
description={tx("settings.help.transcriptionProvider", "Uses the matching provider credentials from Providers.")}
>
<SettingsRow title={tx("settings.rows.transcriptionProvider", "Provider")}>
<ProviderPicker
providers={transcription.providers}
value={form.provider}
@@ -5208,10 +5112,7 @@ function WebSettings({
<p className="mb-3 text-[12px] text-destructive">{capabilityError}</p>
) : null}
<SettingsGroup>
<SettingsRow
title={t("settings.byok.webSearch.provider")}
description={t("settings.byok.webSearch.providerHelp")}
>
<SettingsRow title={t("settings.byok.webSearch.provider")}>
<ProviderPicker
providers={settings.web_search.providers}
value={form.provider}
@@ -5222,10 +5123,7 @@ function WebSettings({
</SettingsRow>
{selectedProvider?.credential === "none" ? (
<SettingsRow
title={t("settings.byok.webSearch.credentials")}
description={t("settings.byok.webSearch.noCredentialHelp")}
>
<SettingsRow title={t("settings.byok.webSearch.credentials")}>
<StatusPill tone="success">{t("settings.byok.webSearch.noCredentialRequired")}</StatusPill>
</SettingsRow>
) : null}
@@ -5310,10 +5208,7 @@ function WebSettings({
<section>
<SettingsSectionTitle>{tx("settings.sections.webBehavior", "Behavior")}</SettingsSectionTitle>
<SettingsGroup>
<SettingsRow
title={tx("settings.rows.maxResults", "Max results")}
description={tx("settings.help.maxResults", "Results returned by each web_search call.")}
>
<SettingsRow title={tx("settings.rows.maxResults", "Max results")}>
<NumberInput
value={form.maxResults ?? settings.web_search.max_results}
min={1}
@@ -5321,10 +5216,7 @@ function WebSettings({
onChange={(maxResults) => onChangeForm((prev) => ({ ...prev, maxResults }))}
/>
</SettingsRow>
<SettingsRow
title={tx("settings.rows.timeout", "Timeout")}
description={tx("settings.help.timeout", "Seconds before a search provider request times out.")}
>
<SettingsRow title={tx("settings.rows.timeout", "Timeout")}>
<NumberInput
value={form.timeout ?? settings.web_search.timeout}
min={1}
@@ -6287,7 +6179,7 @@ function NanobotFeatureInstallDialog({
<Dialog open={Boolean(feature)} onOpenChange={onOpenChange}>
<DialogContent
showCloseButton={false}
className="w-[min(calc(100vw-2rem),24rem)] gap-0 rounded-[28px] border border-white/70 bg-card/95 p-5 text-center shadow-[0_24px_80px_rgba(15,23,42,0.20)] backdrop-blur-xl sm:rounded-[28px]"
className="w-[min(calc(100vw-2rem),24rem)] gap-0 p-5 text-center"
>
<DialogHeader className="items-center space-y-0 text-center">
<DialogTitle className="text-center text-[20px] font-semibold leading-tight tracking-[-0.02em] text-foreground">
@@ -7074,23 +6966,6 @@ function ChannelsSettings({
>
{!showingCompactDetail ? (
<section className="shrink-0 space-y-4">
<div className="flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between">
<p className="max-w-[680px] text-[13px] leading-5 text-muted-foreground">
{tx(
"settings.channels.description",
"Connect chat apps, email, and WebUI to nanobot.",
)}
</p>
<div className="flex flex-wrap gap-2 text-[12px] font-medium text-muted-foreground">
<span className="rounded-full bg-muted/70 px-2.5 py-1">
{t("settings.channels.caption", {
enabled: enabledCount,
total: allChannels.length,
defaultValue: "{{enabled}} enabled · {{total}} channels",
})}
</span>
</div>
</div>
<div className="flex flex-col gap-3 lg:flex-row lg:items-center">
<div className="relative min-w-0 flex-1">
<Search className="pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" aria-hidden />
@@ -7315,24 +7190,9 @@ function AppsCatalogSettings({
mcpError ||
(!focusedApp ? cliMessage || mcpMessage : null);
const statusIsError = Boolean(cliError || mcpError);
const readyCount = (cliApps?.installed_count ?? 0) + (mcpPresets?.installed_count ?? 0);
const caption = t("settings.apps.enabledSummary", {
count: readyCount,
defaultValue: "{{count}} ready",
});
return (
<div className="space-y-7">
<section className="space-y-4">
<div className="flex flex-col gap-2 sm:flex-row sm:items-end sm:justify-between">
<p className="max-w-[680px] text-[13px] leading-5 text-muted-foreground">
{tx(
"settings.apps.description",
"Add tools to nanobot, then @ them in chat.",
)}
</p>
<span className="text-[12px] font-medium text-muted-foreground">{caption}</span>
</div>
<div className="flex flex-col gap-3 lg:flex-row lg:items-center">
<div className="relative flex-1">
<Search className="pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" aria-hidden />
@@ -8299,11 +8159,7 @@ function CliAppLogo({ app, showBrandLogos }: { app: CliAppInfo; showBrandLogos:
function RuntimeSettings({
form,
setForm,
settings,
dirty,
saving,
onSave,
onRestart,
isRestarting,
requiresRestartPending,
@@ -8319,11 +8175,7 @@ function RuntimeSettings({
onInstallCapability,
}: {
form: AgentSettingsDraft;
setForm: Dispatch<SetStateAction<AgentSettingsDraft>>;
settings: SettingsPayload;
dirty: boolean;
saving: boolean;
onSave: () => void;
onRestart?: () => void;
isRestarting?: boolean;
requiresRestartPending: boolean;
@@ -8419,42 +8271,6 @@ function RuntimeSettings({
};
return (
<div className="space-y-7">
<section>
<SettingsSectionTitle>{tx("settings.sections.regional", "Regional")}</SettingsSectionTitle>
<SettingsGroup>
<SettingsRow
title={tx("settings.rows.timezone", "Timezone")}
description={tx(
"settings.help.timezone",
"Used for schedules and time-aware replies.",
)}
>
<TimezonePicker
value={form.timezone}
onChange={(timezone) => setForm((prev) => ({ ...prev, timezone }))}
/>
</SettingsRow>
<RestartSettingsFooter
dirty={dirty}
saving={saving}
pendingRestart={requiresRestartPending}
dirtyMessage={
isNativeHost
? tx("settings.status.hostRestartAfterSaving", "Save changes and nanobot will restart its engine.")
: tx("settings.status.restartAfterSaving", "Save changes, then restart when ready.")
}
pendingMessage={
isNativeHost
? tx("settings.status.hostRestartPending", "Saved. Restarting engine when ready.")
: tx("settings.status.savedRestartApply", "Saved. Restart when ready.")
}
onSave={onSave}
onRestart={onRestart}
isRestarting={isRestarting}
/>
</SettingsGroup>
</section>
{isNativeHost ? (
<section>
<SettingsSectionTitle>{tx("settings.sections.nativeHost", "Native host")}</SettingsSectionTitle>
@@ -8464,9 +8280,7 @@ function RuntimeSettings({
<SettingsRow
title={tx("settings.rows.logs", "Logs")}
description={
hostActionMessage?.target === "logs"
? hostActionMessage.message
: tx("settings.help.logs", "Open the native engine log folder.")
hostActionMessage?.target === "logs" ? hostActionMessage.message : undefined
}
>
<Button
@@ -8495,9 +8309,7 @@ function RuntimeSettings({
description={
hostActionMessage?.target === "diagnostics"
? hostActionMessage.message
: diagnosticsPath
? diagnosticsPath
: tx("settings.help.diagnostics", "Export a small runtime report for support.")
: diagnosticsPath || undefined
}
>
<Button
@@ -8542,7 +8354,7 @@ function RuntimeSettings({
? apiServiceError
: apiDefaults.running
? apiDefaults.endpoint
: tx("settings.api.description", "Connect SDKs and agents through a local /v1 endpoint.")
: undefined
}
>
<div className="flex items-center justify-end gap-2">
@@ -8608,10 +8420,7 @@ function RuntimeSettings({
onChange={(value) => setApiHost(value === "network" ? "0.0.0.0" : "127.0.0.1")}
/>
</SettingsRow>
<SettingsRow
title={tx("settings.api.port", "Port")}
description={tx("settings.api.portHelp", "The API uses this local port.")}
>
<SettingsRow title={tx("settings.api.port", "Port")}>
<NumberInput value={apiPort} min={1} max={65535} onChange={setApiPort} />
</SettingsRow>
{apiNetworkAccess ? (
@@ -8647,11 +8456,6 @@ function RuntimeSettings({
</>
) : null}
</SettingsGroup>
{!apiDefaults.installed && !apiDefaults.running ? (
<p className="mt-2 text-[11.5px] text-muted-foreground">
{tx("settings.api.autoInstall", "API support will be installed automatically when you start it.")}
</p>
) : null}
</section>
<section>
@@ -8661,7 +8465,7 @@ function RuntimeSettings({
title="Langfuse"
description={
settings.observability?.configured
? tx("settings.observability.configured", "Tracing credentials are available to nanobot.")
? undefined
: tx(
"settings.observability.environment",
"Set LANGFUSE_SECRET_KEY and LANGFUSE_PUBLIC_KEY, then restart nanobot.",
@@ -8708,10 +8512,15 @@ function RuntimeSettings({
) : null}
<ReadOnlyRow title={t("settings.rows.configPath")} value={settings.runtime.config_path} />
<ReadOnlyRow title={tx("settings.rows.workspacePath", "Default workspace")} value={settings.runtime.workspace_path} />
{onRestart && !requiresRestartPending ? (
<ReadOnlyRow title={tx("settings.rows.timezone", "Timezone")} value={form.timezone} />
{onRestart ? (
<SettingsRow
title={t("settings.rows.restart")}
description={t("app.system.restartHint")}
description={
requiresRestartPending
? tx("settings.status.savedRestartApply", "Saved. Restart when ready.")
: undefined
}
>
<Button
size="sm"
@@ -8829,117 +8638,6 @@ function AdvancedSettings({
);
}
function TimezonePicker({
value,
onChange,
}: {
value: string;
onChange: (timezone: string) => void;
}) {
const { t } = useTranslation();
const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback });
const [open, setOpen] = useState(false);
const [query, setQuery] = useState("");
const options = useMemo(() => timezoneOptions(value), [value]);
const filteredOptions = useMemo(() => filterTimezoneOptions(options, query), [options, query]);
const optionValues = useMemo(
() => filteredOptions.map((option) => option.name),
[filteredOptions],
);
const chooseTimezone = (timezone: string) => {
onChange(timezone);
setOpen(false);
};
const navigation = useComboboxNavigation({
open,
values: optionValues,
selectedValue: value,
onSelect: chooseTimezone,
onClose: () => setOpen(false),
});
return (
<Popover
open={open}
onOpenChange={(nextOpen) => {
setOpen(nextOpen);
if (!nextOpen) setQuery("");
}}
>
<PopoverTrigger asChild>
<Button
type="button"
variant="outline"
className={cn(
"h-8 w-[220px] justify-between rounded-full border-input bg-background px-3 text-[13px] font-normal shadow-none",
"hover:bg-accent/55 focus-visible:ring-2 focus-visible:ring-ring",
)}
>
<span className="truncate">{value || tx("settings.timezone.select", "Select timezone")}</span>
<ChevronDown className="ml-2 h-3.5 w-3.5 shrink-0 text-muted-foreground" aria-hidden />
</Button>
</PopoverTrigger>
<PopoverContent
align="end"
className="w-[340px] max-w-[calc(100vw-2rem)]"
>
<div className="sticky top-0 z-10 bg-popover px-1 pb-1">
<div className="flex h-9 items-center gap-2 rounded-full border border-input bg-background px-3">
<Search className="h-3.5 w-3.5 shrink-0 text-muted-foreground" aria-hidden />
<Input
autoFocus
value={query}
onChange={(event) => setQuery(event.target.value)}
{...navigation.inputProps}
placeholder={tx("settings.timezone.search", "Search timezone")}
aria-label={tx("settings.timezone.search", "Search timezone")}
className="h-7 border-0 bg-transparent px-0 text-[13px] shadow-none focus-visible:ring-0"
/>
</div>
</div>
{filteredOptions.length ? (
<div
{...navigation.listProps}
aria-label={tx("settings.timezone.select", "Select timezone")}
className="mt-1 max-h-[18rem] overflow-y-auto pr-0.5 scrollbar-thin scrollbar-track-transparent"
data-testid="timezone-picker-list"
>
{filteredOptions.map((option) => {
const selected = option.name === value;
return (
<ComboboxOption
key={option.name}
{...navigation.getOptionProps(option.name)}
className={cn(
"flex h-9 cursor-default items-center justify-between gap-3 rounded-[12px] px-2.5 text-[13px]",
selected && "text-foreground",
)}
>
<span className="min-w-0 truncate font-medium text-foreground">{option.name}</span>
<span className="ml-auto flex shrink-0 items-center gap-2">
<span className="text-[11.5px] font-medium text-muted-foreground/80">
{option.offset}
</span>
{selected ? <Check className="h-3.5 w-3.5 shrink-0" aria-hidden /> : null}
</span>
</ComboboxOption>
);
})}
</div>
) : (
<div
role="status"
className="px-3 py-5 text-center text-[12px] text-muted-foreground"
data-testid="timezone-picker-list"
>
{tx("settings.timezone.empty", "No matching timezones.")}
</div>
)}
</PopoverContent>
</Popover>
);
}
function ProviderPicker({
providers,
value,
@@ -9459,62 +9157,6 @@ function providerVisibilityRank(provider: SettingsPayload["providers"][number]):
return 200;
}
interface TimezoneOption {
name: string;
offset: string;
searchText: string;
}
function timezoneOptions(current: string): TimezoneOption[] {
return timezonesWithCurrent(current).map((name) => {
const offset = timezoneOffset(name);
return {
name,
offset,
searchText: `${name} ${name.replace(/_/g, " ")} ${offset}`.toLowerCase(),
};
});
}
function timezonesWithCurrent(current: string): string[] {
const intl = Intl as typeof Intl & {
supportedValuesOf?: (key: "timeZone") => string[];
};
let values: string[];
try {
values = intl.supportedValuesOf?.("timeZone") ?? [];
} catch {
values = [];
}
const deduped = new Set([...FALLBACK_TIMEZONES, ...values, current].filter(Boolean));
return Array.from(deduped).sort((left, right) => {
if (left === "UTC") return -1;
if (right === "UTC") return 1;
return left.localeCompare(right);
});
}
function filterTimezoneOptions(options: TimezoneOption[], query: string): TimezoneOption[] {
const normalized = query.trim().toLowerCase();
if (!normalized) return options;
return options.filter((option) => option.searchText.includes(normalized));
}
function timezoneOffset(timezone: string): string {
try {
const parts = new Intl.DateTimeFormat("en-US", {
timeZone: timezone,
timeZoneName: "shortOffset",
hour: "2-digit",
minute: "2-digit",
}).formatToParts(new Date());
const value = parts.find((part) => part.type === "timeZoneName")?.value;
return value ? value.replace(/^GMT$/, "UTC").replace(/^GMT/, "UTC") : "UTC";
} catch {
return "Custom timezone";
}
}
function optionRowsWithCurrent(
options: Array<{ name: string; label: string }>,
value: string,
@@ -9931,36 +9573,6 @@ function StatusPill({
);
}
function SegmentedControl({
value,
options,
onChange,
}: {
value: string;
options: Array<{ value: string; label: string }>;
onChange: (value: string) => void;
}) {
return (
<div className="inline-flex h-8 items-center rounded-full bg-muted p-0.5 text-[12px] font-medium text-muted-foreground">
{options.map((option) => (
<button
key={option.value}
type="button"
aria-pressed={value === option.value}
onClick={() => onChange(option.value)}
className={cn(
"rounded-full px-3 py-1 transition-colors",
value === option.value &&
"bg-background text-foreground ring-1 ring-inset ring-border/45",
)}
>
{option.label}
</button>
))}
</div>
);
}
function NumberInput({
value,
min,