Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: sql editor ux (#20446)
ecmadao5ed035b5fa10
diff --git a/frontend/src/react/components/monaco/MonacoEditor.test.tsx b/frontend/src/react/components/monaco/MonacoEditor.test.tsxindex 46d77c32bb..6567d808d5 100644--- a/frontend/src/react/components/monaco/MonacoEditor.test.tsx+++ b/frontend/src/react/components/monaco/MonacoEditor.test.tsx@@ -21,6 +21,7 @@ const mocks = vi.hoisted(() => {getLanguageId: () => "sql",getValue: () => "select 1",getValueInRange: () => "",+ getAllDecorations: () => [],};const subscription = { dispose: vi.fn() };const editor = {diff --git a/frontend/src/react/components/monaco/MonacoEditor.tsx b/frontend/src/react/components/monaco/MonacoEditor.tsxindex d4f88e96c0..a1b38f49e9 100644--- a/frontend/src/react/components/monaco/MonacoEditor.tsx+++ b/frontend/src/react/components/monaco/MonacoEditor.tsx@@ -109,6 +109,11 @@ export interface MonacoEditorProps {formatContentOptions?: FormatContentOptions;}+// Marker class for the active-statement highlight. Used both to render the+// decoration and to identify (and clear) all such decorations on the shared+// model, regardless of which editor lifecycle created them.+const ACTIVE_STATEMENT_DECORATION_CLASS = "bg-gray-200";+export function MonacoEditor({advices = [],autoCompleteContext,@@ -147,6 +152,12 @@ export function MonacoEditor({// approach silently no-op'd in some cases (observed after the model// mutated between ticks), leaving stale highlights on screen.const activeDecorationIdsRef = useRef<string[]>([]);+ // Guards against re-entering emitSelectionSideEffects. Applying the+ // active-statement decoration via deltaDecorations can synchronously emit a+ // cursor/selection-change event (tracked ranges recompute when decorations+ // change), which would re-enter this handler mid-deltaDecorations — Monaco+ // forbids nested deltaDecorations ("could lead to leaking decorations").+ const emittingSideEffectsRef = useRef(false);const contentRef = useRef(safeContent);const languageRef = useRef(safeLanguage);const readOnlyRef = useRef(readOnly);@@ -207,7 +218,19 @@ export function MonacoEditor({const editor = editorRef.current;const model = modelRef.current ?? editor?.getModel();if (!editor || !model) return;+ if (emittingSideEffectsRef.current) return;+ emittingSideEffectsRef.current = true;+ try {+ emitSelectionSideEffectsImpl(editor, model);+ } finally {+ emittingSideEffectsRef.current = false;+ }+ };+ const emitSelectionSideEffectsImpl = (+ editor: IStandaloneCodeEditor,+ model: ITextModel+ ) => {const selection = editor.getSelection();selectionRef.current = selection;onSelectionChangeRef.current?.(selection);@@ -236,13 +259,28 @@ export function MonacoEditor({options: {isWholeLine: false,shouldFillLineOnLineBreak: true,- className: "bg-gray-200",+ className: ACTIVE_STATEMENT_DECORATION_CLASS,},},]: [];+ // The text model is cached and shared across editor re-creations+ // (see getOrCreateTextModel) and outlives every editor instance.+ // Active-statement decorations live on the model, so a decoration+ // created by a prior editor lifecycle (effect re-run, StrictMode+ // double-mount, etc.) isn't tracked by this instance's id ref and+ // would leak as a stacked highlight. Clear ALL active-statement+ // decorations on the model, not just the one id this instance owns,+ // so exactly one highlight survives.+ const staleIds = model+ .getAllDecorations()+ .filter((d) => d.options.className === ACTIVE_STATEMENT_DECORATION_CLASS)+ .map((d) => d.id);+ const oldIds = Array.from(+ new Set([...activeDecorationIdsRef.current, ...staleIds])+ );activeDecorationIdsRef.current = editor.deltaDecorations(- activeDecorationIdsRef.current,+ oldIds,nextDecorations);onActiveContentChangeRef.current?.(@@ -405,8 +443,23 @@ export function MonacoEditor({ws.removeEventListener("message", messageHandler!));}- if (editorRef.current && activeDecorationIdsRef.current.length > 0) {- editorRef.current.deltaDecorations(activeDecorationIdsRef.current, []);+ // Clear ALL active-statement decorations on the (shared, persistent)+ // model, not just this instance's tracked id, so teardown can't leave+ // an orphan highlight behind for the next editor lifecycle.+ const model = modelRef.current ?? editorRef.current?.getModel();+ if (editorRef.current && model) {+ const grayIds = model+ .getAllDecorations()+ .filter(+ (d) => d.options.className === ACTIVE_STATEMENT_DECORATION_CLASS+ )+ .map((d) => d.id);+ const oldIds = Array.from(+ new Set([...activeDecorationIdsRef.current, ...grayIds])+ );+ if (oldIds.length > 0) {+ editorRef.current.deltaDecorations(oldIds, []);+ }}activeDecorationIdsRef.current = [];if (editorRef.current) {diff --git a/frontend/src/react/components/sql-editor/SaveSheetModal.test.tsx b/frontend/src/react/components/sql-editor/SaveSheetModal.test.tsxindex 998d7b3a2b..8cb8494d1f 100644--- a/frontend/src/react/components/sql-editor/SaveSheetModal.test.tsx+++ b/frontend/src/react/components/sql-editor/SaveSheetModal.test.tsx@@ -343,4 +343,24 @@ describe("SaveSheetModal", () => {unmount();});++ test("6. Saved but untitled tab shows modal instead of saving silently", () => {+ const { container, render, unmount } = renderIntoContainer(+ <SaveSheetModal />+ );+ render();++ // Worksheet exists (has a name) but its title is empty — a manual save+ // should prompt for a title rather than silently re-persisting Untitled.+ const savedUntitledTab = { ...savedTab, title: "" };+ emitSaveSheet({ tab: savedUntitledTab });++ const dialog = container.querySelector("[data-testid='dialog']");+ expect(dialog?.getAttribute("data-open")).toBe("true");+ expect(+ mocks.editorWorksheetStore.maybeUpdateWorksheet+ ).not.toHaveBeenCalled();++ unmount();+ });});diff --git a/frontend/src/react/components/sql-editor/SaveSheetModal.tsx b/frontend/src/react/components/sql-editor/SaveSheetModal.tsxindex 14ded7e241..0d8e7e185c 100644--- a/frontend/src/react/components/sql-editor/SaveSheetModal.tsx+++ b/frontend/src/react/components/sql-editor/SaveSheetModal.tsx@@ -28,7 +28,12 @@ export function SaveSheetModal() {const [folder, setFolder] = useState("");const [rawTab, setRawTab] = useState<SQLEditorTab | undefined>(undefined);- const needShowModal = (tab: SQLEditorTab) => !tab.worksheet;+ // A manual save opens the modal when the worksheet has never been saved+ // OR is still untitled, so the user can give it a title rather than+ // silently persisting an "Untitled" worksheet. Auto-save never reaches+ // here (it calls `maybeUpdateWorksheet` directly).+ const needShowModal = (tab: SQLEditorTab) =>+ !tab.worksheet || !tab.title.trim();const doSaveSheet = async (tab?: SQLEditorTab,diff --git a/frontend/src/react/components/sql-editor/SchemaPane/TreeNode/CommonNode.tsx b/frontend/src/react/components/sql-editor/SchemaPane/TreeNode/CommonNode.tsxindex 729c16b454..360a9826d4 100644--- a/frontend/src/react/components/sql-editor/SchemaPane/TreeNode/CommonNode.tsx+++ b/frontend/src/react/components/sql-editor/SchemaPane/TreeNode/CommonNode.tsx@@ -80,7 +80,7 @@ export function CommonNode({className="flex-1 truncate pl-[2px] min-w-16"/>) : (- <span className="pl-[2px]">{text}</span>+ <span className="flex-1 truncate pl-[2px] min-w-16">{text}</span>)) : (fallbackText