Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat(sql-editor): Interactive web terminal for Admin mode (#3468)
Liu Jifc8cc65c8960
diff --git a/frontend/naive-ui.config.ts b/frontend/naive-ui.config.tsindex 8509d0eaef..d6430e35a3 100644--- a/frontend/naive-ui.config.ts+++ b/frontend/naive-ui.config.ts@@ -49,6 +49,24 @@ export const themeOverrides = computed((): GlobalThemeOverrides => {};});+export const darkThemeOverrides = computed((): GlobalThemeOverrides => {+ return {+ common: {+ primaryColor: callVar("--color-matrix-green"),+ primaryColorHover: callVar("--color-matrix-green-hover"),+ primaryColorPressed: callVar("--color-matrix-green"),+ },+ Button: {+ colorInfo: callVar("--color-matrix-green"),+ colorHoverInfo: callVar("--color-matrix-green-hover"),+ colorFocusInfo: callVar("--color-matrix-green"),+ borderInfo: callVar("--color-matrix-green"),+ borderHoverInfo: callVar("--color-matrix-green-hover"),+ borderFocusInfo: callVar("--color-matrix-green"),+ },+ };+});+const isZhCn = (): boolean => {return curLocale.value === "zh-CN";};diff --git a/frontend/src/assets/css/tailwind.css b/frontend/src/assets/css/tailwind.cssindex 62653a75df..3d848b7dcd 100644--- a/frontend/src/assets/css/tailwind.css+++ b/frontend/src/assets/css/tailwind.css@@ -62,6 +62,20 @@--color-control-border: #d1d5db;}+/*+ Colors for dark theme+ Only used by Web Terminal now+*/+:root {+ /* same as vs-dark theme's bg, not pure black. */+ --color-dark-bg: #1e1e1e;++ /* The Matrix green */+ --color-matrix-green: #00cc00;+ /* The matrix green lighter */+ --color-matrix-green-hover: #88ff88;+}+@tailwind base;@tailwind components;@tailwind utilities;@@ -211,6 +225,12 @@@apply visible z-50;}+@layer base {+ .bg-dark-bg {+ background-color: var(--color-dark-bg);+ }+}+@layer utilities {/* Chrome, Safari and Opera */.hide-scrollbar::-webkit-scrollbar {diff --git a/frontend/src/components/MonacoEditor/MonacoEditor.vue b/frontend/src/components/MonacoEditor/MonacoEditor.vueindex a839173f83..251634a56f 100644--- a/frontend/src/components/MonacoEditor/MonacoEditor.vue+++ b/frontend/src/components/MonacoEditor/MonacoEditor.vue@@ -40,6 +40,10 @@ const props = defineProps({type: Boolean,default: true,},+ options: {+ type: Object as PropType<Editor.IStandaloneEditorConstructionOptions>,+ default: undefined,+ },});const emit = defineEmits<{@@ -67,6 +71,7 @@ const initEditorInstance = () => {const model = monaco.editor.createModel(sqlCode.value, "sql");const editorInstance = monaco.editor.create(editorContainerRef.value!, {model,+ theme: "bb",tabSize: 2,insertSpaces: true,autoClosingQuotes: "always",@@ -91,6 +96,7 @@ const initEditorInstance = () => {scrollbar: {alwaysConsumeMouseWheel: false,},+ ...props.options,});// add `Format SQL` action into context menu@@ -187,6 +193,16 @@ onMounted(async () => {// Delay the flush timing to ensure it performs after the language client started.flush: "post",});++ watch(+ () => props.options,+ (opts) => {+ if (opts) {+ editorInstance.updateOptions(opts);+ }+ },+ { deep: true }+ );});});diff --git a/frontend/src/components/MonacoEditor/themes/bb-dark.ts b/frontend/src/components/MonacoEditor/themes/bb-dark.tsnew file mode 100644index 0000000000..ad180162e2--- /dev/null+++ b/frontend/src/components/MonacoEditor/themes/bb-dark.ts@@ -0,0 +1,19 @@+import type { editor as Editor } from "monaco-editor";+import { callVar } from "./utils";++export const getBBDarkTheme = (): Editor.IStandaloneThemeData => ({+ base: "vs-dark",+ inherit: true,+ rules: [+ {+ foreground: callVar("--color-matrix-green-hover"),+ token: "keyword",+ },+ ],+ colors: {+ "editor.foreground": callVar("--color-matrix-green"),+ "editorCursor.foreground": callVar("--color-matrix-green-hover"),+ "editorLineNumber.foreground": callVar("--color-matrix-green"),+ "editorLineNumber.activeForeground": callVar("--color-matrix-green-hover"),+ },+});diff --git a/frontend/src/components/MonacoEditor/themes/bb.ts b/frontend/src/components/MonacoEditor/themes/bb.tsnew file mode 100644index 0000000000..0f614390ab--- /dev/null+++ b/frontend/src/components/MonacoEditor/themes/bb.ts@@ -0,0 +1,13 @@+import type { editor as Editor } from "monaco-editor";+import { callVar } from "./utils";++export const getBBTheme = (): Editor.IStandaloneThemeData => ({+ base: "vs",+ inherit: true,+ rules: [],+ colors: {+ "editorCursor.foreground": callVar("--color-accent"),+ "editorLineNumber.foreground": callVar("--color-control-placeholder"),+ "editorLineNumber.activeForeground": callVar("--color-main"),+ },+});diff --git a/frontend/src/components/MonacoEditor/themes/utils.ts b/frontend/src/components/MonacoEditor/themes/utils.tsnew file mode 100644index 0000000000..f68904b5c8--- /dev/null+++ b/frontend/src/components/MonacoEditor/themes/utils.ts@@ -0,0 +1,5 @@+export const callVar = (css: string) => {+ return getComputedStyle(document.documentElement)+ .getPropertyValue(css)+ .trim();+};diff --git a/frontend/src/components/MonacoEditor/useMonaco.ts b/frontend/src/components/MonacoEditor/useMonaco.tsindex 31a38df5c0..5863a7c463 100644--- a/frontend/src/components/MonacoEditor/useMonaco.ts+++ b/frontend/src/components/MonacoEditor/useMonaco.ts@@ -2,6 +2,8 @@ import type { editor as Editor } from "monaco-editor";import { SQLDialect } from "@/types";import sqlFormatter from "./sqlFormatter";import { ExtractPromiseType } from "@/utils";+import { getBBTheme } from "./themes/bb";+import { getBBDarkTheme } from "./themes/bb-dark";export const useMonaco = async () => {const [monaco, { default: EditorWorker }] = await Promise.all([@@ -9,17 +11,10 @@ export const useMonaco = async () => {import("monaco-editor/esm/vs/editor/editor.worker?worker"),]);- monaco.editor.defineTheme("bb-sql-editor-theme", {- base: "vs",- inherit: true,- rules: [],- colors: {- "editorCursor.foreground": "#504de2",- "editorLineNumber.foreground": "#aaaaaa",- "editorLineNumber.activeForeground": "#111111",- },- });- monaco.editor.setTheme("bb-sql-editor-theme");+ const bbTheme = getBBTheme();+ const bbDarkTheme = getBBDarkTheme();+ monaco.editor.defineTheme("bb", bbTheme);+ monaco.editor.defineTheme("bb-dark", bbDarkTheme);self.MonacoEnvironment = {getWorker: (workerId, label) => {diff --git a/frontend/src/composables/useExecuteSQL.ts b/frontend/src/composables/useExecuteSQL.tsindex 0c07a089d9..31192bdb98 100644--- a/frontend/src/composables/useExecuteSQL.ts+++ b/frontend/src/composables/useExecuteSQL.ts@@ -11,7 +11,7 @@ import {} from "../components/MonacoEditor/sqlParser";import { pushNotification, useTabStore, useSQLEditorStore } from "@/store";import { BBNotificationStyle } from "@/bbkit/types";-import { ExecuteConfig, ExecuteOption, TabMode } from "@/types";+import { ExecuteConfig, ExecuteOption, SQLResultSet, TabMode } from "@/types";const useExecuteSQL = () => {const { t } = useI18n();@@ -121,6 +121,8 @@ const useExecuteSQL = () => {// (with or without warnings).sqlEditorStore.fetchQueryHistoryList();}++ return sqlResultSet;} catch (error) {Object.assign(tab, {queryResult: undefined,@@ -170,6 +172,8 @@ const useExecuteSQL = () => {// (with or without warnings).sqlEditorStore.fetchQueryHistoryList();}++ return sqlResultSet;} catch (error) {Object.assign(tab, {queryResult: undefined,@@ -209,13 +213,16 @@ const useExecuteSQL = () => {tab.isExecutingSQL = true;+ let result: SQLResultSet | undefined = undefined;if (tab.mode === TabMode.ReadOnly) {- await executeReadonly(query, config, option);+ result = await executeReadonly(query, config, option);} else if (tab.mode === TabMode.Admin) {- await executeAdmin(query, config, option);+ result = await executeAdmin(query, config, option);}tab.isExecutingSQL = false;++ return result;};return {diff --git a/frontend/src/store/modules/index.ts b/frontend/src/store/modules/index.tsindex a8bd95324b..07daec84a3 100644--- a/frontend/src/store/modules/index.ts+++ b/frontend/src/store/modules/index.ts@@ -32,6 +32,7 @@ export * from "./sheet";export * from "./stage";export * from "./sql";export * from "./sqlEditor";+export * from "./webTerminal";export * from "./subscription";export * from "./tab";export * from "./table";diff --git a/frontend/src/store/modules/sql.ts b/frontend/src/store/modules/sql.tsindex 9a27a736e3..a56ff60251 100644--- a/frontend/src/store/modules/sql.ts+++ b/frontend/src/store/modules/sql.ts@@ -13,7 +13,7 @@ import {import { useDatabaseStore } from "./database";import { useInstanceStore } from "./instance";-function convert(resultSet: ResourceObject): SQLResultSet {+export function convert(resultSet: ResourceObject): SQLResultSet {return {data: JSON.parse((resultSet.attributes.data as string) || "null"),error: resultSet.attributes.error as string,diff --git a/frontend/src/store/modules/webTerminal.ts b/frontend/src/store/modules/webTerminal.tsnew file mode 100644index 0000000000..3d69eb4637--- /dev/null+++ b/frontend/src/store/modules/webTerminal.ts@@ -0,0 +1,28 @@+import { reactive } from "vue";+import { defineStore } from "pinia";+import type { TabInfo, WebTerminalQueryItem } from "@/types";++const createInitialQueryItemByTab = (tab: TabInfo): WebTerminalQueryItem => ({+ sql: tab.statement,+ isExecutingSQL: false,+});++export const useWebTerminalStore = defineStore("webTerminal", () => {+ const map = new Map<string, WebTerminalQueryItem[]>();++ const getQueryListByTab = (tab: TabInfo) => {+ const existed = map.get(tab.id);+ if (existed) return existed;++ const init = reactive([createInitialQueryItemByTab(tab)]);+ // TODO(Jim): watch the length of the list, shift the oldest one if len>20 (maybe)+ map.set(tab.id, init);+ return init;+ };++ const clearQueryListByTab = (tab: TabInfo) => {+ map.delete(tab.id);+ };++ return { getQueryListByTab, clearQueryListByTab };+});diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.tsindex 021bb79c91..c31f0ae824 100644--- a/frontend/src/types/index.ts+++ b/frontend/src/types/index.ts@@ -39,6 +39,7 @@ export * from "./db_extension";export * from "./label";export * from "./deployment";export * from "./sqlEditor";+export * from "./webTerminal";export * from "./tab";export * from "./subscription";export * from "./sheet";diff --git a/frontend/src/types/sql.ts b/frontend/src/types/sql.tsindex 7514a4b4a4..b640dd6e36 100644--- a/frontend/src/types/sql.ts+++ b/frontend/src/types/sql.ts@@ -29,7 +29,8 @@ export type QueryInfo = {export type Advice = TaskCheckResult;export type SQLResultSet = {- data: any[];+ // [columnNames: string[], types: string[], data: any[][]]+ data: [string[], string[], any[][]];error: string;adviceList: Advice[];};diff --git a/frontend/src/types/webTerminal.ts b/frontend/src/types/webTerminal.tsnew file mode 100644index 0000000000..b029484bfc--- /dev/null+++ b/frontend/src/types/webTerminal.ts@@ -0,0 +1,13 @@+import { SQLResultSet } from "./sql";+import { ExecuteConfig, ExecuteOption } from "./tab";++export type WebTerminalQueryItem = {+ sql: string;+ executeParams?: {+ query: string;+ config: ExecuteConfig;+ option?: Partial<ExecuteOption>;+ };+ isExecutingSQL: boolean;+ queryResult?: SQLResultSet;+};diff --git a/frontend/src/views/sql-editor/EditorPanel/ConnectionHolder.vue b/frontend/src/views/sql-editor/EditorCommon/ConnectionHolder.vuesimilarity index 100%rename from frontend/src/views/sql-editor/EditorPanel/ConnectionHolder.vuerename to frontend/src/views/sql-editor/EditorCommon/ConnectionHolder.vuediff --git a/frontend/src/views/sql-editor/EditorCommon/ConnectionPathBar.vue b/frontend/src/views/sql-editor/EditorCommon/ConnectionPathBar.vuenew file mode 100644index 0000000000..bace378920--- /dev/null+++ b/frontend/src/views/sql-editor/EditorCommon/ConnectionPathBar.vue@@ -0,0 +1,148 @@+<template>+ <div+ v-if="!tabStore.isDisconnected"+ class="w-full py-1 px-4 flex justify-between items-center border-b"+ :class="[isProtectedEnvironment && 'bg-yellow-50']"+ >+ <div :class="[isProtectedEnvironment ? 'text-yellow-700' : 'text-main']">+ <template v-if="isProtectedEnvironment">+ {{ $t("sql-editor.sql-execute-in-protected-environment") }}+ </template>+ </div>++ <div class="action-right flex justify-end items-center">+ <NPopover+ v-if="selectedInstance.id !== UNKNOWN_ID && !hasReadonlyDataSource"+ trigger="hover"+ >+ <template #trigger>+ <heroicons-outline:exclamation+ class="h-6 w-6 flex-shrink-0 mr-2"+ :class="[+ isProtectedEnvironment ? 'text-yellow-500' : 'text-yellow-500',+ ]"+ />+ </template>+ <p class="py-1">+ {{ $t("instance.no-read-only-data-source-warn") }}+ <span+ class="underline text-accent cursor-pointer hover:opacity-80"+ @click="gotoInstanceDetailPage"+ >+ {{ $t("sql-editor.create-read-only-data-source") }}+ </span>+ </p>+ </NPopover>++ <NPopover trigger="hover" placement="bottom" :show-arrow="false">+ <template #trigger>+ <label class="flex items-center text-sm space-x-1">+ <div+ v-if="selectedInstance.id !== UNKNOWN_ID"+ class="flex items-center"+ >+ <span class="">{{ selectedInstance.environment.name }}</span>+ <ProtectedEnvironmentIcon+ :environment="selectedInstance.environment"+ class="ml-1"+ :class="[isProtectedEnvironment && '~!text-yellow-700']"+ />+ </div>+ <div+ v-if="selectedInstance.id !== UNKNOWN_ID"+ class="flex items-center"+ >+ <span class="mx-2">/</span>+ <InstanceEngineIcon :instance="selectedInstance" show-status />+ <span class="ml-2">{{ selectedInstance.name }}</span>+ </div>+ <div+ v-if="selectedDatabase.id !== UNKNOWN_ID"+ class="flex items-center"+ >+ <span class="mx-2">/</span>+ <heroicons-outline:database />+ <span class="ml-2">{{ selectedDatabase.name }}</span>+ </div>+ </label>+ </template>+ <section>+ <div class="space-y-2">+ <div+ v-if="selectedInstance.id !== UNKNOWN_ID"+ class="flex flex-col"+ >+ <h1 class="text-gray-400">{{ $t("common.environment") }}</h1>+ <span class="flex items-center">+ {{ selectedInstance.environment.name }}+ <ProtectedEnvironmentIcon+ :environment="selectedInstance.environment"+ class="ml-1"+ />+ </span>+ </div>+ <div+ v-if="selectedInstance.id !== UNKNOWN_ID"+ class="flex flex-col"+ >+ <h1 class="text-gray-400">{{ $t("common.instance") }}</h1>+ <span>{{ selectedInstance.name }}</span>+ </div>+ <div+ v-if="selectedDatabase.id !== UNKNOWN_ID"+ class="flex flex-col"+ >+ <h1 class="text-gray-400">{{ $t("common.database") }}</h1>+ <span>{{ selectedDatabase.name }}</span>+ </div>+ </div>+ </section>+ </NPopover>+ </div>+ </div>+</template>++<script lang="ts" setup>+import { computed } from "vue";+import { NPopover } from "naive-ui";+import { useRouter } from "vue-router";++import { useTabStore, useInstanceById, useDatabaseById } from "@/store";+import { UNKNOWN_ID } from "@/types";+import { instanceSlug } from "@/utils";++const router = useRouter();+const tabStore = useTabStore();++const connection = computed(() => tabStore.currentTab.connection);++const selectedInstance = useInstanceById(+ computed(() => connection.value.instanceId)+);+const selectedDatabase = useDatabaseById(+ computed(() => connection.value.databaseId)+);+const isProtectedEnvironment = computed(() => {+ const instance = selectedInstance.value;+ return instance.environment.tier === "PROTECTED";+});++const hasReadonlyDataSource = computed(() => {+ for (const ds of selectedInstance.value.dataSourceList) {+ if (ds.type === "RO") {+ return true;+ }+ }+ return false;+});++const gotoInstanceDetailPage = () => {+ const route = router.resolve({+ name: "workspace.instance.detail",+ params: {+ instanceSlug: instanceSlug(selectedInstance.value),+ },+ });+ window.open(route.href);+};+</script>diff --git a/frontend/src/views/sql-editor/TablePanel/DataTable.vue b/frontend/src/views/sql-editor/EditorCommon/DataTable.vuesimilarity index 91%rename from frontend/src/views/sql-editor/TablePanel/DataTable.vuerename to frontend/src/views/sql-editor/EditorCommon/DataTable.vueindex da4d7d1be9..bd54a91205 100644--- a/frontend/src/views/sql-editor/TablePanel/DataTable.vue+++ b/frontend/src/views/sql-editor/EditorCommon/DataTable.vue@@ -4,7 +4,7 @@><div class="w-full flex-1 overflow-hidden"><div- class="header-track absolute z-0 left-0 top-0 right-0 h-[34px] border border-block-border bg-gray-50"+ class="header-track absolute z-0 left-0 top-0 right-0 h-[34px] border border-block-border bg-gray-50 dark:bg-gray-700"/><div@@ -22,7 +22,7 @@<thv-for="header of table.getFlatHeaders()":key="header.index"- class="relative px-2 py-2 min-w-[2rem] text-left bg-gray-50 text-xs font-medium text-gray-500 tracking-wider border border-t-0 border-block-border border-b-0"+ class="relative px-2 py-2 min-w-[2rem] text-left bg-gray-50 dark:bg-gray-700 text-xs font-medium text-gray-500 dark:text-gray-300 tracking-wider border border-t-0 border-block-border border-b-0"v-bind="tableResize.getColumnProps(header.index)">{{ header.column.columnDef.header }}@@ -45,7 +45,7 @@<tdv-for="(cell, cellIndex) of row.getVisibleCells()":key="cellIndex"- class="px-2 py-1 text-sm leading-5 whitespace-pre-wrap break-all border border-block-border group-last:border-b-0 group-even:bg-gray-50/50"+ class="px-2 py-1 text-sm dark:text-gray-100 leading-5 whitespace-pre-wrap break-all border border-block-border group-last:border-b-0 group-even:bg-gray-50/50 dark:group-even:bg-gray-700/50">{{ cell.getValue() }}</td>diff --git a/frontend/src/views/sql-editor/EditorPanel/EditorAction.vue b/frontend/src/views/sql-editor/EditorCommon/EditorAction.vuesimilarity index 93%rename from frontend/src/views/sql-editor/EditorPanel/EditorAction.vuerename to frontend/src/views/sql-editor/EditorCommon/EditorAction.vueindex 1b0554e81a..29f39fd845 100644--- a/frontend/src/views/sql-editor/EditorPanel/EditorAction.vue+++ b/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue@@ -55,19 +55,25 @@<script lang="ts" setup>import { computed, defineEmits } from "vue";-import { useExecuteSQL } from "@/composables/useExecuteSQL";import {useInstanceStore,useTabStore,useSQLEditorStore,useInstanceById,} from "@/store";+import type { ExecuteConfig, ExecuteOption } from "@/types";import { UNKNOWN_ID } from "@/types";import SharePopover from "./SharePopover.vue";import TabModeSelect from "./TabModeSelect.vue";const emit = defineEmits<{(e: "save-sheet", content?: string): void;+ (+ e: "execute",+ sql: string,+ config: ExecuteConfig,+ option?: ExecuteOption+ ): void;}>();const instanceStore = useInstanceStore();@@ -102,14 +108,12 @@ const allowSave = computed(() => {return true;});-const { execute } = useExecuteSQL();-const handleRunQuery = async () => {const currentTab = tabStore.currentTab;const statement = currentTab.statement;const selectedStatement = currentTab.selectedStatement;const query = selectedStatement || statement;- await execute(query, { databaseType: selectedInstanceEngine.value });+ await emit("execute", query, { databaseType: selectedInstanceEngine.value });};const handleExplainQuery = () => {@@ -117,7 +121,8 @@ const handleExplainQuery = () => {const statement = currentTab.statement;const selectedStatement = currentTab.selectedStatement;const query = selectedStatement || statement;- execute(+ emit(+ "execute",query,{ databaseType: selectedInstanceEngine.value },{ explain: true }diff --git a/frontend/src/views/sql-editor/EditorPanel/ExecuteHint.vue b/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vuesimilarity index 100%rename from frontend/src/views/sql-editor/EditorPanel/ExecuteHint.vuerename to frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vuediff --git a/frontend/src/views/sql-editor/EditorCommon/ExecutingHintModal.vue b/frontend/src/views/sql-editor/EditorCommon/ExecutingHintModal.vuenew file mode 100644index 0000000000..aee27449fd--- /dev/null+++ b/frontend/src/views/sql-editor/EditorCommon/ExecutingHintModal.vue@@ -0,0 +1,22 @@+<template>+ <BBModal+ v-if="sqlEditorStore.isShowExecutingHint"+ :title="$t('common.tips')"+ @close="handleClose"+ >+ <ExecuteHint @close="handleClose" />+ </BBModal>+</template>++<script lang="ts" setup>+import { useSQLEditorStore } from "@/store";+import ExecuteHint from "./ExecuteHint.vue";++const sqlEditorStore = useSQLEditorStore();++const handleClose = () => {+ sqlEditorStore.setSQLEditorState({+ isShowExecutingHint: false,+ });+};+</script>diff --git a/frontend/src/views/sql-editor/EditorPanel/SaveSheetModal.vue b/frontend/src/views/sql-editor/EditorCommon/SaveSheetForm.vuesimilarity index 100%rename from frontend/src/views/sql-editor/EditorPanel/SaveSheetModal.vuerename to frontend/src/views/sql-editor/EditorCommon/SaveSheetForm.vuediff --git a/frontend/src/views/sql-editor/EditorCommon/SaveSheetModal.vue b/frontend/src/views/sql-editor/EditorCommon/SaveSheetModal.vuenew file mode 100644index 0000000000..5f8b98ada0--- /dev/null+++ b/frontend/src/views/sql-editor/EditorCommon/SaveSheetModal.vue@@ -0,0 +1,91 @@+<template>+ <BBModal+ v-if="state.showModal"+ :title="$t('sql-editor.save-sheet')"+ @close="close"+ >+ <SaveSheetForm @close="close" @save-sheet="trySaveSheet" />+ </BBModal>+</template>++<script lang="ts" setup>+import { computed, reactive } from "vue";++import type { SheetUpsert } from "@/types";+import { UNKNOWN_ID } from "@/types";+import { useDatabaseStore, useSheetStore, useTabStore } from "@/store";+import { defaultTabName } from "@/utils";+import SaveSheetForm from "./SaveSheetForm.vue";++type LocalState = {+ showModal: boolean;+};++const tabStore = useTabStore();+const databaseStore = useDatabaseStore();+const sheetStore = useSheetStore();++const state = reactive<LocalState>({+ showModal: false,+});++const allowSave = computed((): boolean => {+ const tab = tabStore.currentTab;+ if (tab.statement === "") {+ return false;+ }+ if (tab.isSaved) {+ return false;+ }+ // Temporarily disable saving and sharing if we are connected to an instance+ // but not a database.+ if (tab.connection.databaseId === UNKNOWN_ID) {+ return false;+ }+ return true;+});++const doSaveSheet = async (sheetName?: string) => {+ const { name, statement, sheetId } = tabStore.currentTab;+ sheetName = sheetName || name;++ const conn = tabStore.currentTab.connection;+ const database = await databaseStore.getOrFetchDatabaseById(conn.databaseId);+ const sheetUpsert: SheetUpsert = {+ id: sheetId,+ projectId: database.project.id,+ databaseId: conn.databaseId,+ name: sheetName,+ statement: statement,+ };+ const sheet = await sheetStore.upsertSheet(sheetUpsert);++ tabStore.updateCurrentTab({+ sheetId: sheet.id,+ isSaved: true,+ name: sheetName,+ });+};++const trySaveSheet = (sheetName?: string) => {+ if (!allowSave.value) {+ return;+ }++ if (tabStore.currentTab.name === defaultTabName.value && !sheetName) {+ state.showModal = true;+ return;+ }+ state.showModal = false;++ doSaveSheet(sheetName);+};++const close = () => {+ state.showModal = false;+};++defineExpose({+ trySaveSheet,+});+</script>diff --git a/frontend/src/views/sql-editor/EditorPanel/SharePopover.vue b/frontend/src/views/sql-editor/EditorCommon/SharePopover.vuesimilarity index 100%rename from frontend/src/views/sql-editor/EditorPanel/SharePopover.vuerename to frontend/src/views/sql-editor/EditorCommon/SharePopover.vuediff --git a/frontend/src/views/sql-editor/EditorPanel/TabModeSelect.vue b/frontend/src/views/sql-editor/EditorCommon/TabModeSelect.vuesimilarity index 100%rename from frontend/src/views/sql-editor/EditorPanel/TabModeSelect.vuerename to frontend/src/views/sql-editor/EditorCommon/TabModeSelect.vuediff --git a/frontend/src/views/sql-editor/TablePanel/TableView.vue b/frontend/src/views/sql-editor/EditorCommon/TableView.vuesimilarity index 80%rename from frontend/src/views/sql-editor/TablePanel/TableView.vuerename to frontend/src/views/sql-editor/EditorCommon/TableView.vueindex 26c8b16266..40b0f655c5 100644--- a/frontend/src/views/sql-editor/TablePanel/TableView.vue+++ b/frontend/src/views/sql-editor/EditorCommon/TableView.vue@@ -1,5 +1,9 @@<template>- <div class="relative flex flex-col justify-start items-start h-full p-2">+ <NConfigProvider+ v-bind="naiveUIConfig"+ class="relative flex flex-col justify-start items-start h-full p-2"+ :class="dark && 'dark bg-dark-bg'"+ ><divv-show="queryResult !== null"class="w-full flex flex-row justify-between items-center mb-2"@@ -55,9 +59,9 @@<divv-if="showPlaceholder"class="absolute inset-0 flex flex-col justify-center items-center z-10"- :class="tabStore.currentTab.isExecutingSQL && 'bg-white/80'"+ :class="loading && 'bg-white/80 dark:bg-black/80'">- <template v-if="tabStore.currentTab.isExecutingSQL">+ <template v-if="loading"><BBSpin />{{ $t("sql-editor.loading-data") }}</template>@@ -65,16 +69,19 @@{{ $t("sql-editor.table-empty-placeholder") }}</template></div>- </div>+ </NConfigProvider></template><script lang="ts" setup>-import { computed, reactive } from "vue";+import { computed, PropType, reactive } from "vue";import { useI18n } from "vue-i18n";import { debouncedRef } from "@vueuse/core";import { unparse } from "papaparse";import { isEmpty } from "lodash-es";import dayjs from "dayjs";+import { darkTheme, NConfigProvider } from "naive-ui";++import { darkThemeOverrides } from "@/../naive-ui.config";import { useTabStore, useInstanceStore } from "@/store";import { createExplainToken } from "@/utils";import DataTable from "./DataTable.vue";@@ -84,16 +91,38 @@ interface State {search: string;}+type QueryResult = [string[], string[], any[][]];++const props = defineProps({+ queryResult: {+ type: Object as PropType<QueryResult>,+ default: undefined,+ },+ loading: {+ type: Boolean,+ default: false,+ },+ dark: {+ type: Boolean,+ default: false,+ },+});+const { t } = useI18n();const tabStore = useTabStore();const instanceStore = useInstanceStore();-const queryResult = computed(() => tabStore.currentTab.queryResult || null);-const state = reactive<State>({search: "",});+const naiveUIConfig = computed(() => {+ if (props.dark) {+ return { theme: darkTheme, themeOverrides: darkThemeOverrides.value };+ }+ return {};+});+// use a debounced value to improve performance when typing rapidlyconst keyword = debouncedRef(computed(() => state.search),@@ -101,11 +130,11 @@ const keyword = debouncedRef();const columns = computed(() => {- if (!queryResult.value) {+ if (!props.queryResult) {return [];}- const columns = queryResult.value[0];+ const columns = props.queryResult[0];return columns.map((d) => {return {title: d,@@ -115,11 +144,11 @@ const columns = computed(() => {});const data = computed(() => {- if (!queryResult.value) {+ if (!props.queryResult) {return [];}- const data = queryResult.value[2];+ const data = props.queryResult[2];const search = keyword.value;let temp = data;if (search) {@@ -131,8 +160,8 @@ const data = computed(() => {});const showPlaceholder = computed(() => {- if (!queryResult.value) return true;- if (tabStore.currentTab.isExecutingSQL) return true;+ if (!props.queryResult) return true;+ if (props.loading) return true;return false;});@@ -140,12 +169,12 @@ const exportDropdownOptions = computed(() => [{label: t("sql-editor.download-as-csv"),key: "csv",- disabled: queryResult.value === null || isEmpty(queryResult.value),+ disabled: props.queryResult === null || isEmpty(props.queryResult),},{label: t("sql-editor.download-as-json"),key: "json",- disabled: queryResult.value === null || isEmpty(queryResult.value),+ disabled: props.queryResult === null || isEmpty(props.queryResult),},]);diff --git a/frontend/src/views/sql-editor/EditorCommon/index.ts b/frontend/src/views/sql-editor/EditorCommon/index.tsnew file mode 100644index 0000000000..6f565beaff--- /dev/null+++ b/frontend/src/views/sql-editor/EditorCommon/index.ts@@ -0,0 +1,17 @@+import ConnectionHolder from "./ConnectionHolder.vue";+import ConnectionPathBar from "./ConnectionPathBar.vue";+import EditorAction from "./EditorAction.vue";+import ExecutingHintModal from "./ExecutingHintModal.vue";+import SaveSheetModal from "./SaveSheetModal.vue";+import SharePopover from "./SharePopover.vue";+import TableView from "./TableView.vue";++export {+ ConnectionHolder,+ ConnectionPathBar,+ EditorAction,+ ExecutingHintModal,+ SaveSheetModal,+ SharePopover,+ TableView,+};diff --git a/frontend/src/views/sql-editor/TablePanel/useTableResize.ts b/frontend/src/views/sql-editor/EditorCommon/useTableResize.tssimilarity index 100%rename from frontend/src/views/sql-editor/TablePanel/useTableResize.tsrename to frontend/src/views/sql-editor/EditorCommon/useTableResize.tsdiff --git a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vueindex ce90045071..385811f0a0 100644--- a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue+++ b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue@@ -1,251 +1,51 @@<template><div class="flex h-full w-full flex-col justify-start items-start">- <EditorAction @save-sheet="handleSaveSheet" />+ <EditorAction @execute="handleExecute" @save-sheet="trySaveSheet" />- <div- v-if="!tabStore.isDisconnected"- class="w-full py-1 px-4 flex justify-between items-center border-b"- :class="[isProtectedEnvironment && 'bg-yellow-50']"- >- <div :class="[isProtectedEnvironment ? 'text-yellow-700' : 'text-main']">- <template v-if="isProtectedEnvironment">- {{ $t("sql-editor.sql-execute-in-protected-environment") }}- </template>- </div>-- <div class="action-right flex justify-end items-center">- <NPopover- v-if="selectedInstance.id !== UNKNOWN_ID && !hasReadonlyDataSource"- trigger="hover"- >- <template #trigger>- <heroicons-outline:exclamation- class="h-6 w-6 flex-shrink-0 mr-2"- :class="[- isProtectedEnvironment ? 'text-yellow-500' : 'text-yellow-500',- ]"- />- </template>- <p class="py-1">- {{ $t("instance.no-read-only-data-source-warn") }}- <span- class="underline text-accent cursor-pointer hover:opacity-80"- @click="gotoInstanceDetailPage"- >- {{ $t("sql-editor.create-read-only-data-source") }}- </span>- </p>- </NPopover>-- <NPopover trigger="hover" placement="bottom" :show-arrow="false">- <template #trigger>- <label class="flex items-center text-sm space-x-1">- <div- v-if="selectedInstance.id !== UNKNOWN_ID"- class="flex items-center"- >- <span class="">{{ selectedInstance.environment.name }}</span>- <ProtectedEnvironmentIcon- :environment="selectedInstance.environment"- class="ml-1"- :class="[isProtectedEnvironment && '~!text-yellow-700']"- />- </div>- <div- v-if="selectedInstance.id !== UNKNOWN_ID"- class="flex items-center"- >- <span class="mx-2">/</span>- <InstanceEngineIcon :instance="selectedInstance" show-status />- <span class="ml-2">{{ selectedInstance.name }}</span>- </div>- <div- v-if="selectedDatabase.id !== UNKNOWN_ID"- class="flex items-center"- >- <span class="mx-2">/</span>- <heroicons-outline:database />- <span class="ml-2">{{ selectedDatabase.name }}</span>- </div>- </label>- </template>- <section>- <div class="space-y-2">- <div- v-if="selectedInstance.id !== UNKNOWN_ID"- class="flex flex-col"- >- <h1 class="text-gray-400">{{ $t("common.environment") }}</h1>- <span class="flex items-center">- {{ selectedInstance.environment.name }}- <ProtectedEnvironmentIcon- :environment="selectedInstance.environment"- class="ml-1"- />- </span>- </div>- <div- v-if="selectedInstance.id !== UNKNOWN_ID"- class="flex flex-col"- >- <h1 class="text-gray-400">{{ $t("common.instance") }}</h1>- <span>{{ selectedInstance.name }}</span>- </div>- <div- v-if="selectedDatabase.id !== UNKNOWN_ID"- class="flex flex-col"- >- <h1 class="text-gray-400">{{ $t("common.database") }}</h1>- <span>{{ selectedDatabase.name }}</span>- </div>- </div>- </section>- </NPopover>- </div>- </div>+ <ConnectionPathBar /><template v-if="!tabStore.isDisconnected">- <SQLEditor @save-sheet="handleSaveSheet" />+ <SQLEditor @execute="handleExecute" @save-sheet="trySaveSheet" /></template><template v-else><ConnectionHolder /></template>- <BBModal- v-if="sqlEditorStore.isShowExecutingHint"- :title="$t('common.tips')"- @close="handleClose"- >- <ExecuteHint @close="handleClose" />- </BBModal>- <BBModal- v-if="isShowSaveSheetModal"- :title="$t('sql-editor.save-sheet')"- @close="handleCloseModal"- >- <SaveSheetModal @close="handleCloseModal" @save-sheet="handleSaveSheet" />- </BBModal>+ <ExecutingHintModal />++ <SaveSheetModal ref="saveSheetModal" /></div></template><script lang="ts" setup>-import { computed, ref } from "vue";-import { NPopover } from "naive-ui";-import { useRouter } from "vue-router";+import { ref } from "vue";-import {- useTabStore,- useSQLEditorStore,- useSheetStore,- useDatabaseStore,- useInstanceById,- useDatabaseById,-} from "@/store";-import { defaultTabName } from "@/utils/tab";-import EditorAction from "./EditorAction.vue";+import type { ExecuteConfig, ExecuteOption } from "@/types";+import { useTabStore } from "@/store";import SQLEditor from "./SQLEditor.vue";-import ExecuteHint from "./ExecuteHint.vue";-import ConnectionHolder from "./ConnectionHolder.vue";-import SaveSheetModal from "./SaveSheetModal.vue";-import type { SheetUpsert } from "@/types";-import { UNKNOWN_ID } from "@/types";-import { instanceSlug } from "@/utils";+import {+ EditorAction,+ ConnectionPathBar,+ ConnectionHolder,+ ExecutingHintModal,+ SaveSheetModal,+} from "../EditorCommon";+import { useExecuteSQL } from "@/composables/useExecuteSQL";-const router = useRouter();const tabStore = useTabStore();-const sqlEditorStore = useSQLEditorStore();-const sheetStore = useSheetStore();-const databaseStore = useDatabaseStore();--const isShowSaveSheetModal = ref(false);--const connection = computed(() => tabStore.currentTab.connection);--const selectedInstance = useInstanceById(- computed(() => connection.value.instanceId)-);-const selectedDatabase = useDatabaseById(- computed(() => connection.value.databaseId)-);-const isProtectedEnvironment = computed(() => {- const instance = selectedInstance.value;- return instance.environment.tier === "PROTECTED";-});--const hasReadonlyDataSource = computed(() => {- for (const ds of selectedInstance.value.dataSourceList) {- if (ds.type === "RO") {- return true;- }- }- return false;-});--const gotoInstanceDetailPage = () => {- const route = router.resolve({- name: "workspace.instance.detail",- params: {- instanceSlug: instanceSlug(selectedInstance.value),- },- });- window.open(route.href);-};--const allowSave = computed((): boolean => {- const tab = tabStore.currentTab;- if (tab.statement === "") {- return false;- }- if (tab.isSaved) {- return false;- }- // Temporarily disable saving and sharing if we are connected to an instance- // but not a database.- if (tab.connection.databaseId === UNKNOWN_ID) {- return false;- }- return true;-});--const handleClose = () => {- sqlEditorStore.setSQLEditorState({- isShowExecutingHint: false,- });-};--const handleSaveSheet = async (sheetName?: string) => {- if (!allowSave.value) {- return;- }-- if (tabStore.currentTab.name === defaultTabName.value && !sheetName) {- isShowSaveSheetModal.value = true;- return;- }- isShowSaveSheetModal.value = false;-- const { name, statement, sheetId } = tabStore.currentTab;- sheetName = sheetName ? sheetName : name;+const saveSheetModal = ref<InstanceType<typeof SaveSheetModal>>();- const conn = tabStore.currentTab.connection;- const database = await databaseStore.getOrFetchDatabaseById(conn.databaseId);- const sheetUpsert: SheetUpsert = {- id: sheetId,- projectId: database.project.id,- databaseId: conn.databaseId,- name: sheetName,- statement: statement,- };- const sheet = await sheetStore.upsertSheet(sheetUpsert);+const { execute } = useExecuteSQL();- tabStore.updateCurrentTab({- sheetId: sheet.id,- isSaved: true,- name: sheetName,- });+const handleExecute = (+ query: string,+ config: ExecuteConfig,+ option?: ExecuteOption+) => {+ execute(query, config, option);};-const handleCloseModal = () => {- isShowSaveSheetModal.value = false;+const trySaveSheet = (sheetName?: string) => {+ saveSheetModal.value?.trySaveSheet(sheetName);};</script>diff --git a/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue b/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vueindex c1441e2a06..464d849b63 100644--- a/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue+++ b/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue@@ -28,12 +28,17 @@ import {useSheetStore,useInstanceById,} from "@/store";-import { useExecuteSQL } from "@/composables/useExecuteSQL";import MonacoEditor from "@/components/MonacoEditor/MonacoEditor.vue";-import { SQLDialect } from "@/types";+import type { ExecuteConfig, ExecuteOption, SQLDialect } from "@/types";const emit = defineEmits<{(e: "save-sheet", content?: string): void;+ (+ e: "execute",+ sql: string,+ config: ExecuteConfig,+ option?: ExecuteOption+ ): void;}>();const instanceStore = useInstanceStore();@@ -45,8 +50,6 @@ const sheetStore = useSheetStore();const editorRef = ref<InstanceType<typeof MonacoEditor>>();-const { execute } = useExecuteSQL();-const sqlCode = computed(() => tabStore.currentTab.statement);const selectedInstance = useInstanceById(computed(() => tabStore.currentTab.connection.instanceId)@@ -120,7 +123,9 @@ const handleEditorReady = async () => {editorRef.value?.editorInstance?.getSelection() as any) as string;const query = selectedValue || typedValue || "";- await execute(query, { databaseType: selectedInstanceEngine.value });+ await emit("execute", query, {+ databaseType: selectedInstanceEngine.value,+ });},});@@ -138,7 +143,8 @@ const handleEditorReady = async () => {editorRef.value?.editorInstance?.getSelection() as any) as string;const query = selectedValue || typedValue || "";- await execute(+ await emit(+ "execute",query,{ databaseType: selectedInstanceEngine.value },{ explain: true }diff --git a/frontend/src/views/sql-editor/SQLEditorPage.vue b/frontend/src/views/sql-editor/SQLEditorPage.vueindex 4d97206b6e..4867739fce 100644--- a/frontend/src/views/sql-editor/SQLEditorPage.vue+++ b/frontend/src/views/sql-editor/SQLEditorPage.vue@@ -6,7 +6,11 @@<AsidePanel /></Pane><Pane size="80" class="relative">- <Splitpanes horizontal class="default-theme">+ <Splitpanes+ v-if="tabStore.currentTab.mode === TabMode.ReadOnly"+ horizontal+ class="default-theme"+ ><Pane :size="isDisconnected ? 100 : 60"><EditorPanel /></Pane>@@ -14,6 +18,9 @@<TablePanel /></Pane></Splitpanes>++ <TerminalPanel v-if="tabStore.currentTab.mode === TabMode.Admin" />+<divv-if="isFetchingSheet"class="flex items-center justify-center absolute inset-0 bg-white/50 z-20"@@ -27,13 +34,15 @@<script lang="ts" setup>import { computed } from "vue";+import { Splitpanes, Pane } from "splitpanes";++import { TabMode } from "@/types";import { useSQLEditorStore, useTabStore } from "@/store";import AsidePanel from "./AsidePanel/AsidePanel.vue";import EditorPanel from "./EditorPanel/EditorPanel.vue";+import TerminalPanel from "./TerminalPanel/TerminalPanel.vue";import TabList from "./TabList";import TablePanel from "./TablePanel/TablePanel.vue";-import { Splitpanes, Pane } from "splitpanes";-import "splitpanes/dist/splitpanes.css";const tabStore = useTabStore();const sqlEditorStore = useSQLEditorStore();@@ -43,6 +52,8 @@ const isFetchingSheet = computed(() => sqlEditorStore.isFetchingSheet);</script><style>+@import "splitpanes/dist/splitpanes.css";+/* splitpanes pane style */.splitpanes.default-theme .splitpanes__pane {@apply bg-transparent;diff --git a/frontend/src/views/sql-editor/TablePanel/TablePanel.vue b/frontend/src/views/sql-editor/TablePanel/TablePanel.vueindex 7a5e678beb..cda02d0631 100644--- a/frontend/src/views/sql-editor/TablePanel/TablePanel.vue+++ b/frontend/src/views/sql-editor/TablePanel/TablePanel.vue@@ -1,12 +1,19 @@<template>- <Splitpanes class="default-theme">- <Pane size="100">- <TableView />- </Pane>- </Splitpanes>+ <TableView+ class="w-full h-full"+ :query-result="queryResult"+ :loading="loading"+ /></template><script lang="ts" setup>-import TableView from "./TableView.vue";-import { Splitpanes, Pane } from "splitpanes";+import { computed } from "vue";++import { TableView } from "../EditorCommon/";+import { useTabStore } from "@/store";++const tabStore = useTabStore();++const queryResult = computed(() => tabStore.currentTab.queryResult);+const loading = computed(() => tabStore.currentTab.isExecutingSQL);</script>diff --git a/frontend/src/views/sql-editor/TerminalPanel/CompactSQLEditor.vue b/frontend/src/views/sql-editor/TerminalPanel/CompactSQLEditor.vuenew file mode 100644index 0000000000..fc382dc5ef--- /dev/null+++ b/frontend/src/views/sql-editor/TerminalPanel/CompactSQLEditor.vue@@ -0,0 +1,205 @@+<template>+ <div class="whitespace-pre-wrap w-full overflow-hidden">+ <MonacoEditor+ ref="editorRef"+ class="w-full h-auto max-h-[360px]"+ :value="sql"+ :dialect="selectedDialect"+ :readonly="readonly"+ :options="{+ theme: 'bb-dark',+ minimap: {+ enabled: false,+ },+ scrollbar: {+ vertical: 'hidden',+ horizontal: 'hidden',+ alwaysConsumeMouseWheel: false,+ },+ overviewRulerLanes: 0,+ lineNumbers: getLineNumber,+ lineNumbersMinChars: 5,+ glyphMargin: false,+ cursorStyle: 'block',+ }"+ @change="handleChange"+ @change-selection="handleChangeSelection"+ @save="handleSaveSheet"+ @ready="handleEditorReady"+ />+ </div>+</template>++<script lang="ts" setup>+import { computed, nextTick, ref, watch, watchEffect } from "vue";++import {+ useInstanceStore,+ useTabStore,+ useSQLEditorStore,+ useDatabaseStore,+ useTableStore,+ useInstanceById,+} from "@/store";+import MonacoEditor from "@/components/MonacoEditor/MonacoEditor.vue";+import { ExecuteConfig, ExecuteOption, SQLDialect } from "@/types";++const props = defineProps({+ sql: {+ type: String,+ default: "",+ },+ readonly: {+ type: Boolean,+ default: false,+ },+});++const emit = defineEmits<{+ (e: "save-sheet", content?: string): void;+ (e: "update:sql", sql: string): void;+ (+ e: "execute",+ sql: string,+ config: ExecuteConfig,+ option?: ExecuteOption+ ): void;+}>();++const MIN_EDITOR_HEIGHT = 40; // ~= 1 line++const instanceStore = useInstanceStore();+const tabStore = useTabStore();+const databaseStore = useDatabaseStore();+const tableStore = useTableStore();+const sqlEditorStore = useSQLEditorStore();++const editorRef = ref<InstanceType<typeof MonacoEditor>>();++const selectedInstance = useInstanceById(+ computed(() => tabStore.currentTab.connection.instanceId)+);+const selectedInstanceEngine = computed(() => {+ return instanceStore.formatEngine(selectedInstance.value);+});+const selectedDialect = computed((): SQLDialect => {+ const engine = selectedInstanceEngine.value;+ if (engine === "PostgreSQL") {+ return "postgresql";+ }+ return "mysql";+});+const currentTabId = computed(() => tabStore.currentTabId);+const isSwitchingTab = ref(false);++watch(currentTabId, () => {+ isSwitchingTab.value = true;+ nextTick(() => {+ isSwitchingTab.value = false;+ });+});++watch(+ () => sqlEditorStore.shouldFormatContent,+ () => {+ if (sqlEditorStore.shouldFormatContent) {+ editorRef.value?.formatEditorContent();+ sqlEditorStore.setShouldFormatContent(false);+ }+ }+);++const getLineNumber = (lineNumber: number) => {+ /*+ Show a SQL CLI like command prompt.+ SQL> first_line+ -> second_line+ -> more_lines+ */+ if (lineNumber === 1) return "SQL>";+ return "->";+};++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,+ });++ emit("update:sql", value);+ updateEditorHeight();+};++const handleChangeSelection = (value: string) => {+ tabStore.updateCurrentTab({+ selectedStatement: value,+ });+};++const handleSaveSheet = () => {+ emit("save-sheet");+};++const handleEditorReady = async () => {+ const monaco = await import("monaco-editor");+ const editor = editorRef.value?.editorInstance;+ editor?.addAction({+ id: "RunQuery",+ label: "Run Query",+ keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter],+ contextMenuGroupId: "operation",+ contextMenuOrder: 0,+ run: async () => {+ emit("execute", props.sql, {+ databaseType: selectedInstanceEngine.value,+ });+ },+ });++ editor?.addAction({+ id: "ExplainQuery",+ label: "Explain Query",+ keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyE],+ contextMenuGroupId: "operation",+ contextMenuOrder: 0,+ run: async () => {+ emit(+ "execute",+ props.sql,+ { databaseType: selectedInstanceEngine.value },+ { explain: true }+ );+ },+ });++ watchEffect(() => {+ if (selectedInstance.value) {+ const databaseList = databaseStore.getDatabaseListByInstanceId(+ selectedInstance.value.id+ );+ const tableList = databaseList+ .map((item) => tableStore.getTableListByDatabaseId(item.id))+ .flat();++ editorRef.value?.setEditorAutoCompletionContext(databaseList, tableList);+ }+ });++ updateEditorHeight();+};++const updateEditorHeight = () => {+ const contentHeight =+ editorRef.value?.editorInstance?.getContentHeight() as number;+ let actualHeight = contentHeight;+ if (actualHeight < MIN_EDITOR_HEIGHT) {+ actualHeight = MIN_EDITOR_HEIGHT;+ }+ editorRef.value?.setEditorContentHeight(actualHeight);+};+</script>diff --git a/frontend/src/views/sql-editor/TerminalPanel/TerminalPanel.vue b/frontend/src/views/sql-editor/TerminalPanel/TerminalPanel.vuenew file mode 100644index 0000000000..d994b83e29--- /dev/null+++ b/frontend/src/views/sql-editor/TerminalPanel/TerminalPanel.vue@@ -0,0 +1,127 @@+<template>+ <div+ class="flex h-full w-full flex-col justify-start items-start overflow-hidden"+ >+ <EditorAction @execute="handleExecute" @save-sheet="trySaveSheet" />++ <ConnectionPathBar />++ <div+ v-if="!tabStore.isDisconnected"+ ref="queryListContainerRef"+ class="w-full flex-1 overflow-y-auto bg-dark-bg"+ >+ <div+ ref="queryListRef"+ class="w-full flex flex-col"+ :data-height="queryListHeight"+ >+ <div v-for="(query, i) in queryList" :key="i" class="relative">+ <CompactSQLEditor+ v-model:sql="query.sql"+ class="border-b min-h-[2rem]"+ :readonly="query !== currentQuery"+ @save-sheet="trySaveSheet"+ @execute="handleExecute"+ />+ <div+ v-if="query.queryResult"+ class="max-h-[20rem] overflow-y-auto border-b"+ >+ <TableView+ :query-result="query.queryResult.data"+ :loading="query.isExecutingSQL"+ :dark="true"+ />+ </div>++ <div+ v-if="query.isExecutingSQL"+ class="absolute inset-0 bg-black/20 flex justify-center items-center"+ >+ <BBSpin />+ </div>+ </div>+ </div>+ </div>+ <ConnectionHolder v-else />++ <SaveSheetModal ref="saveSheetModal" />+ </div>+</template>++<script lang="ts" setup>+import { computed, ref, watch } from "vue";+import { useElementSize } from "@vueuse/core";++import { ExecuteConfig, ExecuteOption } from "@/types";+import { useTabStore, useWebTerminalStore } from "@/store";+import CompactSQLEditor from "./CompactSQLEditor.vue";+import {+ EditorAction,+ ConnectionPathBar,+ ConnectionHolder,+ TableView,+ SaveSheetModal,+} from "../EditorCommon";+import { useExecuteSQL } from "@/composables/useExecuteSQL";++const tabStore = useTabStore();+const webTerminalStore = useWebTerminalStore();++const queryList = computed(() => {+ return webTerminalStore.getQueryListByTab(tabStore.currentTab);+});++const queryListContainerRef = ref<HTMLDivElement>();+const queryListRef = ref<HTMLDivElement>();++const currentQuery = computed(+ () => queryList.value[queryList.value.length - 1]+);++const { execute } = useExecuteSQL();++const handleExecute = async (+ query: string,+ config: ExecuteConfig,+ option?: ExecuteOption+) => {+ const queryItem = currentQuery.value;+ if (queryItem.isExecutingSQL) {+ return;+ }++ try {+ queryItem.executeParams = { query, config, option };+ queryItem.isExecutingSQL = true;+ const sqlResultSet = await execute(query, config, option);++ queryItem.queryResult = sqlResultSet;+ queryList.value.push({+ sql: "",+ isExecutingSQL: false,+ });+ } finally {+ queryItem.isExecutingSQL = false;+ }+};++const saveSheetModal = ref<InstanceType<typeof SaveSheetModal>>();++const trySaveSheet = (sheetName?: string) => {+ saveSheetModal.value?.trySaveSheet(sheetName);+};++const { height: queryListHeight } = useElementSize(queryListRef);++watch(queryListHeight, () => {+ // Always scroll to the bottom as if we are in a real terminal.+ requestAnimationFrame(() => {+ const container = queryListContainerRef.value;+ if (container) {+ container.scrollTo(0, container.scrollHeight);+ }+ });+});+</script>diff --git a/frontend/tailwind.config.js b/frontend/tailwind.config.jsindex 3fdca4fa72..a39bc4dfab 100644--- a/frontend/tailwind.config.js+++ b/frontend/tailwind.config.js@@ -97,6 +97,7 @@ module.exports = {},},},+ darkMode: "class",variants: {extend: {ringWidth: ["focus-visible"],