mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-03 19:53:57 +00:00
tabs panel improvements
This commit is contained in:
@@ -77,6 +77,7 @@ export function setChangeSetValue(
|
|||||||
definition: ChangeSetFieldDefinition,
|
definition: ChangeSetFieldDefinition,
|
||||||
value: string
|
value: string
|
||||||
): ChangeSet {
|
): ChangeSet {
|
||||||
|
if (!changeSet || !definition) return changeSet;
|
||||||
let [fieldName, existingItem] = findExistingChangeSetItem(changeSet, definition);
|
let [fieldName, existingItem] = findExistingChangeSetItem(changeSet, definition);
|
||||||
if (fieldName == 'deletes') {
|
if (fieldName == 'deletes') {
|
||||||
changeSet = revertChangeSetRowChanges(changeSet, definition);
|
changeSet = revertChangeSetRowChanges(changeSet, definition);
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import theme from './theme';
|
import theme from './theme';
|
||||||
@@ -15,13 +16,17 @@ const FileTabItem = styled.div`
|
|||||||
border-right: 1px solid white;
|
border-right: 1px solid white;
|
||||||
padding-left: 15px;
|
padding-left: 15px;
|
||||||
padding-right: 15px;
|
padding-right: 15px;
|
||||||
|
flex-shrink: 1;
|
||||||
|
flex-grow: 0;
|
||||||
|
min-width: 10px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
user-select: none;
|
||||||
&:hover {
|
&:hover {
|
||||||
color: ${theme.tabsPanel.hoverFont};
|
color: ${theme.tabsPanel.hoverFont};
|
||||||
}
|
}
|
||||||
background-color: ${props =>
|
background-color: ${(props) =>
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
props.selected ? theme.mainArea.background : 'inherit'};
|
props.selected ? theme.mainArea.background : 'inherit'};
|
||||||
`;
|
`;
|
||||||
@@ -30,21 +35,45 @@ const FileNameWrapper = styled.span`
|
|||||||
margin-left: 5px;
|
margin-left: 5px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const CloseButton = styled.i`
|
||||||
|
margin-left: 5px;
|
||||||
|
color: gray;
|
||||||
|
&:hover {
|
||||||
|
color: ${theme.tabsPanel.hoverFont};
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
export default function TabsPanel() {
|
export default function TabsPanel() {
|
||||||
const tabs = useOpenedTabs();
|
const tabs = useOpenedTabs();
|
||||||
const setOpenedTabs = useSetOpenedTabs();
|
const setOpenedTabs = useSetOpenedTabs();
|
||||||
|
|
||||||
const handleTabClick = tabid => {
|
const handleTabClick = (e, tabid) => {
|
||||||
setOpenedTabs(files =>
|
if (e.target.closest('.tabCloseButton')) {
|
||||||
files.map(x => ({
|
return;
|
||||||
|
}
|
||||||
|
setOpenedTabs((files) =>
|
||||||
|
files.map((x) => ({
|
||||||
...x,
|
...x,
|
||||||
selected: x.tabid == tabid,
|
selected: x.tabid == tabid,
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
const closeTab = (tabid) => {
|
||||||
|
setOpenedTabs((files) => {
|
||||||
|
let index = _.findIndex(files, (x) => x.tabid == tabid);
|
||||||
|
const newFiles = files.filter((x) => x.tabid != tabid);
|
||||||
|
|
||||||
|
if (!newFiles.find((x) => x.selected)) {
|
||||||
|
if (index >= newFiles.length) index -= 1;
|
||||||
|
if (index >= 0) newFiles[index].selected = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return newFiles;
|
||||||
|
});
|
||||||
|
};
|
||||||
const handleMouseUp = (e, tabid) => {
|
const handleMouseUp = (e, tabid) => {
|
||||||
if (e.button == 1) {
|
if (e.button == 1) {
|
||||||
setOpenedTabs(files => files.filter(x => x.tabid != tabid));
|
closeTab(tabid);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// console.log(
|
// console.log(
|
||||||
@@ -54,16 +83,23 @@ export default function TabsPanel() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{tabs.map(tab => (
|
{tabs.map((tab) => (
|
||||||
<FileTabItem
|
<FileTabItem
|
||||||
{...tab}
|
{...tab}
|
||||||
title={tab.tooltip}
|
title={tab.tooltip}
|
||||||
key={tab.tabid}
|
key={tab.tabid}
|
||||||
onClick={() => handleTabClick(tab.tabid)}
|
onClick={(e) => handleTabClick(e, tab.tabid)}
|
||||||
onMouseUp={e => handleMouseUp(e, tab.tabid)}
|
onMouseUp={(e) => handleMouseUp(e, tab.tabid)}
|
||||||
>
|
>
|
||||||
{getIconImage(tab.icon)}
|
{getIconImage(tab.icon)}
|
||||||
<FileNameWrapper>{tab.title}</FileNameWrapper>
|
<FileNameWrapper>{tab.title}</FileNameWrapper>
|
||||||
|
<CloseButton
|
||||||
|
className="fas fa-times tabCloseButton"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
closeTab(tab.tabid);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</FileTabItem>
|
</FileTabItem>
|
||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export default function ToolBar({ toolbarPortalRef }) {
|
|||||||
<ToolbarContainer>
|
<ToolbarContainer>
|
||||||
<ConnectionModal modalState={modalState} />
|
<ConnectionModal modalState={modalState} />
|
||||||
<ToolbarButton onClick={modalState.open}>Add connection</ToolbarButton>
|
<ToolbarButton onClick={modalState.open}>Add connection</ToolbarButton>
|
||||||
<ToolbarButton onClick={newQuery}>Query</ToolbarButton>
|
<ToolbarButton onClick={newQuery}>New Query</ToolbarButton>
|
||||||
<ToolbarContainer ref={toolbarPortalRef}></ToolbarContainer>
|
<ToolbarContainer ref={toolbarPortalRef}></ToolbarContainer>
|
||||||
</ToolbarContainer>
|
</ToolbarContainer>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user