fix(desktop): close database tabs with connection
This commit is contained in:
1 parent
b9fa36763e
commit
b4c469a69f
3 files changed
+78
No files matched your search
@@ -1478,6 +1478,7 @@ async function closeDatabaseConnection() {
|
||||
if (node.type !== "database" || !node.connectionId || node.database == null) return;
|
||||
try {
|
||||
await connectionStore.closeDatabaseConnection(node.connectionId, node.database);
|
||||
queryStore.closeDatabaseTabs(node.connectionId, node.database);
|
||||
toast(t("connection.databaseConnectionClosed", { name: node.label }), 2000);
|
||||
} catch (e: any) {
|
||||
toast(t("connection.saveFailed", { message: e?.message || String(e) }), 5000);
|
||||
|
||||
@@ -303,6 +303,32 @@ export const useQueryStore = defineStore("query", () => {
|
||||
activeTabId.value = next.activeTabId;
|
||||
}
|
||||
|
||||
function closeDatabaseTabs(connectionId: string, database: string) {
|
||||
const closingModes = new Set<QueryTab["mode"]>(["data", "objects", "structure", "mongo"]);
|
||||
const closingIds = new Set(
|
||||
tabs.value
|
||||
.filter((tab) => tab.connectionId === connectionId && tab.database === database && closingModes.has(tab.mode))
|
||||
.map((tab) => tab.id),
|
||||
);
|
||||
if (closingIds.size === 0) return;
|
||||
|
||||
tabs.value
|
||||
.filter((tab) => closingIds.has(tab.id))
|
||||
.forEach((tab) => {
|
||||
if (tab.isExecuting) void cancelTabExecution(tab.id);
|
||||
if (tab.isExplaining) void cancelTabExplain(tab.id);
|
||||
void closeResultSession(tab);
|
||||
void closeClientConnectionSession(tab);
|
||||
clearResultPayload(tab);
|
||||
});
|
||||
|
||||
const activeClosingIndex = tabs.value.findIndex((tab) => tab.id === activeTabId.value && closingIds.has(tab.id));
|
||||
tabs.value = tabs.value.filter((tab) => !closingIds.has(tab.id));
|
||||
if (activeClosingIndex >= 0) {
|
||||
activeTabId.value = tabs.value[Math.min(activeClosingIndex, tabs.value.length - 1)]?.id ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
function updateSql(id: string, sql: string) {
|
||||
const tab = tabs.value.find((t) => t.id === id);
|
||||
if (tab) {
|
||||
@@ -1221,6 +1247,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
closeTab,
|
||||
closeOtherTabs,
|
||||
closeAllTabs,
|
||||
closeDatabaseTabs,
|
||||
updateSql,
|
||||
renameTab,
|
||||
openObjectBrowser,
|
||||
|
||||
Reference in new issue
Block a user