From 7f0f088698f67519f729fc1cd22cc0572e00176c Mon Sep 17 00:00:00 2001 From: "Hyeonjae.Jeong" Date: Wed, 11 Nov 2026 16:22:07 +0900 Subject: [PATCH] fix(desktop): keep IME confirmation from submitting question answers --- .../QuestionForm/QuestionForm.test.tsx | 58 +++++++++++++++++++ .../components/QuestionPage/QuestionPage.tsx | 3 +- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/ApprovalRow/components/QuestionForm/QuestionForm.test.tsx diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/ApprovalRow/components/QuestionForm/QuestionForm.test.tsx b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/ApprovalRow/components/QuestionForm/QuestionForm.test.tsx new file mode 100644 index 00000000000..7d3427df2a5 --- /dev/null +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/ApprovalRow/components/QuestionForm/QuestionForm.test.tsx @@ -0,0 +1,58 @@ +import { afterAll, afterEach, expect, mock, test } from "bun:test"; +import type { ApprovalRequest } from "@superset/chat/protocol"; + +const reactActGlobal = globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }; +const previousActEnvironment = reactActGlobal.IS_REACT_ACT_ENVIRONMENT; +reactActGlobal.IS_REACT_ACT_ENVIRONMENT = true; +const { cleanup, fireEvent, render } = await import("@testing-library/react"); +const { QuestionForm } = await import("./QuestionForm"); + +afterEach(cleanup); +afterAll(() => { + reactActGlobal.IS_REACT_ACT_ENVIRONMENT = previousActEnvironment; +}); + +const form: NonNullable = { + message: "Pick an answer", + fields: [ + { + id: "choice", + input: "single", + required: true, + options: [{ value: "sample", label: "Sample" }], + }, + { id: "choice_custom", input: "text", title: "Other" }, + ], +}; +const item: ApprovalRequest = { + id: "question", + startedAtMs: 0, + kind: "approval_request", + targetItemId: null, + title: "Question", + status: "pending", + form, +}; + +test.each([ + { isComposing: true, keyCode: 13 }, + { isComposing: false, keyCode: 229 }, +])("keeps IME confirmation in Other without submitting (%j)", (ime) => { + const onRespond = mock(() => {}); + const view = render( + , + ); + const input = view.getByRole("textbox", { name: "Other" }); + fireEvent.compositionStart(input); + fireEvent.change(input, { target: { value: "각" } }); + fireEvent.keyDown(input, { key: "Enter", ...ime }); + expect(onRespond).not.toHaveBeenCalled(); + expect((input as HTMLInputElement).value).toBe("각"); + fireEvent.compositionEnd(input, { data: "각" }); + fireEvent.keyDown(input, { key: "Enter", isComposing: false, keyCode: 13 }); + expect(onRespond).toHaveBeenCalledTimes(1); + expect(onRespond).toHaveBeenCalledWith("question", { + type: "form", + values: { choice_custom: "각" }, + }); +}); diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/ApprovalRow/components/QuestionForm/components/QuestionPage/QuestionPage.tsx b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/ApprovalRow/components/QuestionForm/components/QuestionPage/QuestionPage.tsx index 8f6286ed64d..1231cd5b7af 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/ApprovalRow/components/QuestionForm/components/QuestionPage/QuestionPage.tsx +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/ApprovalRow/components/QuestionForm/components/QuestionPage/QuestionPage.tsx @@ -1,5 +1,6 @@ import { Trans, useLingui } from "@lingui/react/macro"; import type { FormField } from "@superset/chat/protocol"; +import { isImeComposing } from "@superset/ui/lib/keyboard"; import { cn } from "@superset/ui/utils"; import { Check, PencilLine } from "lucide-react"; import { @@ -125,7 +126,7 @@ export function QuestionPage({ onChange={(event) => onType(textField.id, event.target.value)} onKeyDown={(event) => { event.stopPropagation(); - if (event.key === "Enter") onEnter(); + if (event.key === "Enter" && !isImeComposing(event)) onEnter(); }} placeholder={ field.input === "integer"