World's first open-source enterprise world model.
Rust agent-memorybitemporalgraphragknowledge-baseknowledge-graphllmontologypgvectorpostgresqlragrustself-hostedsemantic-searchtemporal-knowledge-graphworld-model
Keep weekly cron weekday names independent of interface language (#1166)
Rudy Mizrahi Celeklif964f85caded
diff --git a/web/src/pages/Library.tsx b/web/src/pages/Library.tsxindex cb8a5085..c5d7f838 100644--- a/web/src/pages/Library.tsx+++ b/web/src/pages/Library.tsx@@ -79,7 +79,9 @@ function scheduleLabel(s: SourceView): string {type ScheduleMode = "manual" | "interval" | "daily" | "weekly" | "advanced";/** 已存日程 → 选择器初始状态(编辑模式回显;识别不了的 cron 落到 Advanced)。 */-function scheduleToPickerState(initial?: ScheduleValue) {+const CRON_WEEKDAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] as const;++export function scheduleToPickerState(initial?: ScheduleValue) {const base = {mode: "manual" as ScheduleMode,every: 30,@@ -97,7 +99,7 @@ function scheduleToPickerState(initial?: ScheduleValue) {if (weekly) {const idx = weekly[3].split(",")- .map((n) => (S.library.schedule.daysShort as readonly string[]).indexOf(n))+ .map((n) => (CRON_WEEKDAYS as readonly string[]).indexOf(n)).filter((i) => i >= 0);if (idx.length)return {@@ -119,7 +121,7 @@ function scheduleToPickerState(initial?: ScheduleValue) {}/** 可视化同步日程选择器:Manual / Interval / Daily / Weekly 构建,Advanced 才暴露 cron。 */-function SchedulePicker({+export function SchedulePicker({onChange,initial,}: {@@ -159,7 +161,7 @@ function SchedulePicker({return onChange({ sync_interval_minutes: null, sync_cron: `${mm} ${hh} * * *` });case "weekly": {const ds = [...(v.days ?? days)].sort();- const names = ds.map((i) => S.library.schedule.daysShort[i]).join(",");+ const names = ds.map((i) => CRON_WEEKDAYS[i]).join(",");return onChange({sync_interval_minutes: null,sync_cron: ds.length ? `${mm} ${hh} * * ${names}` : null,diff --git a/web/src/pages/weeklyScheduleLocale.test.ts b/web/src/pages/weeklyScheduleLocale.test.tsnew file mode 100644index 00000000..f624ff27--- /dev/null+++ b/web/src/pages/weeklyScheduleLocale.test.ts@@ -0,0 +1,24 @@+import { Children, isValidElement, type ReactNode } from "react";+import { expect, it, vi } from "vitest";+vi.mock("../i18n", async (original) => ({ ...(await original<typeof import("../i18n")>()), S: (await import("../i18n/zh")).zh }));+vi.mock("react", async (original) => ({ ...(await original<typeof import("react")>()), useState: (initial: unknown) => [typeof initial === "function" ? initial() : initial, vi.fn()] }));+import { SchedulePicker, scheduleToPickerState } from "./Library";+type Props = { children?: ReactNode; onClick?: () => void };+function dayButton(node: ReactNode): Props | undefined {+ if (!isValidElement<Props>(node)) return;+ if (node.props.children === "周二") return node.props;+ return Children.toArray(node.props.children).map(dayButton).find(Boolean);+}+it("reads English cron weekdays in a Chinese interface", () => {+ const state = scheduleToPickerState({ sync_cron: "0 9 * * Mon", sync_interval_minutes: null });+ expect(state.mode).toBe("weekly");+ expect([...state.days]).toEqual([0]);+});+it("emits cron weekday names independently of display labels", () => {+ const onChange = vi.fn();+ const tree = SchedulePicker({ initial: { sync_cron: "0 9 * * Mon", sync_interval_minutes: null }, onChange });+ const button = dayButton(tree);+ expect(button?.onClick).toBeTypeOf("function");+ button!.onClick!();+ expect(onChange).toHaveBeenCalledWith({ sync_cron: "0 9 * * Mon,Tue", sync_interval_minutes: null });+});