Skip to content

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

chore: support close all tabs (#11042)

ecmadaoad42dcb87587
diff --git a/frontend/src/store/modules/tab.ts b/frontend/src/store/modules/tab.ts
index ee3cc8d371..695ab8dec6 100644
--- a/frontend/src/store/modules/tab.ts
+++ b/frontend/src/store/modules/tab.ts
@@ -285,17 +285,3 @@ const maybeMigrateLegacyTab = (
}
return tab;
};
-
-export const isTabClosable = (tab: TabInfo) => {
- const { tabList } = useTabStore();
-
- if (tabList.length > 1) {
- // Not the only one tab
- return true;
- }
- if (tabList.length === 1) {
- // It's the only one tab, and it's closable if it's a sheet tab
- return !!tab.sheetName;
- }
- return false;
-};
diff --git a/frontend/src/utils/tab.ts b/frontend/src/utils/tab.ts
index f5dbb378a5..806bd8c681 100644
--- a/frontend/src/utils/tab.ts
+++ b/frontend/src/utils/tab.ts
@@ -122,7 +122,16 @@ export const isDisconnectedTab = (tab: TabInfo) => {
export const tryConnectToCoreTab = (tab: CoreTabInfo) => {
const tabStore = useTabStore();
- if (isSimilarTab(tab, tabStore.currentTab)) {
+
+ if (!tabStore.currentTabId) {
+ tabStore.addTab({
+ name: getSuggestedTabNameFromConnection(tab.connection),
+ connection: tab.connection,
+ // The newly created tab is "clean" so its connection can be changed
+ isFreshNew: true,
+ });
+ return;
+ } else if (isSimilarTab(tab, tabStore.currentTab)) {
// Don't go further if the connection doesn't change.
return;
}
diff --git a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue
index 74a5d36bef..d2cfde649b 100644
--- a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue
@@ -192,7 +192,7 @@ const dropdownOptions = computed((): DropdownOptionWithTreeNode[] => {
items.push({
key: "connect-in-admin-mode",
label: t("sql-editor.connect-in-admin-mode"),
- onSelect: () => setConnection(node, { mode: TabMode.Admin }),
+ onSelect: () => setConnection(node, TabMode.Admin),
});
}
}
@@ -309,10 +309,7 @@ const allowAdmin = computed(() =>
const setConnection = (
node: SQLEditorTreeNode,
- extra: { sheetName?: string; mode: TabMode } = {
- sheetName: undefined,
- mode: TabMode.ReadOnly,
- }
+ mode: TabMode = TabMode.ReadOnly
) => {
if (node) {
const { type } = node.meta;
@@ -327,7 +324,7 @@ const setConnection = (
}
const coreTab: CoreTabInfo = {
connection: emptyConnection(),
- ...extra,
+ mode,
};
const conn = coreTab.connection;
// If selected item is instance node
diff --git a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue
index e052cab212..ffd30b30c9 100644
--- a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue
@@ -3,18 +3,20 @@
<template v-if="tab.editMode === 'SQL-EDITOR'">
<EditorAction @execute="handleExecute" />
- <ConnectionPathBar />
-
- <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>
+ <ConnectionHolder v-if="tabStore.isDisconnected" />
+ <template v-else>
+ <ConnectionPathBar />
+ <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>
</template>
<Suspense>
@@ -48,6 +50,7 @@ import {
ConnectionPathBar,
ExecutingHintModal,
SaveSheetModal,
+ ConnectionHolder,
} from "../EditorCommon";
import { useSQLEditorContext } from "../context";
diff --git a/frontend/src/views/sql-editor/SecondarySidebar/SheetTabPane/SheetList/SheetList.vue b/frontend/src/views/sql-editor/SecondarySidebar/SheetTabPane/SheetList/SheetList.vue
index fb9b3abf2f..f076cc1fd0 100644
--- a/frontend/src/views/sql-editor/SecondarySidebar/SheetTabPane/SheetList/SheetList.vue
+++ b/frontend/src/views/sql-editor/SecondarySidebar/SheetTabPane/SheetList/SheetList.vue
@@ -140,21 +140,8 @@ const mergedItemList = computed(() => {
return [];
}
- const { tabList } = tabStore;
const mergedList: MergedItem[] = [];
- if (props.view === "my") {
- // Tabs go ahead
- tabList.forEach((tab) => {
- if (!tab.sheetName) {
- mergedList.push({
- type: "TAB",
- target: tab,
- });
- }
- });
- }
- // Sheets follow
sheetList.value.forEach((sheet) => {
mergedList.push({
type: "SHEET",
diff --git a/frontend/src/views/sql-editor/TabList/TabItem/Suffix.vue b/frontend/src/views/sql-editor/TabList/TabItem/Suffix.vue
index 3c4ee780ca..b7e3d87a81 100644
--- a/frontend/src/views/sql-editor/TabList/TabItem/Suffix.vue
+++ b/frontend/src/views/sql-editor/TabList/TabItem/Suffix.vue
@@ -4,7 +4,7 @@
:class="[
{
admin: tab.mode === TabMode.Admin,
- closable,
+ closable: true,
},
[sheetTypeForTab(tab).toLowerCase()],
@@ -24,7 +24,6 @@
<script lang="ts" setup>
import { computed, PropType, reactive } from "vue";
-import { isTabClosable } from "@/store";
import type { TabInfo } from "@/types";
import { TabMode } from "@/types";
import { sheetTypeForTab } from "@/utils";
@@ -54,12 +53,8 @@ defineEmits<{
(e: "close", tab: TabInfo, index: number): void;
}>();
-const closable = computed(() => {
- return isTabClosable(props.tab);
-});
-
const icon = computed((): IconType | undefined => {
- if (state.hovering && closable.value) {
+ if (state.hovering) {
return "close";
}
if (props.tab.mode === TabMode.ReadOnly && !props.tab.isSaved) {
@@ -77,6 +72,10 @@ const icon = computed((): IconType | undefined => {
@apply block w-5 h-5 p-0.5 text-gray-500 rounded;
}
+.suffix.closable {
+ cursor: pointer;
+}
+
.suffix.closable.temp .icon {
@apply text-accent;
}
diff --git a/frontend/src/views/sql-editor/TabList/TabList.vue b/frontend/src/views/sql-editor/TabList/TabList.vue
index 0841ebc6e4..c61f842a78 100644
--- a/frontend/src/views/sql-editor/TabList/TabList.vue
+++ b/frontend/src/views/sql-editor/TabList/TabList.vue
@@ -129,8 +129,8 @@ const filteredTabIdList = computed(() => {
return tabStore.tabIdList;
});
-const handleSelectTab = async (tab: TabInfo) => {
- tabStore.setCurrentTabId(tab.id);
+const handleSelectTab = async (tab: TabInfo | undefined) => {
+ tabStore.setCurrentTabId(tab?.id ?? "");
};
const handleAddTab = () => {
@@ -183,11 +183,6 @@ const handleRemoveTab = async (
}
function remove(index: number) {
- if (tabStore.tabList.length === 1) {
- // Ensure at least 1 tab
- tabStore.addTab();
- }
-
tabStore.removeTab(tab);
// select a tab near the removed tab.