feat(webui): expand and organize settings with autosave (#5704)
* feat(webui): expand settings with autosave and live configuration * feat(memory): add long-term memory and idle compaction switches * refactor(webui): clarify settings hierarchy and align compact controls * refactor(webui): keep only memory consolidation in memory settings * refactor(webui): defer runtime changes until explicit restart * refactor(webui): remove default workspace setting * fix(webui): align model lists and remove preset counters * fix(i18n): use natural Chinese labels for chat platforms * fix(i18n): shorten chat settings navigation label * fix(webui): match settings navigation icons to text size * refactor(webui): remove redundant settings sidebar heading * refactor(webui): use icon-only back navigation in settings * fix(webui): remove back arrow hover hint * refactor(webui): remove redundant overview details * refactor(webui): hide secondary descriptions in settings rows * style(webui): replace settings dividers with rounded highlights * refactor(webui): remove redundant model list subtitles and badges * fix(i18n): restore chat translation namespace boundaries * fix(i18n): complete settings translations for all locales * fix(webui): reveal settings only for enabled capabilities * fix(webui): consolidate capabilities and isolate settings feedback * fix(webui): clear restart notices when settings are reverted * fix(webui): anchor restart controls in settings sidebar * fix(webui): shorten sidebar restart label * fix(webui): align settings spacing and control sizes * refactor(webui): unify settings dialogs and interaction feedback * fix(webui): keep settings option groups on one line without scrolling * refactor(webui): align settings spacing and sidebar icon proportions * style(webui): match main sidebar typography to settings * style(webui): use monospace for sidebar session handles * refactor(webui): remove heartbeat configuration from automations * feat(webui): expose configuration actions beside capability toggles * style(webui): remove ellipsis from configuration actions * refactor(webui): remove redundant app configuration controls * feat(webui): add compact sidebar navigation and shortcut hints * fix(webui): synchronize npm dependency lockfile * test(webui): align input radius expectation with pill styling * feat(webui): show daily token usage and cache breakdown * feat(webui): add model usage details and cache hit rates * feat(webui): chart daily token usage by model * refactor(webui): simplify usage details and model labels * fix(webui): hide usage dialog date range * refactor(webui): consolidate model usage into chart legends * fix(webui): enforce restart choices and correct settings test route * fix(webui): polish settings localization and controls * fix(webui): avoid repeated usage legend labels * fix(webui): skip empty usage columns in keyboard navigation * test(webui): assert settings behavior positively * feat(webui): refine sidebar navigation and add drag resizing * style(webui): soften sidebar scroll edges * style(webui): harmonize sidebar typography and text colors * feat(webui): move channels to the main sidebar * style(webui): remove dotted underlines from settings hints * fix(webui): unify tooltip hover delay * fix(webui): support Seatbelt sandbox settings * fix(webui): remove unused appearance density preference * fix(webui): align settings input values consistently * style(webui): group compact settings controls before inputs * feat(webui): edit multiline settings in compact dialogs * feat(webui): add continuous settings scrolling with gentle snapping * Revert "feat(webui): add continuous settings scrolling with gentle snapping" This reverts commit f0978c261a53c844185eeab4d0c3190fbd196fe6.
This commit is contained in:
1 parent
20f115bf46
commit
8ea683679d
244 files changed
+6929
-3900
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useEffect, useMemo, useRef, useState, type ComponentProps } from "react";
|
||||
import {
|
||||
Bot,
|
||||
Brain,
|
||||
@@ -27,12 +27,7 @@ import { useTranslation } from "react-i18next";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ComboboxOption, useComboboxNavigation } from "@/components/ui/combobox";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import { useLogoFallback } from "@/hooks/useLogoFallback";
|
||||
@@ -93,33 +88,35 @@ export function settingsProviderConfigured(
|
||||
export function ProviderPicker({
|
||||
providers,
|
||||
value,
|
||||
triggerProps,
|
||||
emptyLabel,
|
||||
showProviderLogos = false,
|
||||
onChange,
|
||||
}: {
|
||||
providers: Array<{ name: string; label: string }>;
|
||||
value: string;
|
||||
triggerProps?: Pick<ComponentProps<typeof Button>, "id" | "aria-label" | "aria-describedby" | "aria-invalid" | "disabled">;
|
||||
emptyLabel: string;
|
||||
showProviderLogos?: boolean;
|
||||
onChange: (provider: string) => void;
|
||||
}) {
|
||||
const selectedProvider = providers.find((provider) => provider.name === value) ?? null;
|
||||
const disabled = providers.length === 0;
|
||||
const disabled = !!triggerProps?.disabled || providers.length === 0;
|
||||
|
||||
return (
|
||||
<DropdownMenu modal={false}>
|
||||
<DropdownMenuTrigger asChild disabled={disabled}>
|
||||
<Button
|
||||
<Select value={value} onValueChange={onChange} disabled={disabled}>
|
||||
<SelectTrigger
|
||||
{...triggerProps}
|
||||
aria-label={triggerProps?.["aria-label"] ?? selectedProvider?.label ?? emptyLabel}
|
||||
type="button"
|
||||
variant="outline"
|
||||
disabled={disabled}
|
||||
className={cn(
|
||||
"h-8 w-[210px] 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",
|
||||
"h-9 w-full justify-between rounded-full border-input bg-background px-3 text-[13px] font-normal shadow-none",
|
||||
"settings-hover focus-visible:ring-2 focus-visible:ring-ring",
|
||||
disabled && "text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
<span className="flex min-w-0 items-center gap-2">
|
||||
<SelectValue placeholder={emptyLabel}><span className="flex min-w-0 items-center gap-2">
|
||||
{selectedProvider && showProviderLogos ? (
|
||||
<ProviderPickerIcon
|
||||
provider={selectedProvider.name}
|
||||
@@ -127,24 +124,14 @@ export function ProviderPicker({
|
||||
/>
|
||||
) : null}
|
||||
<span className="truncate">{selectedProvider?.label ?? emptyLabel}</span>
|
||||
</span>
|
||||
<ChevronDown className="ml-2 h-3.5 w-3.5 shrink-0 text-muted-foreground" aria-hidden />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent
|
||||
align="end"
|
||||
className="max-h-[18rem] w-[240px] overflow-y-auto scrollbar-thin scrollbar-track-transparent"
|
||||
>
|
||||
</span></SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{providers.map((provider) => {
|
||||
const selected = provider.name === value;
|
||||
return (
|
||||
<DropdownMenuItem
|
||||
<SelectItem
|
||||
key={provider.name}
|
||||
onSelect={() => onChange(provider.name)}
|
||||
className={cn(
|
||||
"flex cursor-default items-center justify-between gap-2 text-[13px]",
|
||||
selected && "bg-muted/80 text-foreground focus:bg-muted",
|
||||
)}
|
||||
value={provider.name}
|
||||
>
|
||||
<span className="flex min-w-0 items-center gap-2">
|
||||
{showProviderLogos ? (
|
||||
@@ -155,12 +142,11 @@ export function ProviderPicker({
|
||||
) : null}
|
||||
<span className="truncate">{provider.label}</span>
|
||||
</span>
|
||||
{selected ? <Check className="h-3.5 w-3.5 shrink-0" aria-hidden /> : null}
|
||||
</DropdownMenuItem>
|
||||
</SelectItem>
|
||||
);
|
||||
})}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -349,8 +335,8 @@ export function ModelIdPicker({
|
||||
type="button"
|
||||
variant="outline"
|
||||
className={cn(
|
||||
"h-9 w-[min(360px,70vw)] justify-between rounded-full border-input bg-background px-3 text-[12px] font-normal shadow-none",
|
||||
"hover:bg-accent/55 focus-visible:ring-2 focus-visible:ring-ring",
|
||||
"h-9 w-full justify-between rounded-full border-input bg-background px-3 text-[13px] font-normal shadow-none",
|
||||
"settings-hover focus-visible:ring-2 focus-visible:ring-ring",
|
||||
)}
|
||||
>
|
||||
<span className="flex min-w-0 items-center gap-2">
|
||||
@@ -373,7 +359,7 @@ export function ModelIdPicker({
|
||||
</PopoverTrigger>
|
||||
<PopoverContent
|
||||
align="end"
|
||||
className="w-[360px] max-w-[calc(100vw-2rem)] p-1.5"
|
||||
className="w-[var(--radix-popover-trigger-width)] max-w-[calc(100vw-2rem)] p-1.5"
|
||||
>
|
||||
<div className="p-1 pb-1.5">
|
||||
<div className="relative">
|
||||
@@ -410,11 +396,11 @@ export function ModelIdPicker({
|
||||
</div>
|
||||
) : !canFetchModels ? (
|
||||
<div className="px-2 py-1.5 text-[11px] leading-4 text-muted-foreground">
|
||||
{tx("settings.models.autoProviderCustomOnly", "Auto provider mode uses custom model IDs.")}
|
||||
{tx("settings.models.autoProviderCustomOnly", "Enter a model ID manually when using automatic provider selection.")}
|
||||
</div>
|
||||
) : waitingForModelSearch ? (
|
||||
<div className="px-2 py-1.5 text-[11px] leading-4 text-muted-foreground">
|
||||
{tx("settings.models.searchCatalog", "Search provider catalog to choose a model.")}
|
||||
{tx("settings.models.searchCatalog", "Search this provider’s model catalog.")}
|
||||
</div>
|
||||
) : loading ? (
|
||||
<div className="flex items-center gap-2 px-2 py-1.5 text-[11px] text-muted-foreground">
|
||||
@@ -435,8 +421,11 @@ export function ModelIdPicker({
|
||||
</div>
|
||||
) : isCatalog && !normalizedQuery ? (
|
||||
<div className="px-2 py-1.5 text-[11px] leading-4 text-muted-foreground">
|
||||
{tx("settings.models.searchCatalog", "Search provider catalog to choose a model.")}
|
||||
{providerModelCount ? ` ${providerModelCount} ${tx("settings.models.modelsAvailable", "available")}.` : ""}
|
||||
{tx("settings.models.searchCatalog", "Search this provider’s model catalog.")}
|
||||
{providerModelCount ? <> {t("settings.models.availableCount", {
|
||||
defaultValue: "Models available: {{count}}",
|
||||
count: providerModelCount,
|
||||
})}</> : null}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { SettingsHint } from "@/components/settings/shared/SettingsHint";
|
||||
import { isNativeRuntime } from "@/lib/runtime";
|
||||
import type { NanobotFeatureInfo } from "@/lib/types";
|
||||
import { cn } from "@/lib/utils";
|
||||
@@ -84,7 +85,7 @@ export function NanobotFeatureInstallDialog({
|
||||
variant="ghost"
|
||||
onClick={() => onOpenChange(false)}
|
||||
disabled={installing}
|
||||
className="h-11 w-full min-w-0 bg-muted/70 px-5 text-[15px] font-semibold text-foreground shadow-none hover:bg-muted"
|
||||
className="h-11 w-full min-w-0 bg-muted/70 px-5 text-[15px] font-semibold text-foreground shadow-none settings-hover"
|
||||
>
|
||||
{tx("settings.automations.cancel", "Cancel")}
|
||||
</Button>
|
||||
@@ -133,7 +134,7 @@ export function DismissibleStatusMessage({
|
||||
"flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition-colors",
|
||||
isError
|
||||
? "text-destructive/70 hover:bg-destructive/10 hover:text-destructive"
|
||||
: "text-muted-foreground/70 hover:bg-muted hover:text-foreground",
|
||||
: "text-muted-foreground/70 settings-hover hover:text-foreground",
|
||||
)}
|
||||
>
|
||||
<X className="h-3.5 w-3.5" aria-hidden />
|
||||
@@ -153,16 +154,16 @@ export function RestartRequiredNotice({
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div className="flex flex-col gap-3 rounded-control border border-amber-500/20 bg-amber-500/8 px-4 py-3 text-[12.5px] text-amber-800 dark:text-amber-200 sm:flex-row sm:items-center sm:justify-between">
|
||||
<span>{message}</span>
|
||||
<div className="flex flex-wrap items-center gap-x-3 gap-y-1 text-[12px] text-muted-foreground">
|
||||
<span role="status">{message}</span>
|
||||
{onRestart ? (
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="outline"
|
||||
variant="ghost"
|
||||
onClick={onRestart}
|
||||
disabled={isRestarting}
|
||||
className="h-8 rounded-full bg-background/80 px-3 text-[12px] font-semibold"
|
||||
className="h-8 rounded-full px-2 text-[12px] font-medium text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
{isRestarting ? (
|
||||
<Loader2 className="mr-1.5 h-3.5 w-3.5 animate-spin" aria-hidden />
|
||||
@@ -178,7 +179,7 @@ export function RestartRequiredNotice({
|
||||
|
||||
export function SettingsSectionTitle({ children }: { children: ReactNode }) {
|
||||
return (
|
||||
<h2 className="mb-2 px-1 text-[13px] font-semibold tracking-[-0.01em] text-foreground/85">
|
||||
<h2 className="settings-section-title select-none text-[13px] font-semibold tracking-[-0.01em] text-foreground/85">
|
||||
{children}
|
||||
</h2>
|
||||
);
|
||||
@@ -187,7 +188,7 @@ export function SettingsSectionTitle({ children }: { children: ReactNode }) {
|
||||
export function SettingsGroup({ children }: { children: ReactNode }) {
|
||||
return (
|
||||
<div className="overflow-hidden rounded-panel bg-settings-surface">
|
||||
<div className="divide-y divide-border/45">{children}</div>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -197,21 +198,18 @@ export function SettingsRow({
|
||||
description,
|
||||
children,
|
||||
}: {
|
||||
title: string;
|
||||
title: ReactNode;
|
||||
description?: string;
|
||||
children?: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<div className="flex min-h-[62px] flex-col gap-3 px-4 py-3.5 sm:flex-row sm:items-center sm:justify-between sm:px-5">
|
||||
<div className="settings-row rounded-xl transition-colors settings-hover focus-within:bg-sidebar-accent/60">
|
||||
<div className="min-w-0">
|
||||
<div className="text-[14px] font-medium leading-5 text-foreground">{title}</div>
|
||||
{description ? (
|
||||
<div className="mt-0.5 max-w-[28rem] text-[12px] leading-5 text-muted-foreground">
|
||||
{description}
|
||||
</div>
|
||||
) : null}
|
||||
<div className="select-none text-[14px] font-medium leading-5 text-foreground">
|
||||
{description ? <SettingsHint description={description}>{title}</SettingsHint> : title}
|
||||
</div>
|
||||
</div>
|
||||
{children ? <div className="min-w-0 sm:ml-6 sm:shrink-0">{children}</div> : null}
|
||||
{children ? <div className="settings-control">{children}</div> : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -235,6 +233,9 @@ export function ReadOnlyRow({
|
||||
}
|
||||
|
||||
export function RestartSettingsFooter({
|
||||
saveLabel,
|
||||
error = false,
|
||||
autoSave = false,
|
||||
dirty,
|
||||
saving,
|
||||
pendingRestart,
|
||||
@@ -247,6 +248,9 @@ export function RestartSettingsFooter({
|
||||
onReset,
|
||||
isRestarting,
|
||||
}: {
|
||||
saveLabel?: string;
|
||||
error?: boolean;
|
||||
autoSave?: boolean;
|
||||
dirty: boolean;
|
||||
saving: boolean;
|
||||
pendingRestart: boolean;
|
||||
@@ -269,22 +273,27 @@ export function RestartSettingsFooter({
|
||||
? tx("app.system.restartingEngine", "Restarting engine...")
|
||||
: t("app.system.restarting");
|
||||
const statusMessage =
|
||||
message ??
|
||||
(saving ? t("settings.actions.saving") : undefined) ?? message ??
|
||||
(pendingRestart && !dirty
|
||||
? pendingMessage ?? tx("settings.status.savedRestartApply", "Saved. Restart when ready.")
|
||||
? pendingMessage ?? tx("settings.status.savedRestartApply", "Saved. Restart to apply changes.")
|
||||
: dirty
|
||||
? dirtyMessage ?? t("settings.status.unsaved")
|
||||
? autoSave
|
||||
? error ? undefined : t("settings.actions.saving")
|
||||
: dirtyMessage ?? t("settings.status.unsaved")
|
||||
: undefined);
|
||||
const statusTone = disabled ? "danger" : dirty || pendingRestart ? "accent" : undefined;
|
||||
const statusTone = error || disabled ? "danger" : dirty || pendingRestart ? "accent" : undefined;
|
||||
|
||||
if (autoSave && !statusMessage && !pendingRestart) return null;
|
||||
|
||||
return (
|
||||
<div className="flex min-h-[58px] flex-col gap-3 px-4 py-3 sm:flex-row sm:items-center sm:justify-between sm:px-5">
|
||||
<div className="min-w-0 text-[13px] leading-5 text-muted-foreground">
|
||||
<div className={cn("settings-footer", autoSave && "settings-footer-auto")}>
|
||||
<div role={error ? "alert" : "status"} className="min-w-0 text-[13px] leading-5 text-muted-foreground">
|
||||
<SettingsStatusMessage tone={statusTone}>{statusMessage}</SettingsStatusMessage>
|
||||
</div>
|
||||
<div className="flex w-full shrink-0 flex-wrap justify-end gap-2 sm:w-auto">
|
||||
{pendingRestart && !dirty && onRestart ? (
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={onRestart}
|
||||
@@ -299,8 +308,9 @@ export function RestartSettingsFooter({
|
||||
{isRestarting ? restartingLabel : restartLabel}
|
||||
</Button>
|
||||
) : null}
|
||||
{onReset ? (
|
||||
{onReset && !autoSave ? (
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={onReset}
|
||||
@@ -310,15 +320,16 @@ export function RestartSettingsFooter({
|
||||
{t("settings.actions.cancel")}
|
||||
</Button>
|
||||
) : null}
|
||||
<Button
|
||||
{!autoSave ? <Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={onSave}
|
||||
disabled={!dirty || disabled || saving}
|
||||
className="rounded-full"
|
||||
>
|
||||
{saving ? t("settings.actions.saving") : t("settings.actions.save")}
|
||||
</Button>
|
||||
{saving ? t("settings.actions.saving") : saveLabel ?? t("settings.actions.save")}
|
||||
</Button> : null}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
@@ -366,7 +377,7 @@ export function StatusPill({
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
"inline-flex max-w-[260px] items-center rounded-full px-2.5 py-1 text-[12px] font-medium",
|
||||
"inline-flex max-w-[260px] select-none items-center rounded-full px-2.5 py-1 text-[12px] font-medium",
|
||||
tone === "success" && "bg-emerald-500/10 text-emerald-700 dark:text-emerald-300",
|
||||
tone === "warning" && "bg-amber-500/10 text-amber-700 dark:text-amber-300",
|
||||
tone === "neutral" && "bg-muted text-muted-foreground",
|
||||
@@ -391,7 +402,7 @@ export function NumberInput({
|
||||
suffix?: string;
|
||||
}) {
|
||||
return (
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="relative w-full">
|
||||
<Input
|
||||
type="number"
|
||||
min={min}
|
||||
@@ -401,9 +412,9 @@ export function NumberInput({
|
||||
const parsed = Number(event.target.value);
|
||||
if (Number.isFinite(parsed)) onChange(parsed);
|
||||
}}
|
||||
className="h-8 w-24 max-w-full rounded-full text-[13px]"
|
||||
className={cn("h-9 w-full rounded-full text-[13px]", suffix && "pr-12")}
|
||||
/>
|
||||
{suffix ? <span className="text-[12px] text-muted-foreground">{suffix}</span> : null}
|
||||
{suffix ? <span className="pointer-events-none absolute inset-y-0 right-3 flex select-none items-center text-[12px] text-muted-foreground">{suffix}</span> : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import { useEffect, useRef, useState, type ReactNode } from "react";
|
||||
import { ChevronDown } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { ToggleButton } from "@/components/settings/ToggleButton";
|
||||
import { SettingsGroup, SettingsRow } from "@/components/settings/shared/SettingsControls";
|
||||
import { Dialog, DialogContent, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
|
||||
|
||||
export function SettingsAdvancedOptions({ children }: { children: ReactNode }) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<details className="group/advanced [&>summary]:select-none">
|
||||
<summary className="settings-list-inset flex min-h-12 cursor-pointer list-none items-center justify-between gap-4 rounded-xl text-[13px] leading-5 text-muted-foreground settings-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring [&::-webkit-details-marker]:hidden">
|
||||
{t("settings.runtimeConfig.advancedOptions")}
|
||||
<ChevronDown aria-hidden className="h-3.5 w-3.5 shrink-0 group-open/advanced:rotate-180" />
|
||||
</summary>
|
||||
<div className="space-y-1">{children}</div>
|
||||
</details>
|
||||
);
|
||||
}
|
||||
|
||||
export function SettingsFeature({
|
||||
title, enabled, onChange, disabled, initialOpen = false, error, children,
|
||||
}: {
|
||||
title: string;
|
||||
enabled: boolean;
|
||||
onChange: (enabled: boolean) => void;
|
||||
disabled?: boolean;
|
||||
initialOpen?: boolean;
|
||||
error?: string;
|
||||
children?: ReactNode;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [open, setOpen] = useState(initialOpen && enabled);
|
||||
const section = useRef<HTMLElement>(null);
|
||||
useEffect(() => {
|
||||
if (initialOpen && enabled) {
|
||||
setOpen(true);
|
||||
section.current?.scrollIntoView?.({ block: "nearest" });
|
||||
}
|
||||
}, [initialOpen, enabled]);
|
||||
return (
|
||||
<section ref={section} aria-label={title}>
|
||||
<Dialog open={Boolean(children) && open} onOpenChange={setOpen}>
|
||||
<SettingsGroup>
|
||||
<SettingsRow title={children ? (
|
||||
<DialogTrigger asChild>
|
||||
<button type="button"
|
||||
className="flex min-h-9 w-full items-center rounded-lg text-start focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">
|
||||
{title}
|
||||
</button>
|
||||
</DialogTrigger>
|
||||
) : title}>
|
||||
{children ? <DialogTrigger asChild>
|
||||
<button type="button"
|
||||
className="mr-3 shrink-0 rounded-lg px-2 py-1 text-[13px] leading-5 text-muted-foreground settings-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">
|
||||
{t("settings.configure")}
|
||||
</button>
|
||||
</DialogTrigger> : null}
|
||||
<ToggleButton checked={enabled} disabled={disabled} ariaLabel={title} label={title}
|
||||
onChange={(next) => { setOpen(next); onChange(next); }} />
|
||||
</SettingsRow>
|
||||
</SettingsGroup>
|
||||
{children ? <DialogContent aria-describedby={undefined} className="settings-grid max-h-[85dvh] w-[min(calc(100vw-2rem),40rem)] max-w-none overflow-y-auto p-0 [--settings-surface:var(--background)]">
|
||||
<DialogTitle className="sr-only">{title}</DialogTitle>
|
||||
<div className="pb-4 pt-8">{children}</div>
|
||||
</DialogContent> : null}
|
||||
</Dialog>
|
||||
{error && !open ? <p role="alert" className="settings-list-inset pt-2 text-[13px] leading-5 text-destructive">{error}</p> : null}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { useState, type ReactNode } from "react";
|
||||
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
|
||||
export function SettingsHint({ children, description }: { children: ReactNode; description: string }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
return (
|
||||
<TooltipProvider>
|
||||
<Tooltip open={open} onOpenChange={setOpen}>
|
||||
<TooltipTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
onClick={(event) => { event.preventDefault(); setOpen(true); }}
|
||||
className="max-w-full cursor-help rounded-sm text-left outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top" className="max-w-[min(22rem,calc(100vw-2rem))] whitespace-normal text-pretty leading-5">
|
||||
{description}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import { useRef, useState } from "react";
|
||||
import { SquarePen } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
|
||||
|
||||
export function SettingsTextEditor({ id, title, description, value, placeholder, disabled, onSave }: {
|
||||
id?: string;
|
||||
title: string;
|
||||
description?: string;
|
||||
value: string;
|
||||
placeholder?: string;
|
||||
disabled?: boolean;
|
||||
onSave: (value: string) => void | Promise<void>;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [draft, setDraft] = useState(value);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
const editor = useRef<HTMLTextAreaElement>(null);
|
||||
const save = async () => {
|
||||
setSaving(true);
|
||||
setError("");
|
||||
try {
|
||||
await onSave(draft);
|
||||
setOpen(false);
|
||||
} catch (cause) {
|
||||
setError(cause instanceof Error ? cause.message : String(cause));
|
||||
editor.current?.focus();
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
return <Dialog open={open} onOpenChange={(next) => {
|
||||
if (saving) return;
|
||||
if (next) { setDraft(value); setError(""); }
|
||||
setOpen(next);
|
||||
}}>
|
||||
<TooltipProvider><Tooltip>
|
||||
<TooltipTrigger asChild><DialogTrigger asChild>
|
||||
<Button id={id} type="button" variant="ghost" disabled={disabled} aria-label={title}
|
||||
className="ml-auto flex h-9 w-9 shrink-0 rounded-full p-0 text-muted-foreground">
|
||||
<SquarePen className="h-4 w-4" aria-hidden />
|
||||
</Button>
|
||||
</DialogTrigger></TooltipTrigger>
|
||||
<TooltipContent>{t("settings.actions.edit")}</TooltipContent>
|
||||
</Tooltip></TooltipProvider>
|
||||
<DialogContent className="max-w-xl" showCloseButton={!saving}
|
||||
onOpenAutoFocus={(event) => { event.preventDefault(); editor.current?.focus(); }}
|
||||
onEscapeKeyDown={(event) => { if (saving) event.preventDefault(); }}
|
||||
onPointerDownOutside={(event) => { if (saving) event.preventDefault(); }}>
|
||||
<DialogHeader>
|
||||
<DialogTitle className="pr-6 text-base">{title}</DialogTitle>
|
||||
<DialogDescription>{description || title}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Textarea ref={editor} aria-label={title} value={draft} placeholder={placeholder} disabled={saving}
|
||||
aria-invalid={Boolean(error)} spellCheck={false}
|
||||
onChange={(event) => { setDraft(event.target.value); setError(""); }}
|
||||
className="h-[min(40vh,280px)] min-h-24 resize-none rounded-xl font-mono text-[13px] leading-6" />
|
||||
{error && <p role="alert" className="break-words text-[13px] text-destructive">{error}</p>}
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" disabled={saving} onClick={() => setOpen(false)}>{t("settings.actions.cancel")}</Button>
|
||||
<Button type="button" disabled={saving} onClick={() => void save()}>{t(saving ? "settings.actions.saving" : "settings.actions.save")}</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import { useMemo, useState, type ComponentProps } from "react";
|
||||
import { ChevronDown } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ComboboxOption, useComboboxNavigation } from "@/components/ui/combobox";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
|
||||
export function TimezonePicker({ value, onChange, ...triggerProps }: {
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
} & Pick<ComponentProps<typeof Button>, "id" | "aria-label" | "aria-describedby" | "aria-invalid" | "disabled">) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [query, setQuery] = useState("");
|
||||
const options = useMemo(() => {
|
||||
const now = new Date();
|
||||
return [...new Set(["UTC", ...Intl.supportedValuesOf("timeZone"), value].filter(Boolean))]
|
||||
.sort().map((zone) => {
|
||||
try {
|
||||
const name = new Intl.DateTimeFormat(i18n.language, { timeZone: zone, timeZoneName: "longGeneric" })
|
||||
.formatToParts(now).find((part) => part.type === "timeZoneName")?.value ?? zone;
|
||||
const offset = new Intl.DateTimeFormat("en", { timeZone: zone, timeZoneName: "longOffset" })
|
||||
.formatToParts(now).find((part) => part.type === "timeZoneName")?.value ?? "";
|
||||
return { zone, detail: `${name} · ${offset.replace("GMT", "UTC")}` };
|
||||
} catch {
|
||||
// Keep a server-supported timezone visible even if this browser cannot format it.
|
||||
return { zone, detail: zone };
|
||||
}
|
||||
});
|
||||
}, [i18n.language, value]);
|
||||
const filtered = options.filter(({ zone, detail }) =>
|
||||
`${zone.replaceAll("_", " ")} ${zone} ${detail}`.toLocaleLowerCase(i18n.language)
|
||||
.includes(query.trim().toLocaleLowerCase(i18n.language)));
|
||||
const select = (zone: string) => { onChange(zone); setOpen(false); };
|
||||
const navigation = useComboboxNavigation({
|
||||
open, values: filtered.map(({ zone }) => zone), selectedValue: value,
|
||||
onSelect: select, onClose: () => setOpen(false),
|
||||
});
|
||||
return (
|
||||
<Popover open={open} onOpenChange={(next) => { setOpen(next); setQuery(""); }}>
|
||||
<PopoverTrigger asChild>
|
||||
<Button {...triggerProps} type="button" variant="outline"
|
||||
className="h-9 w-full justify-between rounded-full border-input bg-background px-3 text-[13px] font-normal shadow-none">
|
||||
<span className="truncate">{value}</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-80 max-w-[calc(100vw-2rem)] p-1.5">
|
||||
<Input {...navigation.inputProps} value={query} onChange={(event) => setQuery(event.target.value)}
|
||||
aria-label={t("sidebar.searchAria")} placeholder={t("sidebar.searchPlaceholder")}
|
||||
className="mb-1.5 h-9 rounded-full" />
|
||||
<div {...navigation.listProps} aria-label={triggerProps["aria-label"]} className="max-h-64 overflow-y-auto">
|
||||
{filtered.map(({ zone, detail }) => (
|
||||
<ComboboxOption key={zone} {...navigation.getOptionProps(zone)} className="block">
|
||||
<span className="block">{zone}</span>
|
||||
<span className="block text-xs text-muted-foreground">{detail}</span>
|
||||
</ComboboxOption>
|
||||
))}
|
||||
</div>
|
||||
{!filtered.length ? <p role="status" className="p-2 text-xs text-muted-foreground">{t("settings.timezoneNoMatches")}</p> : null}
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
|
||||
/** Save a valid draft once per edit; failures wait for another edit or explicit retry. */
|
||||
export function useAutoSave(value: unknown, dirty: boolean, saving: boolean, onSave: () => void, enabled = true) {
|
||||
const latest = useRef(onSave);
|
||||
latest.current = onSave;
|
||||
const attempted = useRef<string | null>(null);
|
||||
const signature = JSON.stringify(value);
|
||||
useEffect(() => {
|
||||
if (!dirty) { attempted.current = null; return; }
|
||||
if (!enabled || saving || attempted.current === signature) return;
|
||||
const timer = window.setTimeout(() => {
|
||||
attempted.current = signature;
|
||||
latest.current();
|
||||
}, 600);
|
||||
return () => window.clearTimeout(timer);
|
||||
}, [signature, dirty, saving, enabled]);
|
||||
}
|
||||
Reference in new issue
Block a user