#938 current database is not changed after closing tab

This commit is contained in:
SPRINX0\prochazka
2024-11-21 15:03:43 +01:00
parent c6cd865663
commit dc18be07ce
3 changed files with 41 additions and 23 deletions

View File

@@ -1,35 +1,51 @@
import _ from 'lodash';
import { currentDatabase, getCurrentDatabase, getLockedDatabaseMode, openedTabs } from '../stores';
import { currentDatabase, getActiveTab, getCurrentDatabase, getLockedDatabaseMode, openedTabs } from '../stores';
import { shouldShowTab } from '../tabpanel/TabsPanel.svelte';
import { callWhenAppLoaded, getAppLoaded } from './appLoadManager';
import { getConnectionInfo } from './metadataLoaders';
import { switchCurrentDatabase } from './common';
let lastCurrentTab = null;
// let lastCurrentTab = null;
openedTabs.subscribe(value => {
const newCurrentTab = (value || []).find(x => x.selected);
if (newCurrentTab == lastCurrentTab) return;
if (getLockedDatabaseMode() && getCurrentDatabase()) return;
// openedTabs.subscribe(value => {
// const newCurrentTab = (value || []).find(x => x.selected);
// if (newCurrentTab == lastCurrentTab) return;
// if (getLockedDatabaseMode() && getCurrentDatabase()) return;
const lastTab = lastCurrentTab;
lastCurrentTab = newCurrentTab;
// if (lastTab?.tabComponent == 'ConnectionTab') return;
// const lastTab = lastCurrentTab;
// lastCurrentTab = newCurrentTab;
// // if (lastTab?.tabComponent == 'ConnectionTab') return;
if (newCurrentTab) {
const { conid, database } = newCurrentTab.props || {};
if (conid && database && (conid != lastTab?.props?.conid || database != lastTab?.props?.database)) {
const doWork = async () => {
const connection = await getConnectionInfo({ conid });
switchCurrentDatabase({
connection,
name: database,
});
};
callWhenAppLoaded(doWork);
}
// if (newCurrentTab) {
// const { conid, database } = newCurrentTab.props || {};
// if (conid && database && (conid != lastTab?.props?.conid || database != lastTab?.props?.database)) {
// const doWork = async () => {
// const connection = await getConnectionInfo({ conid });
// switchCurrentDatabase({
// connection,
// name: database,
// });
// };
// callWhenAppLoaded(doWork);
// }
// }
// });
export function changeDatabaseByCurrentTab() {
const currentTab = getActiveTab();
const { conid, database } = currentTab?.props || {};
const db = getCurrentDatabase();
if (conid && database && (conid != db?.connection?._id || database != db?.name)) {
const doWork = async () => {
const connection = await getConnectionInfo({ conid });
switchCurrentDatabase({
connection,
name: database,
});
};
callWhenAppLoaded(doWork);
}
});
}
currentDatabase.subscribe(currentDb => {
if (!getLockedDatabaseMode()) return;