mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-02 10:13:57 +00:00
tabs with shown database
This commit is contained in:
@@ -4,9 +4,10 @@ import styled from 'styled-components';
|
|||||||
import theme from './theme';
|
import theme from './theme';
|
||||||
import { DropDownMenuItem, DropDownMenuDivider } from './modals/DropDownMenu';
|
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 { getIconImage } from './icons';
|
||||||
import { showMenu } from './modals/DropDownMenu';
|
import { showMenu } from './modals/DropDownMenu';
|
||||||
|
import { getConnectionInfo } from './utility/metadataLoaders';
|
||||||
|
|
||||||
// const files = [
|
// const files = [
|
||||||
// { name: 'app.js' },
|
// { name: 'app.js' },
|
||||||
@@ -14,6 +15,31 @@ import { showMenu } from './modals/DropDownMenu';
|
|||||||
// { name: 'ApplicationList' },
|
// { 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`
|
const FileTabItem = styled.div`
|
||||||
border-right: 1px solid white;
|
border-right: 1px solid white;
|
||||||
padding-left: 15px;
|
padding-left: 15px;
|
||||||
@@ -64,8 +90,16 @@ function TabContextMenu({ close, closeAll, closeOthers, closeWithSameDb, closeWi
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function TabsPanel() {
|
export default function TabsPanel() {
|
||||||
|
const noDbKey = '_no';
|
||||||
|
const formatDbKey = (conid, database) => `${database}-${conid}`;
|
||||||
|
|
||||||
const tabs = useOpenedTabs();
|
const tabs = useOpenedTabs();
|
||||||
const setOpenedTabs = useSetOpenedTabs();
|
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) => {
|
const handleTabClick = (e, tabid) => {
|
||||||
if (e.target.closest('.tabCloseButton')) {
|
if (e.target.closest('.tabCloseButton')) {
|
||||||
@@ -134,28 +168,61 @@ export default function TabsPanel() {
|
|||||||
// 't',
|
// 't',
|
||||||
// tabs.map(x => x.tooltip)
|
// 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 (
|
return (
|
||||||
<>
|
<>
|
||||||
{tabs.map((tab) => (
|
{dbKeys.map((dbKey) => (
|
||||||
<FileTabItem
|
<DbWrapperHandler key={dbKey}>
|
||||||
{...tab}
|
<DbGroupHandler>
|
||||||
title={tab.tooltip}
|
{tabsByDb[dbKey].map((tab) => (
|
||||||
key={tab.tabid}
|
<FileTabItem
|
||||||
onClick={(e) => handleTabClick(e, tab.tabid)}
|
{...tab}
|
||||||
onMouseUp={(e) => handleMouseUp(e, tab.tabid)}
|
title={tab.tooltip}
|
||||||
onContextMenu={(e) => handleContextMenu(e, tab.tabid, tab.props)}
|
key={tab.tabid}
|
||||||
>
|
onClick={(e) => handleTabClick(e, tab.tabid)}
|
||||||
{tab.busy ? <i className="fas fa-spinner fa-spin"></i> : getIconImage(tab.icon)}
|
onMouseUp={(e) => handleMouseUp(e, tab.tabid)}
|
||||||
<FileNameWrapper>{tab.title}</FileNameWrapper>
|
onContextMenu={(e) => handleContextMenu(e, tab.tabid, tab.props)}
|
||||||
<CloseButton
|
>
|
||||||
className="fas fa-times tabCloseButton"
|
{tab.busy ? <i className="fas fa-spinner fa-spin"></i> : getIconImage(tab.icon)}
|
||||||
onClick={(e) => {
|
<FileNameWrapper>{tab.title}</FileNameWrapper>
|
||||||
e.preventDefault();
|
<CloseButton
|
||||||
closeTab(tab.tabid);
|
className="fas fa-times tabCloseButton"
|
||||||
}}
|
onClick={(e) => {
|
||||||
/>
|
e.preventDefault();
|
||||||
</FileTabItem>
|
closeTab(tab.tabid);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</FileTabItem>
|
||||||
|
))}
|
||||||
|
</DbGroupHandler>
|
||||||
|
<DbNameWrapper
|
||||||
|
// @ts-ignore
|
||||||
|
selected={tabsByDb[dbKey][0].tabDbKey == currentDbKey}
|
||||||
|
onClick={() => handleSetDb(tabsByDb[dbKey][0].props)}
|
||||||
|
>
|
||||||
|
<i className="fas fa-database" /> {tabsByDb[dbKey][0].tabDbName}
|
||||||
|
</DbNameWrapper>
|
||||||
|
</DbWrapperHandler>
|
||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export default {
|
|||||||
background: '#ccc',
|
background: '#ccc',
|
||||||
},
|
},
|
||||||
tabsPanel: {
|
tabsPanel: {
|
||||||
height: 31,
|
height: 45,
|
||||||
background: '#ddd',
|
background: '#ddd',
|
||||||
hoverFont: '#338',
|
hoverFont: '#338',
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user