From e7da8685743851348a412fe0f9a4ec39334d058a Mon Sep 17 00:00:00 2001 From: chengyongru <2755839590@qq.com> Date: Sun, 13 Sep 2026 03:38:39 +0800 Subject: [PATCH] feat(webui): refine automation views and scheduling controls --- webui/src/App.tsx | 1 + .../src/components/settings/SettingsPage.tsx | 5 +- .../src/components/settings/SettingsView.tsx | 3 + .../settings/system/AutomationCalendar.tsx | 83 +--- .../settings/system/AutomationRunAtPicker.tsx | 196 +++++++++ .../settings/system/AutomationsSettings.tsx | 408 ++++++++---------- .../src/components/thread/ThreadComposer.tsx | 25 +- webui/src/globals.css | 139 +++--- webui/src/i18n/locales/en/common.json | 27 +- webui/src/i18n/locales/es/common.json | 27 +- webui/src/i18n/locales/fr/common.json | 27 +- webui/src/i18n/locales/id/common.json | 27 +- webui/src/i18n/locales/ja/common.json | 27 +- webui/src/i18n/locales/ko/common.json | 27 +- webui/src/i18n/locales/pt-BR/common.json | 27 +- webui/src/i18n/locales/vi/common.json | 27 +- webui/src/i18n/locales/zh-CN/common.json | 27 +- webui/src/i18n/locales/zh-TW/common.json | 27 +- .../tests/automation-run-at-picker.test.tsx | 133 ++++++ webui/src/tests/automations-settings.test.tsx | 406 ++++++++++------- webui/src/tests/session-info-popover.test.tsx | 6 +- webui/src/tests/settings-system.test.tsx | 55 ++- webui/src/tests/settings-test-utils.tsx | 2 + 23 files changed, 1131 insertions(+), 601 deletions(-) create mode 100644 webui/src/components/settings/system/AutomationRunAtPicker.tsx create mode 100644 webui/src/tests/automation-run-at-picker.test.tsx diff --git a/webui/src/App.tsx b/webui/src/App.tsx index a98704fee..fd398e63f 100644 --- a/webui/src/App.tsx +++ b/webui/src/App.tsx @@ -2880,6 +2880,7 @@ function Shell({ initialSection={settingsInitialSection} initialSettings={settingsSnapshot} showSidebar={view === "settings"} + mainNavigationExpanded={showMainSidebar && hostSidebarOpen} onToggleTheme={toggle} onBackToChat={onBackToChat} onModelNameChange={onModelNameChange} diff --git a/webui/src/components/settings/SettingsPage.tsx b/webui/src/components/settings/SettingsPage.tsx index 2be379df4..3dd9f3eec 100644 --- a/webui/src/components/settings/SettingsPage.tsx +++ b/webui/src/components/settings/SettingsPage.tsx @@ -49,6 +49,7 @@ interface SettingsPageProps { controller: SettingsController; theme: "light" | "dark"; showSidebar: boolean; + mainNavigationExpanded: boolean; onToggleTheme: () => void; onBackToChat: () => void; skills: SkillSummary[]; @@ -69,6 +70,7 @@ export function SettingsPage({ controller, theme, showSidebar, + mainNavigationExpanded, onToggleTheme, onBackToChat, skills, @@ -734,6 +736,7 @@ export function SettingsPage({ data-testid="settings-section-transition" ref={setDialogLayoutAnchor} data-settings-section={activeSection} + data-main-navigation-expanded={mainNavigationExpanded} className={cn( "mx-auto w-full animate-in fade-in-0 slide-in-from-bottom-1 py-6 duration-200 ease-out", "motion-reduce:animate-none sm:py-8 lg:py-12", @@ -744,7 +747,7 @@ export function SettingsPage({ )} > {!showSidebar ? ( -
+
- - -
-
- {wideCalendar ?
{weekdayLabels.map((label) =>
{label}
)}
: null} @@ -396,21 +342,6 @@ export function AutomationCalendar({ jobs, locale, copy, filters, onInspect }: A )} : null} - {jobs.length ? ( -
- - - - - {copy.planned} - - - {copy.recorded} - - -
- ) : null} - ); } diff --git a/webui/src/components/settings/system/AutomationRunAtPicker.tsx b/webui/src/components/settings/system/AutomationRunAtPicker.tsx new file mode 100644 index 000000000..7fbb7f048 --- /dev/null +++ b/webui/src/components/settings/system/AutomationRunAtPicker.tsx @@ -0,0 +1,196 @@ +import { CalendarDays, ChevronLeft, ChevronRight, Clock3 } from "lucide-react"; +import { useId, useLayoutEffect, useRef, useState, type KeyboardEvent } from "react"; +import { useTranslation } from "react-i18next"; + +import { Button } from "@/components/ui/button"; +import { formControlFocusClassName } from "@/components/ui/form-control"; +import { Input } from "@/components/ui/input"; +import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; +import { cn } from "@/lib/utils"; + +function dateKey(date: Date): string { + return `${String(date.getFullYear()).padStart(4, "0")}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`; +} + +function localDay(year: number, month: number, day: number): Date { + const date = new Date(0); + date.setHours(12, 0, 0, 0); + date.setFullYear(year, month, day); + return date; +} + +function parseDay(value: string): Date | null { + if (!/^\d{4}-\d{2}-\d{2}$/.test(value)) return null; + const [year, month, day] = value.split("-").map(Number); + const date = localDay(year, month - 1, day); + return year > 0 && dateKey(date) === value ? date : null; +} + +export function parseAutomationRunAt(value: string): Date | null { + const [day, time, extra] = value.split("T"); + const date = parseDay(day); + if (!date || extra !== undefined || !/^([01]\d|2[0-3]):[0-5]\d$/.test(time ?? "")) return null; + const [hour, minute] = time.split(":").map(Number); + date.setHours(hour, minute, 0, 0); + // Reject impossible dates and local times instead of silently rolling forward. + return dateKey(date) === day && date.getHours() === hour && date.getMinutes() === minute ? date : null; +} + +function moveMonth(date: Date, amount: number): Date { + const month = localDay(date.getFullYear(), date.getMonth() + amount, 1); + const lastDay = localDay(month.getFullYear(), month.getMonth() + 1, 0).getDate(); + month.setDate(Math.min(date.getDate(), lastDay)); + return month; +} + +export function AutomationRunAtPicker({ value, onChange, disabled = false, errorId }: { + value: string; + onChange: (value: string) => void; + disabled?: boolean; + errorId?: string; +}) { + const { t, i18n } = useTranslation(); + const locale = i18n.resolvedLanguage || i18n.language; + const id = useId(); + const [open, setOpen] = useState(false); + const [focusedDay, setFocusedDay] = useState(() => parseDay(value.split("T")[0]) ?? new Date()); + const activeDay = useRef(null); + const restoreGridFocus = useRef(false); + const [dateValue, timeValue = ""] = value.split("T"); + const month = localDay(focusedDay.getFullYear(), focusedDay.getMonth(), 1); + const weekStart = (month.getDay() + 6) % 7; + const monthLabel = new Intl.DateTimeFormat(locale, { year: "numeric", month: "long" }).format(month); + const dayFormatter = new Intl.DateTimeFormat(locale, { dateStyle: "full" }); + const weekdays = Array.from({ length: 7 }, (_, index) => localDay(2026, 0, 5 + index)); + const todayKey = dateKey(new Date()); + + useLayoutEffect(() => { + if (restoreGridFocus.current) { + activeDay.current?.focus({ preventScroll: true }); + restoreGridFocus.current = false; + } + }, [focusedDay]); + + const navigate = (next: Date, focus = false) => { + if (next.getFullYear() < 1 || next.getFullYear() > 9999) return; + restoreGridFocus.current = focus; + setFocusedDay(next); + }; + const selectDay = (day: Date) => { + onChange(`${dateKey(day)}T${timeValue}`); + setOpen(false); + }; + const onDayKeyDown = (event: KeyboardEvent, day: Date) => { + const next = new Date(day); + const weekday = (day.getDay() + 6) % 7; + const rtl = i18n.dir(locale) === "rtl"; + switch (event.key) { + case "ArrowLeft": next.setDate(day.getDate() + (rtl ? 1 : -1)); break; + case "ArrowRight": next.setDate(day.getDate() + (rtl ? -1 : 1)); break; + case "ArrowUp": next.setDate(day.getDate() - 7); break; + case "ArrowDown": next.setDate(day.getDate() + 7); break; + case "Home": next.setDate(day.getDate() - weekday); break; + case "End": next.setDate(day.getDate() + 6 - weekday); break; + case "PageUp": case "PageDown": + event.preventDefault(); + navigate(moveMonth(day, (event.key === "PageUp" ? -1 : 1) * (event.shiftKey ? 12 : 1)), true); + return; + default: return; + } + event.preventDefault(); + navigate(next, true); + }; + + return ( +
+ {t("settings.automations.fields.runAt")} +
+
+ + onChange(`${event.target.value}T${timeValue}`)} /> + { + setOpen(next); + if (next) setFocusedDay(parseDay(dateValue) ?? new Date()); + }}> + + + + { + event.preventDefault(); + setOpen(false); + }} + onOpenAutoFocus={(event) => { event.preventDefault(); activeDay.current?.focus({ preventScroll: true }); }}> +
+ {monthLabel} + + +
+ + {weekdays.map((day) => ( + + ))} + {Array.from({ length: 6 }, (_, week) => ( + {Array.from({ length: 7 }, (_, column) => { + const day = localDay(month.getFullYear(), month.getMonth(), 1 - weekStart + week * 7 + column); + const key = dateKey(day); + const selected = key === dateValue; + const focused = key === dateKey(focusedDay); + return ; + })} + ))} +
+ {new Intl.DateTimeFormat(locale, { weekday: "short" }).format(day)} +
+ +
+ +
+
+
+
+ + + onChange(`${dateValue}T${event.target.value}`)} /> +
+
+
+ ); +} diff --git a/webui/src/components/settings/system/AutomationsSettings.tsx b/webui/src/components/settings/system/AutomationsSettings.tsx index e27288c31..8d61b976f 100644 --- a/webui/src/components/settings/system/AutomationsSettings.tsx +++ b/webui/src/components/settings/system/AutomationsSettings.tsx @@ -6,6 +6,7 @@ import { ChevronDown, CircleAlert, Clipboard, + ListFilter, Loader2, } from "lucide-react"; import { useTranslation } from "react-i18next"; @@ -13,14 +14,15 @@ import { useTranslation } from "react-i18next"; import { channelTranslator } from "@/channel-plugins/i18n"; import { channelUiOwner, channelUiPresentation } from "@/channel-plugins/registry"; import { AutomationCalendar } from "@/components/settings/system/AutomationCalendar"; -import { SettingsGroup } from "@/components/settings/shared/SettingsControls"; +import { AutomationRunAtPicker, parseAutomationRunAt } from "@/components/settings/system/AutomationRunAtPicker"; import { modelPresetOptionsFromSettings, toModelBadgeInfo, } from "@/components/thread/model-preset"; import { ThreadComposer } from "@/components/thread/ThreadComposer"; import { Button } from "@/components/ui/button"; -import { Disclosure, DisclosureContent } from "@/components/ui/disclosure"; +import { Disclosure } from "@/components/ui/disclosure"; +import { DropdownMenu, DropdownMenuContent, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"; import { ExpandableText } from "@/components/ui/expandable-text"; import { Dialog, @@ -50,7 +52,6 @@ export type AutomationFilter = "all" | "active" | "paused" | "failed" | "system" export type AutomationAction = "enable" | "disable" | "delete" | "run"; const EMPTY_TITLE_OVERRIDES: Record = {}; -const SYSTEM_TASKS_OPEN_STORAGE_KEY = "nanobot-webui.automation-system-tasks-open"; export function AutomationsSettings({ payload, loading, filter, actionKey, error, @@ -97,35 +98,28 @@ export function AutomationsSettings({ const [inspectedJob, setInspectedJob] = useState(null); const [detailOpen, setDetailOpen] = useState(false); const [localModelPreset, setLocalModelPreset] = useState(null); - const [systemOpen, setSystemOpen] = useState(() => { - try { - return window.localStorage.getItem(SYSTEM_TASKS_OPEN_STORAGE_KEY) !== "false"; - } catch { - return true; - } + const [view, setView] = useState<"tasks" | "calendar">("calendar"); + const [month, setMonth] = useState(() => { + const today = new Date(); + return new Date(today.getFullYear(), today.getMonth(), 1); }); const pageTitle = useRef(null); const selectedTrigger = useRef(null); const afterDetailClose = useRef<((job: SessionAutomationJob) => void) | null>(null); - const filtered = useMemo(() => { - return jobs - .filter((job) => automationMatchesFilter(job, filter)); - }, [filter, jobs]); - const personalJobs = jobs.filter((job) => !job.protected); - const personal = filtered.filter((job) => !job.protected); - const system = filtered.filter((job) => job.protected); + const visibleJobs = useMemo(() => jobs.filter((job) => !job.protected), [jobs]); + const filtered = useMemo(() => visibleJobs.filter((job) => automationMatchesFilter(job, filter)), [filter, visibleJobs]); // Keep an inspected task open when an action moves it outside the current filter. const liveSelectedJob = jobs.find((job) => job.id === inspectedJob?.id); // Retain the last detail through its exit, even if a one-shot task disappears. const selectedJob = liveSelectedJob ?? inspectedJob; const summaryOptions: Array<{ value: AutomationFilter; label: string; count: number }> = [ - { value: "all", label: tx("settings.automations.filters.all", "All"), count: personalJobs.length }, + { value: "all", label: tx("settings.automations.filters.all", "All"), count: visibleJobs.length }, { value: "active", label: tx("settings.automations.filters.active", "Active"), - count: personalJobs.filter((job) => automationMatchesFilter(job, "active")).length }, - { value: "paused", label: tx("settings.automations.filters.paused", "Paused"), - count: personalJobs.filter((job) => automationMatchesFilter(job, "paused")).length }, + count: visibleJobs.filter((job) => automationMatchesFilter(job, "active")).length }, + { value: "paused", label: tx("settings.automations.filters.paused", "Disabled"), + count: visibleJobs.filter((job) => automationMatchesFilter(job, "paused")).length }, { value: "failed", label: tx("settings.automations.filters.failed", "Needs attention"), - count: personalJobs.filter(automationNeedsAttention).length }, + count: visibleJobs.filter(automationNeedsAttention).length }, ]; const configuredPresetNames = useMemo( () => new Set(settingsSnapshot?.model_presets?.map((preset) => preset.name) ?? []), @@ -163,19 +157,6 @@ export function AutomationsSettings({ onReturnToDetailHandled?.(); }, [jobs, onReturnToDetailHandled, returnToDetailJob]); - const renderJob = (job: SessionAutomationJob) => ( - { - selectedTrigger.current = button; - setInspectedJob(job); - setDetailOpen(true); - }} - /> - ); const inspectJob = (job: SessionAutomationJob, trigger: HTMLElement) => { selectedTrigger.current = trigger; setInspectedJob(job); @@ -201,10 +182,37 @@ export function AutomationsSettings({ options, activeModelPreset, ); + const filterLabel = filter === "all" ? tx("settings.automations.filter", "Filter") : tx("settings.automations.filteredBy", "Filter: {{status}}", { + status: summaryOptions.find((option) => option.value === filter)?.label, + }); + const filters = visibleJobs.length ? ( + + + + + + { + const option = summaryOptions.find((item) => item.value === value); + if (option) onFilterChange(option.value); + }}> + {summaryOptions.map((option) => ( + + {option.label} + {option.count} + + ))} + + + + ) : null; return (
-
+

{tx("settings.nav.automations", "Automations")}

@@ -221,7 +229,7 @@ export function AutomationsSettings({ inputAriaLabel={tx("settings.automations.createInput", "Describe an automation")} placeholder={tx( "settings.automations.createPrompt", - "What would you like nanobot to schedule?", + "What would you like nanobot to automate?", )} variant="thread" compactWhenIdle @@ -240,89 +248,115 @@ export function AutomationsSettings({ ) : null} {error ? : null} - {loading && !payload ? ( -
- - {tx("settings.automations.loading", "Loading automations...")} -
- ) : ( - - ({ - value: option.value, - label: <>{option.label} {option.count}, - }))} - onChange={onFilterChange} - /> +
+
+
+ +
+ {view === "calendar" ? ( +

+ {new Intl.DateTimeFormat(locale, { month: "long", year: "numeric" }).format(month)} +

+ ) : null} + {filters ?
{filters}
: null} + {view === "calendar" ? ( +
+ + +
) : null} - copy={{ - previousMonth: tx("settings.automations.calendar.previousMonth", "Previous month"), - nextMonth: tx("settings.automations.calendar.nextMonth", "Next month"), - today: tx("settings.automations.calendar.today", "Today"), - planned: tx("settings.automations.calendar.planned", "Planned"), - recorded: tx("settings.automations.calendar.recorded", "Recorded"), - running: tx("settings.automations.status.running", "Running"), - failed: tx("settings.automations.status.failed", "Failed"), - more: (count) => tx("settings.automations.calendar.more", "+{{count}} more", { count }), - close: tx("common.close", "Close"), - noEntries: personal.length - ? tx("settings.automations.calendar.noEntries", "No runs in this month.") - : personalJobs.length - ? tx("settings.automations.noMatches", "No automations match this view.") - : tx("settings.automations.empty", "No automations yet."), - completed: tx("settings.automations.status.completed", "Completed"), - }} - onInspect={inspectJob} - /> - )} - - {system.length ? ( - -
- - -
    - {system.map(renderJob)} +
+ {loading && !payload ? ( +
+ + {tx("settings.automations.loading", "Loading automations...")} +
+ ) : view === "tasks" ? ( +
+ {filtered.length ? ( +
    + {filtered.map((job) => { + const status = automationStatusKey(job); + const emphasizedStatus = status === "running" || status === "failed" || status === "paused"; + return ( +
  • + +
  • + ); + })}
- + ) : ( +

+ {visibleJobs.length ? tx("settings.automations.noMatches", "No automations match this view.") : tx("settings.automations.empty", "No automations yet.")} +

+ )}
- - ) : null} + ) : ( + tx("settings.automations.calendar.more", "+{{count}} more", { count }), + close: tx("common.close", "Close"), + system: tx("settings.automations.filters.system", "System"), + noEntries: filtered.length + ? tx("settings.automations.calendar.noEntries", "No runs in this month.") + : visibleJobs.length + ? tx("settings.automations.noMatches", "No automations match this view.") + : tx("settings.automations.empty", "No automations yet."), + completed: tx("settings.automations.status.completed", "Completed"), + }} + onInspect={inspectJob} + /> + )} +
+
void; -}) { - const { t } = useTranslation(); - const tx = (key: string, fallback: string, values?: Record) => - t(key, { defaultValue: fallback, ...(values ?? {}) }); - const attention = automationNeedsAttention(job); - const compact = Boolean(job.protected); - const summary = job.state.last_error - ? localizedAutomationError(job.state.last_error, tx) - : compact ? null : automationSummary(job, tx); - const running = Boolean(job.state.pending); - return ( -
  • - -
  • - ); -} function AutomationDetailPanel({ job, locale, actionKey, error, onAction, onRequestEdit, onRequestDelete, @@ -464,7 +451,6 @@ function AutomationDetailPanel({ const { t } = useTranslation(); const tx = (key: string, fallback: string, values?: Record) => t(key, { defaultValue: fallback, ...(values ?? {}) }); - const origin = automationOriginLabel(job, t); const originHref = job.origin?.channel === "websocket" && job.origin.session_key ? `#/chat/${encodeURIComponent(job.origin.session_key)}` : null; const localTrigger = isLocalTriggerAutomation(job); @@ -494,12 +480,12 @@ function AutomationDetailPanel({ {canManage ? ( {formatAutomationSchedule(job, locale, tx)} - + {!localTrigger ? {tx("settings.automations.labels.next", "Next")} {formatAutomationNext(job, tx)} - + : null} ) : null} @@ -553,9 +539,9 @@ function AutomationDetailPanel({ : lastStatus || tx("settings.automations.neverRun", "Not run yet")} - {!job.protected ? ( + {!job.protected && job.origin?.channel && job.origin.channel !== "websocket" ? ( - {origin} + {automationChannelLabel(job.origin.channel, t)} ) : null} @@ -585,7 +571,7 @@ function AutomationDetailPanel({
    {!localTrigger ? (