change current db by tab

This commit is contained in:
Jan Prochazka
2021-03-01 18:37:15 +01:00
parent a4387155e7
commit 689eb7baa2
2 changed files with 26 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
import _ from 'lodash';
import { currentDatabase, openedTabs } from '../stores';
let lastCurrentTab = null;
openedTabs.subscribe(value => {
const newCurrentTab = (value || []).find(x => x.selected);
if (newCurrentTab == lastCurrentTab) return;
if (newCurrentTab) {
const { conid, database } = newCurrentTab.props || {};
if (
conid &&
database &&
(conid != _.get(lastCurrentTab, 'props.conid') || database != _.get(lastCurrentTab, 'props.database'))
) {
currentDatabase.set({
connection: { _id: conid },
name: database,
});
}
}
lastCurrentTab = newCurrentTab;
});