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: allow change connection for unsaved sheet (#11069)
ecmadao8849a1c881ac
diff --git a/frontend/src/store/modules/tab.ts b/frontend/src/store/modules/tab.tsindex 695ab8dec6..202c77d131 100644--- a/frontend/src/store/modules/tab.ts+++ b/frontend/src/store/modules/tab.ts@@ -5,7 +5,6 @@ import { computed, reactive, ref, toRef, watch } from "vue";import { TabInfo, CoreTabInfo, AnyTabInfo, TabMode } from "@/types";import {getDefaultTab,- INITIAL_TAB,isTempTab,isSimilarTab,WebStorageHelper,@@ -178,19 +177,13 @@ export const useTabStore = defineStore("tab", () => {const init = () => {// Load tabIdList and currentTabIdtabIdList.value = storage.load(KEYS.tabIdList, []);- currentTabId.value = storage.load(KEYS.currentTabId, INITIAL_TAB.id);+ currentTabId.value = storage.load(KEYS.currentTabId, "");if (tabIdList.value.indexOf(currentTabId.value) < 0) {// currentTabId is not in tabIdList accidentally// fallback to the first tabcurrentTabId.value = tabIdList.value[0];}- // Fallback to the initial tab if tabIdList is empty.- if (tabIdList.value.length === 0) {- // tabIdList is empty accidentally- tabIdList.value = [INITIAL_TAB.id];- }-// Load tab detailstabIdList.value.forEach((id) => {const tabPartial = storage.load<PersistentTabInfo | undefined>(diff --git a/frontend/src/utils/tab.ts b/frontend/src/utils/tab.tsindex 806bd8c681..ccedaf9d1b 100644--- a/frontend/src/utils/tab.ts+++ b/frontend/src/utils/tab.ts@@ -43,8 +43,6 @@ export const getDefaultTab = (): TabInfo => {};};-export const INITIAL_TAB = getDefaultTab();-export const isTempTab = (tab: TabInfo): boolean => {if (tab.sheetName) return false;if (!tab.isSaved) return false;@@ -135,9 +133,12 @@ export const tryConnectToCoreTab = (tab: CoreTabInfo) => {// Don't go further if the connection doesn't change.return;}- if (tabStore.currentTab.isFreshNew) {- // If the current tab is "fresh new", update its connection directly.- tabStore.updateCurrentTab(tab);+ if (tabStore.currentTab.isFreshNew || !tabStore.currentTab.sheetName) {+ // If the current tab is "fresh new" or unsaved, update its connection directly.+ tabStore.updateCurrentTab({+ ...tab,+ name: getSuggestedTabNameFromConnection(tab.connection),+ });} else {// Otherwise select or add a new tab and set its connection.const name = getSuggestedTabNameFromConnection(tab.connection);diff --git a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vueindex d2cfde649b..5c3c248c5b 100644--- a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue+++ b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue@@ -445,9 +445,13 @@ const selectAllFromTableOrView = async (node: SQLEditorTreeNode) => {},mode: TabMode.ReadOnly,};- if (tabStore.currentTab.isFreshNew) {- // If the current tab is "fresh new", update its connection directly.- tabStore.updateCurrentTab(tab);+ if (tabStore.currentTab.isFreshNew || !tabStore.currentTab.sheetName) {+ // If the current tab is "fresh new" or unsaved, update its connection directly.+ tabStore.updateCurrentTab({+ ...tab,+ name: getSuggestedTabNameFromConnection(tab.connection),+ statement: tabStore.currentTab.statement || query,+ });} else {// Otherwise select or add a new tab and set its connectiontabStore.addTab(@@ -677,6 +681,7 @@ watch(}if (databaseId !== String(UNKNOWN_ID)) {const db = databaseStore.getDatabaseByUID(databaseId);+ treeStore.expandNodes("project", db.projectEntity);treeStore.expandNodes("database", db);}},