Skip to content

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

feat(sql-editor): execute query in new tab (#14713)

Liu Ji17f29bb6f9c0
diff --git a/frontend/src/views/sql-editor/EditorPanel/StandardPanel/SQLEditor.vue b/frontend/src/views/sql-editor/EditorPanel/StandardPanel/SQLEditor.vue
index 55b26ecd30..3d4590ec7a 100644
--- a/frontend/src/views/sql-editor/EditorPanel/StandardPanel/SQLEditor.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/StandardPanel/SQLEditor.vue
@@ -65,6 +65,7 @@ import { activeSQLEditorRef } from "./state";
const emit = defineEmits<{
(e: "execute", params: SQLEditorQueryParams): void;
+ (e: "execute-in-new-tab", params: SQLEditorQueryParams): void;
}>();
const tabStore = useSQLEditorTabStore();
@@ -150,19 +151,25 @@ const handleSaveSheet = () => {
editorEvents.emit("save-sheet", { tab });
};
-const runQueryAction = (explain = false) => {
+const runQueryAction = (explain = false, newTab = false) => {
const tab = tabStore.currentTab;
if (!tab) {
return;
}
const statement = tab.selectedStatement || tab.statement || "";
- emit("execute", {
+ const params: SQLEditorQueryParams = {
connection: { ...tab.connection },
statement,
engine: instance.value.engine,
explain,
- selection: tab.editorState.selection,
- });
+ selection: null,
+ };
+ if (!newTab) {
+ params.selection = tab.editorState.selection;
+ emit("execute", params);
+ } else {
+ emit("execute-in-new-tab", params);
+ }
uiStateStore.saveIntroStateByKey({
key: "data.query",
newState: true,
@@ -183,6 +190,16 @@ const handleEditorReady = (
contextMenuOrder: 0,
run: () => runQueryAction(false),
});
+ editor.addAction({
+ id: "RunQueryInNewTab",
+ label: "Run Query in New Tab",
+ keybindings: [
+ monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.Enter,
+ ],
+ contextMenuGroupId: "operation",
+ contextMenuOrder: 0,
+ run: () => runQueryAction(false, /* newTab */ true),
+ });
editor.addAction({
id: "ExplainQuery",
label: "Explain Query",
diff --git a/frontend/src/views/sql-editor/EditorPanel/StandardPanel/StandardPanel.vue b/frontend/src/views/sql-editor/EditorPanel/StandardPanel/StandardPanel.vue
index f966ebb03c..4e8f369ac5 100644
--- a/frontend/src/views/sql-editor/EditorPanel/StandardPanel/StandardPanel.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/StandardPanel/StandardPanel.vue
@@ -16,7 +16,10 @@
>
<Pane>
<Suspense>
- <SQLEditor @execute="handleExecute" />
+ <SQLEditor
+ @execute="handleExecute"
+ @execute-in-new-tab="handleExecuteInNewTab"
+ />
<template #fallback>
<div
class="w-full h-full flex-grow flex flex-col items-center justify-center"
@@ -65,9 +68,10 @@
</template>
<script lang="ts" setup>
+import { cloneDeep } from "lodash-es";
import { storeToRefs } from "pinia";
import { Pane, Splitpanes } from "splitpanes";
-import { computed, defineAsyncComponent } from "vue";
+import { computed, defineAsyncComponent, nextTick } from "vue";
import { BBSpin } from "@/bbkit";
import { useExecuteSQL } from "@/composables/useExecuteSQL";
import { AIChatToSQL } from "@/plugins/ai";
@@ -76,7 +80,11 @@ import {
useSQLEditorTabStore,
} from "@/store";
import type { SQLEditorQueryParams } from "@/types";
-import { instanceV1HasReadonlyMode } from "@/utils";
+import {
+ defaultSQLEditorTab,
+ instanceV1HasReadonlyMode,
+ suggestedTabTitleForSQLEditorConnection,
+} from "@/utils";
import {
EditorAction,
ExecutingHintModal,
@@ -86,6 +94,7 @@ import { useSQLEditorContext } from "../../context";
import ReadonlyModeNotSupported from "../ReadonlyModeNotSupported.vue";
import ResultPanel from "../ResultPanel";
import Welcome from "../Welcome";
+import { useEditorPanelContext } from "../context";
const SQLEditor = defineAsyncComponent(() => import("./SQLEditor.vue"));
@@ -93,6 +102,7 @@ const tabStore = useSQLEditorTabStore();
const { currentTab: tab, isDisconnected } = storeToRefs(tabStore);
const { instance } = useConnectionOfCurrentSQLEditorTab();
const { showAIPanel, AIPanelSize, handleAIPanelResize } = useSQLEditorContext();
+const { cloneViewState } = useEditorPanelContext();
const allowReadonlyMode = computed(() => {
if (isDisconnected.value) return false;
@@ -105,4 +115,28 @@ const { execute } = useExecuteSQL();
const handleExecute = (params: SQLEditorQueryParams) => {
execute(params);
};
+const handleExecuteInNewTab = (params: SQLEditorQueryParams) => {
+ const fromTab = tabStore.currentTab;
+ const clonedTab = defaultSQLEditorTab();
+ if (fromTab) {
+ clonedTab.connection = cloneDeep(fromTab.connection);
+ clonedTab.treeState = cloneDeep(fromTab.treeState);
+ }
+ clonedTab.title = suggestedTabTitleForSQLEditorConnection(
+ clonedTab.connection
+ );
+ const newTab = tabStore.addTab(clonedTab, /* beside */ true);
+ if (fromTab) {
+ const vs = cloneViewState(fromTab.id, newTab.id);
+ if (vs) {
+ vs.view = "CODE";
+ vs.detail = {};
+ }
+ }
+ newTab.statement = params.statement;
+
+ nextTick(() => {
+ execute(params);
+ });
+};
</script>