From f80be658ea08cfe5945af23ada52b166d48e9a9b Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Mon, 30 Nov 2026 15:01:45 +0800 Subject: [PATCH] fix(run-targets): apply a published ports edit that hasn't left the field (#6966) Published ports and the other list fields of a run target were stored only on blur, so OK pressed with Enter, or applying the settings while the field still had focus, dropped the edit. The list is now staged on every change; the text stays as typed while the field has focus. --- .../__tests__/runTargetsSwitchDraft.test.tsx | 21 +++++++++++++------ .../settings/pages/RunTargetsBody.tsx | 11 +++++----- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/features/settings/__tests__/runTargetsSwitchDraft.test.tsx b/src/features/settings/__tests__/runTargetsSwitchDraft.test.tsx index 7dd05b203b..7ce3eed51d 100644 --- a/src/features/settings/__tests__/runTargetsSwitchDraft.test.tsx +++ b/src/features/settings/__tests__/runTargetsSwitchDraft.test.tsx @@ -43,17 +43,26 @@ afterEach(() => { }); describe("Run Targets detail form", () => { - it("does not commit an uncommitted ports edit to the target selected while it is open", () => { + it("keeps a ports edit with the target it was made to when another target is selected", () => { mount(); - // An edit to odoo110's published ports that ListField has not committed yet. + // An edit to odoo110's published ports, still focused. fireEvent.change(portsBox(), { target: { value: "8069" } }); - // Selecting another target switches selection on mousedown, before the blur commits. + // Selecting another target switches selection on mousedown, before the field loses focus. fireEvent.mouseDown(screen.getByRole("option", { name: /odoo170/ })); fireEvent.blur(portsBox()); - // odoo170 keeps its own ports; the uncommitted draft is not written over them. + // odoo170 keeps its own ports; the edit is not written over them. expect(portsBox().value).toBe("9000:9000"); - // And odoo110 still holds what it held before the edit was committed anywhere. + // And odoo110 holds the edit. fireEvent.mouseDown(screen.getByRole("option", { name: /odoo110/ })); - expect(portsBox().value).toBe("8069:8069"); + expect(portsBox().value).toBe("8069"); + }); + + it("stages a ports edit before the field loses focus, so OK applies it", () => { + mount(); + fireEvent.change(portsBox(), { target: { value: "8069:8069 8070:8070" } }); + expect(portsBox().value).toBe("8069:8069 8070:8070"); + const change = Object.values(useSettingsDialog.getState().staged).find((c) => c.key === "runTargets"); + const targets = change?.value as Array<{ id: string; ports: string[] }> | undefined; + expect(targets?.find((t) => t.id === "odoo110")?.ports).toEqual(["8069:8069", "8070:8070"]); }); }); diff --git a/src/features/settings/pages/RunTargetsBody.tsx b/src/features/settings/pages/RunTargetsBody.tsx index ae88bfc93a..dc2e31c26c 100644 --- a/src/features/settings/pages/RunTargetsBody.tsx +++ b/src/features/settings/pages/RunTargetsBody.tsx @@ -263,7 +263,8 @@ function ListField({ hint?: string; }) { const id = useId(); - // Edited as text; the list is stored once the field loses focus. + // Edited as text, which stays as typed while the field has focus; the list is stored on every change, so OK + // (Enter included) applies an edit that hasn't left the field. const [draft, setDraft] = useState(null); return ( @@ -273,11 +274,11 @@ function ListField({ className={styles.wide} value={draft ?? value.join(" ")} placeholder={placeholder} - onChange={(e) => setDraft(e.target.value)} - onBlur={() => { - if (draft !== null) onChange(splitList(draft)); - setDraft(null); + onChange={(e) => { + setDraft(e.target.value); + onChange(splitList(e.target.value)); }} + onBlur={() => setDraft(null)} /> );