Skip to content

World's first open-source enterprise world model.

Preserve the schedule while its time input is incomplete (#1168)

Rudy Mizrahi Celekli35ac130bc3d7
diff --git a/web/src/pages/Library.tsx b/web/src/pages/Library.tsx
index c5d7f838..31d815f5 100644
--- a/web/src/pages/Library.tsx
+++ b/web/src/pages/Library.tsx
@@ -145,7 +145,7 @@ export function SchedulePicker({
const t = v.time ?? time;
const [hh, mm] = t.split(":").map(Number);
// 时间格式未成形时(手输中途)不更新日程,保留上一个有效值
- if ((m === "daily" || m === "weekly") && (Number.isNaN(hh) || Number.isNaN(mm))) return;
+ if ((m === "daily" || m === "weekly") && !/^([01]?\d|2[0-3]):[0-5]\d$/.test(t)) return;
switch (m) {
case "manual":
return onChange({ sync_interval_minutes: null, sync_cron: null });
diff --git a/web/src/pages/scheduleIncompleteTime.test.ts b/web/src/pages/scheduleIncompleteTime.test.ts
new file mode 100644
index 00000000..a7552236
--- /dev/null
+++ b/web/src/pages/scheduleIncompleteTime.test.ts
@@ -0,0 +1,24 @@
+import { Children, isValidElement, type ReactNode } from "react";
+import { expect, it, vi } from "vitest";
+const state = vi.hoisted(() => ({ time: "09:" }));
+vi.mock("react", async (original) => ({ ...(await original<typeof import("react")>()), useState: (initial: unknown) => [initial === "09:00" ? state.time : typeof initial === "function" ? initial() : initial, vi.fn()] }));
+import { SchedulePicker } from "./Library";
+type Props = { children?: ReactNode; onClick?: () => void };
+function dayButton(node: ReactNode): Props | undefined {
+ if (!isValidElement<Props>(node)) return;
+ if (node.props.children === "Tue") return node.props;
+ return Children.toArray(node.props.children).map(dayButton).find(Boolean);
+}
+it.each(["09:", "25:00", ""])("does not emit a day change while the time is %s", (time) => {
+ state.time = time;
+ const onChange = vi.fn();
+ const button = dayButton(SchedulePicker({ initial: { sync_cron: "0 9 * * Mon", sync_interval_minutes: null }, onChange }));
+ button!.onClick!();
+ expect(onChange).not.toHaveBeenCalled();
+});
+it("still emits a valid time when weekdays change", () => {
+ state.time = "09:00";
+ const onChange = vi.fn();
+ dayButton(SchedulePicker({ initial: { sync_cron: "0 9 * * Mon", sync_interval_minutes: null }, onChange }))!.onClick!();
+ expect(onChange).toHaveBeenCalledWith({ sync_cron: "0 9 * * Mon,Tue", sync_interval_minutes: null });
+});