mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-02 04:23:57 +00:00
#938 current database is not changed after closing tab
This commit is contained in:
@@ -92,7 +92,7 @@ export const openedConnections = writable([]);
|
|||||||
export const temporaryOpenedConnections = writable([]);
|
export const temporaryOpenedConnections = writable([]);
|
||||||
export const openedSingleDatabaseConnections = writable([]);
|
export const openedSingleDatabaseConnections = writable([]);
|
||||||
export const expandedConnections = writable([]);
|
export const expandedConnections = writable([]);
|
||||||
export const currentDatabase = writable(null);
|
export const currentDatabase = writableWithForage(null, 'currentDatabase');
|
||||||
export const openedTabs = writableWithForage<TabDefinition[]>([], getOpenedTabsStorageName(), x => [...(x || [])]);
|
export const openedTabs = writableWithForage<TabDefinition[]>([], getOpenedTabsStorageName(), x => [...(x || [])]);
|
||||||
export const copyRowsFormat = writableWithStorage('textWithoutHeaders', 'copyRowsFormat');
|
export const copyRowsFormat = writableWithStorage('textWithoutHeaders', 'copyRowsFormat');
|
||||||
export const extensions = writable<ExtensionsDirectory>(null);
|
export const extensions = writable<ExtensionsDirectory>(null);
|
||||||
|
|||||||
@@ -295,6 +295,7 @@
|
|||||||
import CloseTabModal from '../modals/CloseTabModal.svelte';
|
import CloseTabModal from '../modals/CloseTabModal.svelte';
|
||||||
import SwitchDatabaseModal from '../modals/SwitchDatabaseModal.svelte';
|
import SwitchDatabaseModal from '../modals/SwitchDatabaseModal.svelte';
|
||||||
import { getConnectionLabel } from 'dbgate-tools';
|
import { getConnectionLabel } from 'dbgate-tools';
|
||||||
|
import { changeDatabaseByCurrentTab } from '../utility/changeCurrentDbByTab';
|
||||||
|
|
||||||
export let multiTabIndex;
|
export let multiTabIndex;
|
||||||
export let shownTab;
|
export let shownTab;
|
||||||
@@ -334,6 +335,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setSelectedTab(tabid);
|
setSelectedTab(tabid);
|
||||||
|
changeDatabaseByCurrentTab();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleMouseDown = (e, tabid) => {
|
const handleMouseDown = (e, tabid) => {
|
||||||
|
|||||||
@@ -1,24 +1,41 @@
|
|||||||
import _ from 'lodash';
|
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 { shouldShowTab } from '../tabpanel/TabsPanel.svelte';
|
||||||
import { callWhenAppLoaded, getAppLoaded } from './appLoadManager';
|
import { callWhenAppLoaded, getAppLoaded } from './appLoadManager';
|
||||||
import { getConnectionInfo } from './metadataLoaders';
|
import { getConnectionInfo } from './metadataLoaders';
|
||||||
import { switchCurrentDatabase } from './common';
|
import { switchCurrentDatabase } from './common';
|
||||||
|
|
||||||
let lastCurrentTab = null;
|
// let lastCurrentTab = null;
|
||||||
|
|
||||||
openedTabs.subscribe(value => {
|
// openedTabs.subscribe(value => {
|
||||||
const newCurrentTab = (value || []).find(x => x.selected);
|
// const newCurrentTab = (value || []).find(x => x.selected);
|
||||||
if (newCurrentTab == lastCurrentTab) return;
|
// if (newCurrentTab == lastCurrentTab) return;
|
||||||
if (getLockedDatabaseMode() && getCurrentDatabase()) return;
|
// if (getLockedDatabaseMode() && getCurrentDatabase()) return;
|
||||||
|
|
||||||
const lastTab = lastCurrentTab;
|
// const lastTab = lastCurrentTab;
|
||||||
lastCurrentTab = newCurrentTab;
|
// lastCurrentTab = newCurrentTab;
|
||||||
// if (lastTab?.tabComponent == 'ConnectionTab') return;
|
// // if (lastTab?.tabComponent == 'ConnectionTab') return;
|
||||||
|
|
||||||
if (newCurrentTab) {
|
// if (newCurrentTab) {
|
||||||
const { conid, database } = newCurrentTab.props || {};
|
// const { conid, database } = newCurrentTab.props || {};
|
||||||
if (conid && database && (conid != lastTab?.props?.conid || database != lastTab?.props?.database)) {
|
// 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 doWork = async () => {
|
||||||
const connection = await getConnectionInfo({ conid });
|
const connection = await getConnectionInfo({ conid });
|
||||||
switchCurrentDatabase({
|
switchCurrentDatabase({
|
||||||
@@ -29,7 +46,6 @@ openedTabs.subscribe(value => {
|
|||||||
callWhenAppLoaded(doWork);
|
callWhenAppLoaded(doWork);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
currentDatabase.subscribe(currentDb => {
|
currentDatabase.subscribe(currentDb => {
|
||||||
if (!getLockedDatabaseMode()) return;
|
if (!getLockedDatabaseMode()) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user