Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore(sql-editor): loading spinner for monaco-editor (#9587)
Liu Ji8079e573dc01
diff --git a/frontend/src/components/AnomalyCenter/AnomalyTable.vue b/frontend/src/components/AnomalyCenter/AnomalyTable.vueindex dd1bbeb07c..e4f032862b 100644--- a/frontend/src/components/AnomalyCenter/AnomalyTable.vue+++ b/frontend/src/components/AnomalyCenter/AnomalyTable.vue@@ -57,7 +57,7 @@@close="dismissModal"><div- class="space-y-4 flex flex-col overflow-hidden"+ class="space-y-4 flex flex-col overflow-hidden relative"style="width: calc(100vw - 10rem); height: calc(100vh - 12rem)"><DiffEditordiff --git a/frontend/src/components/Changelist/ChangelistDetail/RawSQLEditor/RawSQLEditor.vue b/frontend/src/components/Changelist/ChangelistDetail/RawSQLEditor/RawSQLEditor.vueindex 361da09382..4aa211aece 100644--- a/frontend/src/components/Changelist/ChangelistDetail/RawSQLEditor/RawSQLEditor.vue+++ b/frontend/src/components/Changelist/ChangelistDetail/RawSQLEditor/RawSQLEditor.vue@@ -8,7 +8,7 @@<divref="editorWrapperRef"- class="flex-1 overflow-hidden"+ class="flex-1 overflow-hidden relative":data-height="editorWrapperHeight"><MonacoEditordiff --git a/frontend/src/components/IssueV1/components/GrantRequest/GrantRequestExporterForm.vue b/frontend/src/components/IssueV1/components/GrantRequest/GrantRequestExporterForm.vueindex e71f1c842b..9ab0f63301 100644--- a/frontend/src/components/IssueV1/components/GrantRequest/GrantRequestExporterForm.vue+++ b/frontend/src/components/IssueV1/components/GrantRequest/GrantRequestExporterForm.vue@@ -27,7 +27,7 @@class="w-full flex flex-col justify-start items-start"><span class="flex items-center textlabel mb-2">SQL</span>- <div class="w-full border rounded">+ <div class="w-full border rounded min-h-[6rem] relative"><MonacoEditorclass="w-full h-[300px]":content="state.statement"diff --git a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vueindex a3641823fa..d3af452a53 100644--- a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue+++ b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue@@ -117,7 +117,7 @@</template></BBAttention>- <div class="whitespace-pre-wrap overflow-hidden">+ <div class="whitespace-pre-wrap overflow-hidden min-h-[120px] relative"><MonacoEditorclass="w-full h-auto max-h-[360px] min-h-[120px] border rounded-[3px]":filename="`${selectedTask.name}.sql`"diff --git a/frontend/src/components/IssueV1/components/StatementSection/SDLView/SDLView.vue b/frontend/src/components/IssueV1/components/StatementSection/SDLView/SDLView.vueindex 9274911400..ec5a207072 100644--- a/frontend/src/components/IssueV1/components/StatementSection/SDLView/SDLView.vue+++ b/frontend/src/components/IssueV1/components/StatementSection/SDLView/SDLView.vue@@ -52,37 +52,39 @@</NTab></NTabs>- <DiffEditor- v-if="state.tab === 'DIFF'"- class="border rounded-[3px] overflow-clip"- :original="sdlState.detail.previousSDL"- :modified="sdlState.detail.prettyExpectedSDL"- :readonly="true"- :auto-height="{- alignment: 'modified',- min: 120,- max: 480,- }"- />- <MonacoEditor- v-if="state.tab === 'STATEMENT'"- class="w-full h-auto border rounded-[3px] overflow-clip"- data-label="bb-issue-sql-editor"- :content="sdlState.detail.diffDDL"- :readonly="true"- :auto-focus="false"- :auto-height="{ min: 120, max: 360 }"- />- <MonacoEditor- v-if="state.tab === 'SCHEMA'"- class="w-full h-auto border rounded-[3px] overflow-clip"- data-label="bb-issue-sql-editor"- :content="sdlState.detail.expectedSDL"- :readonly="true"- :auto-focus="false"- :auto-height="{ min: 120, max: 360 }"- :advices="markers"- />+ <div class="relative min-h-[6rem]">+ <DiffEditor+ v-if="state.tab === 'DIFF'"+ class="border rounded-[3px] overflow-clip"+ :original="sdlState.detail.previousSDL"+ :modified="sdlState.detail.prettyExpectedSDL"+ :readonly="true"+ :auto-height="{+ alignment: 'modified',+ min: 120,+ max: 480,+ }"+ />+ <MonacoEditor+ v-if="state.tab === 'STATEMENT'"+ class="w-full h-auto border rounded-[3px] overflow-clip"+ data-label="bb-issue-sql-editor"+ :content="sdlState.detail.diffDDL"+ :readonly="true"+ :auto-focus="false"+ :auto-height="{ min: 120, max: 360 }"+ />+ <MonacoEditor+ v-if="state.tab === 'SCHEMA'"+ class="w-full h-auto border rounded-[3px] overflow-clip"+ data-label="bb-issue-sql-editor"+ :content="sdlState.detail.expectedSDL"+ :readonly="true"+ :auto-focus="false"+ :auto-height="{ min: 120, max: 360 }"+ :advices="markers"+ />+ </div></template></div></div>diff --git a/frontend/src/components/MonacoEditor/DiffEditor.vue b/frontend/src/components/MonacoEditor/DiffEditor.vueindex 4caa3f85e9..9470d33b9f 100644--- a/frontend/src/components/MonacoEditor/DiffEditor.vue+++ b/frontend/src/components/MonacoEditor/DiffEditor.vue@@ -10,7 +10,6 @@</template><script lang="ts" setup>-import type monaco from "monaco-editor";import { v4 as uuidv4 } from "uuid";import {onMounted,@@ -24,17 +23,11 @@ import {} from "vue";import type { Language } from "@/types";import type { AutoHeightOptions } from "./composables";-import type { MonacoModule } from "./types";--const [- { useMonacoTextModel },- { useAutoHeight, useOptionByKey },- { extensionNameOfLanguage },-] = await Promise.all([- import("./text-model"),- import("./composables"),- import("./utils"),-]);+import { useAutoHeight, useOptionByKey } from "./composables";+import monaco, { createMonacoDiffEditor } from "./editor";+import { useMonacoTextModel } from "./text-model";+import type { IStandaloneDiffEditor, MonacoModule } from "./types";+import { extensionNameOfLanguage } from "./utils";export type DiffEditorAutoHeightOptions = AutoHeightOptions & {alignment: "original" | "modified";@@ -59,23 +52,16 @@ const props = withDefaults(const emit = defineEmits<{(e: "update:modified", modified: string): void;- (- e: "ready",- monaco: MonacoModule,- editor: monaco.editor.IStandaloneDiffEditor- ): void;+ (e: "ready", monaco: MonacoModule, editor: IStandaloneDiffEditor): void;}>();const containerRef = ref<HTMLDivElement>();// use shallowRef to avoid deep conversion which will cause page crash.-const editorRef = shallowRef<monaco.editor.IStandaloneDiffEditor>();+const editorRef = shallowRef<IStandaloneDiffEditor>();const isEditorLoaded = ref(false);-const useDiffModels = (- monaco: MonacoModule,- editor: monaco.editor.IStandaloneDiffEditor-) => {+const useDiffModels = (monaco: MonacoModule, editor: IStandaloneDiffEditor) => {const language = toRef(props, "language");const original = useMonacoTextModel(computed(() => `${uuidv4()}.${extensionNameOfLanguage(props.language)}`),@@ -106,7 +92,7 @@ const useDiffModels = (const useModifiedContent = (monaco: MonacoModule,- editor: monaco.editor.IStandaloneDiffEditor+ editor: IStandaloneDiffEditor) => {const modified = ref(getModifiedContent(editor));const update = () => {@@ -119,7 +105,7 @@ const useModifiedContent = (return modified;};-const getModifiedContent = (editor: monaco.editor.IStandaloneDiffEditor) => {+const getModifiedContent = (editor: IStandaloneDiffEditor) => {const model = editor.getModel();if (!model) return "";@@ -127,8 +113,6 @@ const getModifiedContent = (editor: monaco.editor.IStandaloneDiffEditor) => {};onMounted(async () => {- const { default: monaco, createMonacoDiffEditor } = await import("./editor");-const container = containerRef.value;if (!container) {// Give up creating monaco editor if the component has been unmounteddiff --git a/frontend/src/components/MonacoEditor/MonacoEditor.vue b/frontend/src/components/MonacoEditor/MonacoEditor.vueindex 0fe71b1582..1b3f3b2e63 100644--- a/frontend/src/components/MonacoEditor/MonacoEditor.vue+++ b/frontend/src/components/MonacoEditor/MonacoEditor.vue@@ -10,16 +10,9 @@import { v4 as uuidv4 } from "uuid";import { computed, toRef } from "vue";import type { Language } from "@/types";--const [- { default: MonacoTextModelEditor },- { useMonacoTextModel },- { extensionNameOfLanguage },-] = await Promise.all([- import("./MonacoTextModelEditor.vue"),- import("./text-model"),- import("./utils"),-]);+import MonacoTextModelEditor from "./MonacoTextModelEditor.vue";+import { useMonacoTextModel } from "./text-model";+import { extensionNameOfLanguage } from "./utils";const props = withDefaults(defineProps<{diff --git a/frontend/src/components/MonacoEditor/MonacoTextModelEditor.vue b/frontend/src/components/MonacoEditor/MonacoTextModelEditor.vueindex cc09ebe0e7..cb6134fa7e 100644--- a/frontend/src/components/MonacoEditor/MonacoTextModelEditor.vue+++ b/frontend/src/components/MonacoEditor/MonacoTextModelEditor.vue@@ -10,7 +10,6 @@</template><script lang="ts" setup>-import type monaco from "monaco-editor";import {onMounted,ref,@@ -38,18 +37,25 @@ import {useSuggestOptionByLanguage,} from "./composables";import { shouldUseNewLSP } from "./dev";-import type { AdviceOption, MonacoModule } from "./types";+import monaco, { createMonacoEditor } from "./editor";+import type {+ AdviceOption,+ IStandaloneCodeEditor,+ IStandaloneEditorConstructionOptions,+ ITextModel,+ MonacoModule,+} from "./types";const props = withDefaults(defineProps<{- model?: monaco.editor.ITextModel;+ model?: ITextModel;sqlDialect?: SQLDialect;readonly?: boolean;autoFocus?: boolean;autoHeight?: AutoHeightOptions;autoCompleteContext?: AutoCompleteContext;advices?: AdviceOption[];- options?: monaco.editor.IStandaloneEditorConstructionOptions;+ options?: IStandaloneEditorConstructionOptions;}>(),{model: undefined,@@ -66,21 +72,15 @@ const props = withDefaults(const emit = defineEmits<{(e: "update:content", content: string): void;(e: "select-content", content: string): void;- (- e: "ready",- monaco: MonacoModule,- editor: monaco.editor.IStandaloneCodeEditor- ): void;+ (e: "ready", monaco: MonacoModule, editor: IStandaloneCodeEditor): void;}>();const containerRef = ref<HTMLDivElement>();// use shallowRef to avoid deep conversion which will cause page crash.-const editorRef = shallowRef<monaco.editor.IStandaloneCodeEditor>();+const editorRef = shallowRef<IStandaloneCodeEditor>();const ready = ref(false);onMounted(async () => {- const { default: monaco, createMonacoEditor } = await import("./editor");-const container = containerRef.value;if (!container) {// Give up creating monaco editor if the component has been unmounteddiff --git a/frontend/src/components/MonacoEditor/WrappedDiffEditor.vue b/frontend/src/components/MonacoEditor/WrappedDiffEditor.vueindex 377bf9d53b..e0140b5d32 100644--- a/frontend/src/components/MonacoEditor/WrappedDiffEditor.vue+++ b/frontend/src/components/MonacoEditor/WrappedDiffEditor.vue@@ -1,9 +1,44 @@<template><Suspense><DiffEditor v-bind="($attrs as any)" />+ <template #fallback>+ <div ref="spinnerWrapperElRef" :class="classes">+ <BBSpin />+ </div>+ </template></Suspense></template><script setup lang="ts">-import DiffEditor from "./DiffEditor.vue";+import { useParentElement } from "@vueuse/core";+import { computed, defineAsyncComponent, ref } from "vue";++const DiffEditor = defineAsyncComponent(() => import("./DiffEditor.vue"));++const spinnerWrapperElRef = ref<HTMLElement>();+const parentElRef = useParentElement(spinnerWrapperElRef);++const classes = computed(() => {+ const classes: string[] = [+ "flex",+ "flex-col",+ "items-center",+ "justify-center",+ ];+ const parent = parentElRef.value;+ if (parent) {+ const { position, display } = getComputedStyle(parent);+ if (["relative", "absolute", "fixed"].includes(position)) {+ classes.push("absolute", "inset-0", "bg-white/50");+ return classes;+ }+ if (["flex", "inline-flex"].includes(display)) {+ classes.push("w-full", "h-full", "flex-1");+ return classes;+ }+ }++ classes.push("w-full", "h-full");+ return classes;+});</script>diff --git a/frontend/src/components/MonacoEditor/WrappedMonacoEditor.vue b/frontend/src/components/MonacoEditor/WrappedMonacoEditor.vueindex a897f05782..478a953255 100644--- a/frontend/src/components/MonacoEditor/WrappedMonacoEditor.vue+++ b/frontend/src/components/MonacoEditor/WrappedMonacoEditor.vue@@ -1,9 +1,46 @@<template><Suspense><MonacoEditor v-bind="($attrs as any)" />+ <template #fallback>+ <div ref="spinnerWrapperElRef" :class="classes">+ <BBSpin />+ </div>+ </template></Suspense></template><script setup lang="ts">-import MonacoEditor from "./MonacoEditor.vue";+import { useParentElement } from "@vueuse/core";+import { defineAsyncComponent, ref } from "vue";+import { computed } from "vue";+import { BBSpin } from "@/bbkit";++const MonacoEditor = defineAsyncComponent(() => import("./MonacoEditor.vue"));++const spinnerWrapperElRef = ref<HTMLElement>();+const parentElRef = useParentElement(spinnerWrapperElRef);++const classes = computed(() => {+ const classes: string[] = [+ "flex",+ "flex-col",+ "items-center",+ "justify-center",+ ];+ const parent = parentElRef.value;+ if (parent) {+ const { position, display } = getComputedStyle(parent);+ if (["relative", "absolute", "fixed"].includes(position)) {+ classes.push("absolute", "inset-0", "bg-white/50");+ return classes;+ }+ if (["flex", "inline-flex"].includes(display)) {+ classes.push("w-full", "h-full", "flex-1");+ return classes;+ }+ }++ classes.push("w-full", "h-full");+ return classes;+});</script>diff --git a/frontend/src/components/MonacoEditor/types.ts b/frontend/src/components/MonacoEditor/types.tsindex b2af79d0d7..1834adbb49 100644--- a/frontend/src/components/MonacoEditor/types.ts+++ b/frontend/src/components/MonacoEditor/types.ts@@ -3,7 +3,13 @@ import type * as monaco from "monaco-editor/esm/vs/editor/editor.api.js";export type MonacoModule = typeof monaco;export type IStandaloneCodeEditor = monaco.editor.IStandaloneCodeEditor;+export type IStandaloneEditorConstructionOptions =+ monaco.editor.IStandaloneEditorConstructionOptions;export type IStandaloneDiffEditor = monaco.editor.IStandaloneDiffEditor;+export type IStandaloneDiffEditorConstructionOptions =+ monaco.editor.IStandaloneDiffEditorConstructionOptions;++export type ITextModel = monaco.editor.ITextModel;export type AdviceOption = {severity: "ERROR" | "WARNING";diff --git a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vueindex 8d62f8b419..7fe742f27c 100644--- a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue+++ b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue@@ -9,6 +9,13 @@<Suspense><SQLEditor @execute="handleExecute" />+ <template #fallback>+ <div+ class="w-full h-auto flex-grow flex flex-col items-center justify-center"+ >+ <BBSpin />+ </div>+ </template></Suspense></template>@@ -27,6 +34,7 @@</template><script lang="ts" setup>+import { defineAsyncComponent } from "vue";import { useExecuteSQL } from "@/composables/useExecuteSQL";import { AIChatToSQL } from "@/plugins/ai";import {@@ -44,9 +52,10 @@ import {SaveSheetModal,} from "../EditorCommon";import { useSQLEditorContext } from "../context";-import SQLEditor from "./SQLEditor.vue";import SheetForIssueTipsBar from "./SheetForIssueTipsBar.vue";+const SQLEditor = defineAsyncComponent(() => import("./SQLEditor.vue"));+const tabStore = useTabStore();const tab = useCurrentTab();const { showAIChatBox } = useSQLEditorContext();diff --git a/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue b/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vueindex c38a26ba6e..cecb95df5c 100644--- a/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue+++ b/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue@@ -28,6 +28,11 @@ import type {IStandaloneCodeEditor,MonacoModule,} from "@/components/MonacoEditor";+import MonacoEditor from "@/components/MonacoEditor/MonacoEditor.vue";+import {+ extensionNameOfLanguage,+ formatEditorContent,+} from "@/components/MonacoEditor/utils";import {useTabStore,useSQLEditorStore,@@ -45,14 +50,6 @@ import {import { formatEngineV1, useInstanceV1EditorLanguage } from "@/utils";import { useSQLEditorContext } from "../context";-const [- { default: MonacoEditor },- { extensionNameOfLanguage, formatEditorContent },-] = await Promise.all([- import("@/components/MonacoEditor/MonacoEditor.vue"),- import("@/components/MonacoEditor/utils"),-]);-const emit = defineEmits<{(e: "execute",diff --git a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/HoverPanel/ViewInfo.vue b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/HoverPanel/ViewInfo.vueindex 27947709f2..8dc7d8399d 100644--- a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/HoverPanel/ViewInfo.vue+++ b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/HoverPanel/ViewInfo.vue@@ -10,11 +10,13 @@</NCheckbox></div></div>- <MonacoEditor- :content="format ? formatted.data : view.definition"- :readonly="true"- class="border w-full flex-1"- />+ <div class="w-full flex-1 relative">+ <MonacoEditor+ :content="format ? formatted.data : view.definition"+ :readonly="true"+ class="border w-full h-full"+ />+ </div></div></template>diff --git a/frontend/src/views/sql-editor/TerminalPanel/CompactSQLEditor.vue b/frontend/src/views/sql-editor/TerminalPanel/CompactSQLEditor.vueindex c6c90ca26e..621a2ea43b 100644--- a/frontend/src/views/sql-editor/TerminalPanel/CompactSQLEditor.vue+++ b/frontend/src/views/sql-editor/TerminalPanel/CompactSQLEditor.vue@@ -29,6 +29,11 @@ import type {IStandaloneCodeEditor,MonacoModule,} from "@/components/MonacoEditor";+import MonacoEditor from "@/components/MonacoEditor/MonacoEditor.vue";+import {+ useEditorContextKey,+ formatEditorContent,+} from "@/components/MonacoEditor/utils";import { useTabStore, useSQLEditorStore, useInstanceV1ByUID } from "@/store";import {dialectOfEngineV1,@@ -37,21 +42,12 @@ import {SQLDialect,} from "@/types";import { formatEngineV1, useInstanceV1EditorLanguage } from "@/utils";--const [- { default: MonacoEditor },- { useEditorContextKey, formatEditorContent },- {- checkCursorAtFirstLine,- checkCursorAtLast,- checkCursorAtLastLine,- checkEndsWithSemicolon,- },-] = await Promise.all([- import("@/components/MonacoEditor/MonacoEditor.vue"),- import("@/components/MonacoEditor/utils"),- import("./utils"),-]);+import {+ checkCursorAtFirstLine,+ checkCursorAtLast,+ checkCursorAtLastLine,+ checkEndsWithSemicolon,+} from "./utils";const props = defineProps({sql: {diff --git a/frontend/src/views/sql-editor/TerminalPanel/TerminalPanelV1.vue b/frontend/src/views/sql-editor/TerminalPanel/TerminalPanelV1.vueindex a7debfb04b..d0ab5d131f 100644--- a/frontend/src/views/sql-editor/TerminalPanel/TerminalPanelV1.vue+++ b/frontend/src/views/sql-editor/TerminalPanel/TerminalPanelV1.vue@@ -31,6 +31,13 @@@history="handleHistory"@clear-screen="handleClearScreen"/>+ <template #fallback>+ <div+ class="w-full min-h-[2rem] flex flex-col items-center justify-center"+ >+ <BBSpin />+ </div>+ </template></Suspense><ResultViewV1v-if="query.params && query.resultSet"@@ -70,7 +77,8 @@<script lang="ts" setup>import { useElementSize } from "@vueuse/core";-import { computed, ref, unref, watch } from "vue";+import { computed, defineAsyncComponent, ref, unref, watch } from "vue";+import { BBSpin } from "@/bbkit";import { useTabStore, useWebTerminalV1Store } from "@/store";import { ExecuteConfig, ExecuteOption, WebTerminalQueryItemV1 } from "@/types";import {@@ -79,10 +87,13 @@ import {ConnectionHolder,ResultViewV1,} from "../EditorCommon";-import CompactSQLEditor from "./CompactSQLEditor.vue";import { useAttractFocus } from "./useAttractFocus";import { useHistory } from "./useHistory";+const CompactSQLEditor = defineAsyncComponent(+ () => import("./CompactSQLEditor.vue")+);+const tabStore = useTabStore();const webTerminalStore = useWebTerminalV1Store();