diff --git a/packages/web/src/TabsPanel.js b/packages/web/src/TabsPanel.js
index 86f1bc3c8..cc2f34d5b 100644
--- a/packages/web/src/TabsPanel.js
+++ b/packages/web/src/TabsPanel.js
@@ -4,9 +4,10 @@ import styled from 'styled-components';
import theme from './theme';
import { DropDownMenuItem, DropDownMenuDivider } from './modals/DropDownMenu';
-import { useOpenedTabs, useSetOpenedTabs } from './utility/globalState';
+import { useOpenedTabs, useSetOpenedTabs, useCurrentDatabase, useSetCurrentDatabase } from './utility/globalState';
import { getIconImage } from './icons';
import { showMenu } from './modals/DropDownMenu';
+import { getConnectionInfo } from './utility/metadataLoaders';
// const files = [
// { name: 'app.js' },
@@ -14,6 +15,31 @@ import { showMenu } from './modals/DropDownMenu';
// { name: 'ApplicationList' },
// ];
+const DbGroupHandler = styled.div`
+ display: flex;
+ flex: 1;
+`;
+
+const DbWrapperHandler = styled.div`
+ display: flex;
+ flex-direction: column;
+`;
+
+const DbNameWrapper = styled.div`
+ text-align: center;
+ font-size: 8pt;
+ border-top: 1px solid #ccc;
+ border-right: 1px solid white;
+ cursor: pointer;
+ user-select: none;
+ &:hover {
+ background-color: #aaa;
+ }
+ background-color: ${(props) =>
+ // @ts-ignore
+ props.selected ? theme.mainArea.background : 'inherit'};
+`;
+
const FileTabItem = styled.div`
border-right: 1px solid white;
padding-left: 15px;
@@ -64,8 +90,16 @@ function TabContextMenu({ close, closeAll, closeOthers, closeWithSameDb, closeWi
}
export default function TabsPanel() {
+ const noDbKey = '_no';
+ const formatDbKey = (conid, database) => `${database}-${conid}`;
+
const tabs = useOpenedTabs();
const setOpenedTabs = useSetOpenedTabs();
+ const currentDb = useCurrentDatabase();
+ const setCurrentDb = useSetCurrentDatabase();
+
+ const { name, connection } = currentDb || {};
+ const currentDbKey = name && connection ? formatDbKey(connection._id, name) : noDbKey;
const handleTabClick = (e, tabid) => {
if (e.target.closest('.tabCloseButton')) {
@@ -134,28 +168,61 @@ export default function TabsPanel() {
// 't',
// tabs.map(x => x.tooltip)
// );
+ const tabsWithDb = tabs.map((tab) => ({
+ ...tab,
+ tabDbName: tab.props && tab.props.conid && tab.props.database ? tab.props.database : '(no DB)',
+ tabDbKey:
+ tab.props && tab.props.conid && tab.props.database ? formatDbKey(tab.props.conid, tab.props.database) : noDbKey,
+ }));
+ const tabsByDb = _.groupBy(tabsWithDb, 'tabDbKey');
+ const dbKeys = _.keys(tabsByDb).sort();
+
+ const handleSetDb = async (props) => {
+ const { conid, database } = props || {};
+ if (conid) {
+ const connection = await getConnectionInfo({ conid, database });
+ if (connection) {
+ setCurrentDb({ connection, name: database });
+ return;
+ }
+ }
+ setCurrentDb(null);
+ };
return (
<>
- {tabs.map((tab) => (
- handleTabClick(e, tab.tabid)}
- onMouseUp={(e) => handleMouseUp(e, tab.tabid)}
- onContextMenu={(e) => handleContextMenu(e, tab.tabid, tab.props)}
- >
- {tab.busy ? : getIconImage(tab.icon)}
- {tab.title}
- {
- e.preventDefault();
- closeTab(tab.tabid);
- }}
- />
-
+ {dbKeys.map((dbKey) => (
+
+
+ {tabsByDb[dbKey].map((tab) => (
+ handleTabClick(e, tab.tabid)}
+ onMouseUp={(e) => handleMouseUp(e, tab.tabid)}
+ onContextMenu={(e) => handleContextMenu(e, tab.tabid, tab.props)}
+ >
+ {tab.busy ? : getIconImage(tab.icon)}
+ {tab.title}
+ {
+ e.preventDefault();
+ closeTab(tab.tabid);
+ }}
+ />
+
+ ))}
+
+ handleSetDb(tabsByDb[dbKey][0].props)}
+ >
+ {tabsByDb[dbKey][0].tabDbName}
+
+
))}
>
);
diff --git a/packages/web/src/theme.js b/packages/web/src/theme.js
index 29350d09e..39ad28823 100644
--- a/packages/web/src/theme.js
+++ b/packages/web/src/theme.js
@@ -12,7 +12,7 @@ export default {
background: '#ccc',
},
tabsPanel: {
- height: 31,
+ height: 45,
background: '#ddd',
hoverFont: '#338',
},