Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: share monaco editor and data table instance between tabs (#2604)

Liu Jibd96532f904e
diff --git a/frontend/src/components/ProvideSQLEditorContext.vue b/frontend/src/components/ProvideSQLEditorContext.vue
index 411795ca27..7dec24fb88 100644
--- a/frontend/src/components/ProvideSQLEditorContext.vue
+++ b/frontend/src/components/ProvideSQLEditorContext.vue
@@ -106,7 +106,6 @@ const prepareSheetFromQuery = async () => {
setConnectionContextFromCurrentTab();
useSQLEditorStore().setSQLEditorState({
sharedSheet: sheet,
- shouldSetContent: true,
});
}
};
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index b0af287f04..f5781565ba 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -838,21 +838,21 @@ const routes: Array<RouteRecordRaw> = [
path: "",
name: "sql-editor.home",
meta: { title: () => "SQL Editor" },
- component: () => import("../views/sql-editor/SQLEditor.vue"),
+ component: () => import("../views/sql-editor/SQLEditorPage.vue"),
props: true,
},
{
path: "/sql-editor/:connectionSlug",
name: "sql-editor.detail",
meta: { title: () => "SQL Editor" },
- component: () => import("../views/sql-editor/SQLEditor.vue"),
+ component: () => import("../views/sql-editor/SQLEditorPage.vue"),
props: true,
},
{
path: "/sql-editor/:connectionSlug/:sheetSlug",
name: "sql-editor.share",
meta: { title: () => "SQL Editor" },
- component: () => import("../views/sql-editor/SQLEditor.vue"),
+ component: () => import("../views/sql-editor/SQLEditorPage.vue"),
props: true,
},
],
diff --git a/frontend/src/store/modules/sqlEditor.ts b/frontend/src/store/modules/sqlEditor.ts
index 43a20b75b5..c48231c188 100644
--- a/frontend/src/store/modules/sqlEditor.ts
+++ b/frontend/src/store/modules/sqlEditor.ts
@@ -34,7 +34,6 @@ export const useSQLEditorStore = defineStore("sqlEditor", {
connectionContext: getDefaultConnectionContext(),
isExecuting: false,
isShowExecutingHint: false,
- shouldSetContent: false,
shouldFormatContent: false,
// Related data and status
queryHistoryList: [],
@@ -88,9 +87,6 @@ export const useSQLEditorStore = defineStore("sqlEditor", {
setConnectionContext(payload: Partial<ConnectionContext>) {
Object.assign(this.connectionContext, payload);
},
- setShouldSetContent(payload: boolean) {
- this.shouldSetContent = payload;
- },
setShouldFormatContent(payload: boolean) {
this.shouldFormatContent = payload;
},
diff --git a/frontend/src/types/store.ts b/frontend/src/types/store.ts
index 523d423940..ed630c567e 100644
--- a/frontend/src/types/store.ts
+++ b/frontend/src/types/store.ts
@@ -194,7 +194,6 @@ export interface LabelState {
export interface SQLEditorState {
connectionTree: ConnectionAtom[];
connectionContext: ConnectionContext;
- shouldSetContent: boolean;
shouldFormatContent: boolean;
queryHistoryList: QueryHistory[];
isFetchingQueryHistory: boolean;
diff --git a/frontend/src/views/sql-editor/AsidePanel/SheetContainer.vue b/frontend/src/views/sql-editor/AsidePanel/SheetContainer.vue
index ab23a6fac0..d1042ac7d2 100644
--- a/frontend/src/views/sql-editor/AsidePanel/SheetContainer.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/SheetContainer.vue
@@ -246,7 +246,6 @@ const handleSheetClick = async (sheet: Sheet) => {
if (tab.sheetId === sheet.id) {
tabStore.setCurrentTabId(tab.id);
setConnectionContextFromCurrentTab();
- sqlEditorStore.setShouldSetContent(true);
return;
}
}
@@ -259,7 +258,6 @@ const handleSheetClick = async (sheet: Sheet) => {
sheetId: sheet.id,
});
setConnectionContextFromCurrentTab();
- sqlEditorStore.setShouldSetContent(true);
}
};
</script>
diff --git a/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue b/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue
index d85de74078..c1441e2a06 100644
--- a/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue
@@ -17,8 +17,7 @@
</template>
<script lang="ts" setup>
-import { debounce } from "lodash-es";
-import { computed, defineEmits, ref, watch, watchEffect } from "vue";
+import { computed, defineEmits, nextTick, ref, watch, watchEffect } from "vue";
import {
useInstanceStore,
@@ -63,16 +62,15 @@ const selectedDialect = computed((): SQLDialect => {
return "mysql";
});
const readonly = computed(() => sheetStore.isReadOnly);
+const currentTabId = computed(() => tabStore.currentTabId);
+const isSwitchingTab = ref(false);
-watch(
- () => sqlEditorStore.shouldSetContent,
- () => {
- if (sqlEditorStore.shouldSetContent) {
- editorRef.value?.setEditorContent(tabStore.currentTab.statement);
- sqlEditorStore.setShouldSetContent(false);
- }
- }
-);
+watch(currentTabId, () => {
+ isSwitchingTab.value = true;
+ nextTick(() => {
+ isSwitchingTab.value = false;
+ });
+});
watch(
() => sqlEditorStore.shouldFormatContent,
@@ -84,18 +82,23 @@ watch(
}
);
-const handleChange = debounce((value: string) => {
+const handleChange = (value: string) => {
+ // When we are switching between tabs, the MonacoEditor emits a 'change'
+ // event, but we shouldn't update the current tab;
+ if (isSwitchingTab.value) {
+ return;
+ }
tabStore.updateCurrentTab({
statement: value,
isSaved: false,
});
-}, 300);
+};
-const handleChangeSelection = debounce((value: string) => {
+const handleChangeSelection = (value: string) => {
tabStore.updateCurrentTab({
selectedStatement: value,
});
-}, 300);
+};
const handleSaveSheet = () => {
emit("save-sheet");
diff --git a/frontend/src/views/sql-editor/SQLEditor.vue b/frontend/src/views/sql-editor/SQLEditorPage.vue
similarity index 94%
rename from frontend/src/views/sql-editor/SQLEditor.vue
rename to frontend/src/views/sql-editor/SQLEditorPage.vue
index 7c90bb33f4..9f7a106cbc 100644
--- a/frontend/src/views/sql-editor/SQLEditor.vue
+++ b/frontend/src/views/sql-editor/SQLEditorPage.vue
@@ -9,10 +9,10 @@
<template v-if="hasTabs">
<Splitpanes horizontal class="default-theme">
<Pane :size="isDisconnected ? 100 : 60">
- <EditorPanel :key="paneKey" />
+ <EditorPanel />
</Pane>
<Pane :size="isDisconnected ? 0 : 40">
- <TablePanel :key="paneKey" />
+ <TablePanel />
</Pane>
</Splitpanes>
</template>
@@ -38,7 +38,6 @@ import "splitpanes/dist/splitpanes.css";
const tabStore = useTabStore();
const hasTabs = computed(() => tabStore.hasTabs);
-const paneKey = computed(() => tabStore.currentTab.id);
const isDisconnected = computed(() => tabStore.isDisconnected);
</script>