дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 17:21:13 +02:00
fix(settings): keep an uncommitted Run Targets field edit off the next target (#5900)
The run target list switches selection on mousedown, before the Published ports / Compose files field's blur commits its draft, so the commit closure already saw the newly selected target and wrote the edit onto it. The Target Settings form is now keyed by target id, so switching targets remounts it and drops the uncommitted draft. Fixes #5872 Co-authored-by: Inf1mum <[email protected]>
Цей коміт міститься в:
1 джерело
7c3b9824e6
коміт
54a7962043
2 files changed
+62
-1
No files matched your search
@@ -0,0 +1,59 @@
|
||||
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("@/platform/ipc", async (importOriginal) => {
|
||||
const real = await importOriginal<typeof import("@/platform/ipc")>();
|
||||
return { ...real, isTauri: () => false };
|
||||
});
|
||||
|
||||
const { PageContext } = await import("../components/context");
|
||||
const { RunTargetsEditor } = await import("../pages/RunTargetsBody");
|
||||
const { useSettingsDialog } = await import("../model/staging");
|
||||
const { DEFAULT_SETTINGS } = await import("../model/schema");
|
||||
const { DEFAULT_RUN_TARGET } = await import("@/platform/remoteSettings");
|
||||
|
||||
const TARGETS = [
|
||||
{ ...DEFAULT_RUN_TARGET, kind: "compose" as const, id: "odoo110", name: "odoo110", ports: ["8069:8069"] },
|
||||
{ ...DEFAULT_RUN_TARGET, kind: "compose" as const, id: "odoo170", name: "odoo170", ports: ["9000:9000"] },
|
||||
];
|
||||
|
||||
function mount() {
|
||||
const settings = structuredClone(DEFAULT_SETTINGS) as typeof DEFAULT_SETTINGS & Record<string, unknown>;
|
||||
settings.runTargets = TARGETS;
|
||||
useSettingsDialog.setState({
|
||||
base: structuredClone(settings),
|
||||
globalBase: settings,
|
||||
staged: {},
|
||||
query: "",
|
||||
});
|
||||
render(
|
||||
<PageContext.Provider value={{ pageId: "build.runTargets", scope: "global" }}>
|
||||
<RunTargetsEditor />
|
||||
</PageContext.Provider>,
|
||||
);
|
||||
}
|
||||
|
||||
const portsBox = () => screen.getByRole("textbox", { name: "Published ports" }) as HTMLInputElement;
|
||||
|
||||
beforeEach(() => {
|
||||
Object.assign(window, { __TAURI_INTERNALS__: { transformCallback: () => 1 } });
|
||||
});
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
describe("Run Targets detail form", () => {
|
||||
it("does not commit an uncommitted ports edit to the target selected while it is open", () => {
|
||||
mount();
|
||||
// An edit to odoo110's published ports that ListField has not committed yet.
|
||||
fireEvent.change(portsBox(), { target: { value: "8069" } });
|
||||
// Selecting another target switches selection on mousedown, before the blur commits.
|
||||
fireEvent.mouseDown(screen.getByRole("option", { name: /odoo170/ }));
|
||||
fireEvent.blur(portsBox());
|
||||
// odoo170 keeps its own ports; the uncommitted draft is not written over them.
|
||||
expect(portsBox().value).toBe("9000:9000");
|
||||
// And odoo110 still holds what it held before the edit was committed anywhere.
|
||||
fireEvent.mouseDown(screen.getByRole("option", { name: /odoo110/ }));
|
||||
expect(portsBox().value).toBe("8069:8069");
|
||||
});
|
||||
});
|
||||
@@ -516,7 +516,9 @@ export function RunTargetsEditor() {
|
||||
</Row>
|
||||
</Section>
|
||||
{current && (
|
||||
<Section title="Target Settings">
|
||||
// Keyed by target id: switching targets remounts the form and drops any
|
||||
// uncommitted ListField draft instead of committing it to the new target.
|
||||
<Section title="Target Settings" key={current.id}>
|
||||
<TextField label="Name" value={current.name} onChange={(name) => update({ name })} />
|
||||
<Row label="Type" className={styles.alignedRow}>
|
||||
<Select
|
||||
|
||||
Reference in new issue
Заблокувати користувача