single database mode

This commit is contained in:
Jan Prochazka
2022-12-23 11:03:03 +01:00
parent 45652cfc33
commit fa13990189
9 changed files with 154 additions and 78 deletions

View File

@@ -1,5 +1,6 @@
import _ from 'lodash';
import { currentDatabase, openedTabs } from '../stores';
import { currentDatabase, getCurrentDatabase, getSingleDatabaseMode, openedTabs } from '../stores';
import { shouldShowTab } from '../widgets/TabsPanel.svelte';
import { callWhenAppLoaded } from './appLoadManager';
import { getConnectionInfo } from './metadataLoaders';
@@ -8,6 +9,7 @@ let lastCurrentTab = null;
openedTabs.subscribe(value => {
const newCurrentTab = (value || []).find(x => x.selected);
if (newCurrentTab == lastCurrentTab) return;
if (getSingleDatabaseMode() && getCurrentDatabase()) return;
const lastTab = lastCurrentTab;
lastCurrentTab = newCurrentTab;
@@ -27,3 +29,22 @@ openedTabs.subscribe(value => {
}
}
});
currentDatabase.subscribe(currentDb => {
if (!getSingleDatabaseMode()) return;
openedTabs.update(tabs => {
const newTabs = tabs.map(tab => ({
...tab,
selected: tab.selected && shouldShowTab(tab, true, currentDb),
}));
if (newTabs.find(x => x.selected)) return newTabs;
const selectedIndex = _.findLastIndex(newTabs, x => shouldShowTab(x));
return newTabs.map((x, index) => ({
...x,
selected: index == selectedIndex,
}));
});
});