Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai 5451d9fa9f fix(run-targets): apply a published ports edit that hasn't left the field
Published ports and the other list fields of a run target were stored only when the field lost focus, so OK pressed with Enter, or anything that applied 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.
2026-11-30 15:01:14 +08:00
2 змінених файлів з 21 додано та 11 видалено

No files matched your search

+15 -6
Переглянути файл
@@ -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"]);
});
});
+6 -5
Переглянути файл
@@ -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<string | null>(null);
return (
<Row label={label} htmlFor={id} className={styles.alignedRow} hint={hint}>
@@ -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)}
/>
</Row>
);