Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix(automations): start a Custom schedule from the preset it replaces (#18464)

Engel Nyst8b623be71f78
diff --git a/__tests__/components/automations/automation-setup-panel.test.tsx b/__tests__/components/automations/automation-setup-panel.test.tsx
index cb1fa14385..9887997af5 100644
--- a/__tests__/components/automations/automation-setup-panel.test.tsx
+++ b/__tests__/components/automations/automation-setup-panel.test.tsx
@@ -804,6 +804,38 @@ describe("AutomationSetupPanel", () => {
);
});
+ it("starts a Custom schedule from the preset it replaces", async () => {
+ const user = userEvent.setup();
+ renderPanel();
+
+ await user.click(screen.getByTestId("automation-setup-frequency-weekly"));
+ await user.selectOptions(
+ screen.getByTestId("automation-setup-weekday"),
+ "3",
+ );
+ fireEvent.change(screen.getByTestId("automation-setup-time"), {
+ target: { value: "10:30" },
+ });
+ await user.click(screen.getByTestId("automation-setup-frequency-custom"));
+
+ const custom = screen.getByTestId("automation-setup-custom-schedule");
+ expect(custom).toHaveValue("30 10 * * 3");
+
+ // Re-selecting Custom keeps what the user typed.
+ fireEvent.change(custom, { target: { value: "15 8 * * 1-5" } });
+ await user.click(screen.getByTestId("automation-setup-frequency-custom"));
+ expect(screen.getByTestId("automation-setup-custom-schedule")).toHaveValue(
+ "15 8 * * 1-5",
+ );
+
+ // Leaving for a preset and coming back starts from that preset again.
+ await user.click(screen.getByTestId("automation-setup-frequency-daily"));
+ await user.click(screen.getByTestId("automation-setup-frequency-custom"));
+ expect(screen.getByTestId("automation-setup-custom-schedule")).toHaveValue(
+ "30 10 * * *",
+ );
+ });
+
it("creates plugin drafts with the selected plugin source", async () => {
vi.mocked(AutomationService.createAutomationDraft).mockResolvedValue({
id: "automation-1",
diff --git a/src/components/features/automations/setup/automation-setup-panel.tsx b/src/components/features/automations/setup/automation-setup-panel.tsx
index 8af56138a7..15fff8e7e2 100644
--- a/src/components/features/automations/setup/automation-setup-panel.tsx
+++ b/src/components/features/automations/setup/automation-setup-panel.tsx
@@ -2102,6 +2102,19 @@ export function AutomationSetupPanel({
}}
streamingField={streamingField}
setFrequency={(value) => {
+ if (value === "custom" && frequency !== "custom") {
+ // Start Custom from the preset the user configured.
+ updateField(
+ "customSchedule",
+ toCron(
+ time,
+ frequency,
+ customSchedule,
+ scheduleDateTime || defaultScheduleDateTimeLocal(),
+ weekday,
+ ),
+ );
+ }
updateField("frequency", value);
if (value === "once" && !scheduleDateTime.trim()) {
updateField(