mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-23 01:06:01 +00:00
#938 current database is not changed after closing tab
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user