mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
managers sizing
This commit is contained in:
parent
8f5467859b
commit
9c364d86ff
@ -14,6 +14,7 @@ const Row = styled.div`
|
|||||||
margin-left: 5px;
|
margin-left: 5px;
|
||||||
margin-right: 5px;
|
margin-right: 5px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
white-space: nowrap;
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: lightblue;
|
background-color: lightblue;
|
||||||
}
|
}
|
||||||
@ -103,7 +104,7 @@ export default function ColumnManager(props) {
|
|||||||
<InlineButton onClick={() => display.hideAllColumns()}>Hide</InlineButton>
|
<InlineButton onClick={() => display.hideAllColumns()}>Hide</InlineButton>
|
||||||
<InlineButton onClick={() => display.showAllColumns()}>Show</InlineButton>
|
<InlineButton onClick={() => display.showAllColumns()}>Show</InlineButton>
|
||||||
</SearchBoxWrapper>
|
</SearchBoxWrapper>
|
||||||
<ManagerInnerContainer>
|
<ManagerInnerContainer style={{ maxWidth: props.managerSize }}>
|
||||||
{display
|
{display
|
||||||
.getColumns(columnFilter)
|
.getColumns(columnFilter)
|
||||||
.filter((column) => filterName(columnFilter, column.columnName))
|
.filter((column) => filterName(columnFilter, column.columnName))
|
||||||
|
@ -14,6 +14,7 @@ import {
|
|||||||
WidgetTitle,
|
WidgetTitle,
|
||||||
} from './ManagerStyles';
|
} from './ManagerStyles';
|
||||||
import ReferenceManager from './ReferenceManager';
|
import ReferenceManager from './ReferenceManager';
|
||||||
|
import { HorizontalSplitter } from '../widgets/Splitter';
|
||||||
|
|
||||||
const MainContainer = styled.div`
|
const MainContainer = styled.div`
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@ -32,6 +33,7 @@ const ColumnManagerContainer = styled.div`
|
|||||||
const LeftContainer = styled.div`
|
const LeftContainer = styled.div`
|
||||||
background-color: white;
|
background-color: white;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex: 1;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const DataGridContainer = styled.div`
|
const DataGridContainer = styled.div`
|
||||||
@ -42,27 +44,47 @@ const DataGridContainer = styled.div`
|
|||||||
/** @param props {import('./types').DataGridProps} */
|
/** @param props {import('./types').DataGridProps} */
|
||||||
export default function DataGrid(props) {
|
export default function DataGrid(props) {
|
||||||
const Container1 = props.showReferences ? ManagerOuterContainer1 : ManagerOuterContainerFull;
|
const Container1 = props.showReferences ? ManagerOuterContainer1 : ManagerOuterContainerFull;
|
||||||
|
const [managerSize, setManagerSize] = React.useState(0);
|
||||||
return (
|
return (
|
||||||
<MainContainer>
|
<HorizontalSplitter initialValue="300px" size={managerSize} setSize={setManagerSize}>
|
||||||
<LeftContainer>
|
<LeftContainer>
|
||||||
<ManagerMainContainer>
|
<ManagerMainContainer>
|
||||||
<Container1>
|
<Container1>
|
||||||
<ColumnManager {...props} />
|
<ColumnManager {...props} managerSize={managerSize}/>
|
||||||
</Container1>
|
</Container1>
|
||||||
{props.showReferences && (
|
{props.showReferences && (
|
||||||
<ManagerOuterContainer2>
|
<ManagerOuterContainer2>
|
||||||
<ReferenceManager {...props} />
|
<ReferenceManager {...props} managerSize={managerSize}/>
|
||||||
</ManagerOuterContainer2>
|
</ManagerOuterContainer2>
|
||||||
)}
|
)}
|
||||||
</ManagerMainContainer>
|
</ManagerMainContainer>
|
||||||
</LeftContainer>
|
</LeftContainer>
|
||||||
|
|
||||||
{/* <ColumnManagerContainer>
|
|
||||||
<ColumnManager {...props} />
|
|
||||||
</ColumnManagerContainer> */}
|
|
||||||
<DataGridContainer>
|
<DataGridContainer>
|
||||||
<DataGridCore {...props} />
|
<DataGridCore {...props} />
|
||||||
</DataGridContainer>
|
</DataGridContainer>
|
||||||
</MainContainer>
|
</HorizontalSplitter>
|
||||||
|
|
||||||
|
// <MainContainer>
|
||||||
|
// <LeftContainer style={{ width: 300 }}>
|
||||||
|
// <ManagerMainContainer>
|
||||||
|
// <Container1>
|
||||||
|
// <ColumnManager {...props} />
|
||||||
|
// </Container1>
|
||||||
|
// {props.showReferences && (
|
||||||
|
// <ManagerOuterContainer2>
|
||||||
|
// <ReferenceManager {...props} />
|
||||||
|
// </ManagerOuterContainer2>
|
||||||
|
// )}
|
||||||
|
// </ManagerMainContainer>
|
||||||
|
// </LeftContainer>
|
||||||
|
|
||||||
|
// {/* <ColumnManagerContainer>
|
||||||
|
// <ColumnManager {...props} />
|
||||||
|
// </ColumnManagerContainer> */}
|
||||||
|
// <DataGridContainer>
|
||||||
|
// <DataGridCore {...props} />
|
||||||
|
// </DataGridContainer>
|
||||||
|
// </MainContainer>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,8 @@ export const ManagerOuterContainerFull = styled(ManagerOuterContainer)`
|
|||||||
|
|
||||||
export const ManagerInnerContainer = styled.div`
|
export const ManagerInnerContainer = styled.div`
|
||||||
flex: 1 1;
|
flex: 1 1;
|
||||||
overflow-y: scroll;
|
overflow-y: auto;
|
||||||
|
overflow-x: auto;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const Input = styled.input`
|
export const Input = styled.input`
|
||||||
|
@ -23,10 +23,12 @@ const LinkContainer = styled.div`
|
|||||||
}
|
}
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-wrap: nowrap;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const NameContainer = styled.div`
|
const NameContainer = styled.div`
|
||||||
margin-left: 5px;
|
margin-left: 5px;
|
||||||
|
white-space: nowrap;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
function ManagerRow({ tableName, columns, Icon, onClick }) {
|
function ManagerRow({ tableName, columns, Icon, onClick }) {
|
||||||
@ -55,7 +57,7 @@ export default function ReferenceManager(props) {
|
|||||||
<SearchBoxWrapper>
|
<SearchBoxWrapper>
|
||||||
<SearchInput placeholder="Search references" filter={filter} setFilter={setFilter} inputRef={inputRef} />
|
<SearchInput placeholder="Search references" filter={filter} setFilter={setFilter} inputRef={inputRef} />
|
||||||
</SearchBoxWrapper>
|
</SearchBoxWrapper>
|
||||||
<ManagerInnerContainer>
|
<ManagerInnerContainer style={{ maxWidth: props.managerSize }}>
|
||||||
{foreignKeys && foreignKeys.length > 0 && (
|
{foreignKeys && foreignKeys.length > 0 && (
|
||||||
<>
|
<>
|
||||||
<Header>References tables ({foreignKeys.length})</Header>
|
<Header>References tables ({foreignKeys.length})</Header>
|
||||||
|
@ -13,5 +13,6 @@ export interface DataGridProps {
|
|||||||
onReferenceClick?: (def: GridReferenceDefinition) => void;
|
onReferenceClick?: (def: GridReferenceDefinition) => void;
|
||||||
onReferenceSourceChanged?: Function;
|
onReferenceSourceChanged?: Function;
|
||||||
refReloadToken?: string;
|
refReloadToken?: string;
|
||||||
masterLoadedTime?: number
|
masterLoadedTime?: number;
|
||||||
|
managerSize?: number;
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,17 @@ import styled from 'styled-components';
|
|||||||
import useDimensions from '../utility/useDimensions';
|
import useDimensions from '../utility/useDimensions';
|
||||||
import theme from '../theme';
|
import theme from '../theme';
|
||||||
|
|
||||||
const MainContainer = styled.div`
|
const VerticalMainContainer = styled.div`
|
||||||
flex: 1;
|
flex: 1;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const HorizontalMainContainer = styled.div`
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
`;
|
||||||
|
|
||||||
export const VerticalSplitHandle = styled.div`
|
export const VerticalSplitHandle = styled.div`
|
||||||
background-color: #ccc;
|
background-color: #ccc;
|
||||||
height: ${theme.splitter.thickness}px;
|
height: ${theme.splitter.thickness}px;
|
||||||
@ -74,27 +79,72 @@ export function useSplitterDrag(axes, onResize) {
|
|||||||
return handleResizeDown;
|
return handleResizeDown;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function VerticalSplitter({ children }) {
|
function SplitterCore({
|
||||||
|
children,
|
||||||
|
eventField,
|
||||||
|
dimensionField,
|
||||||
|
styleField,
|
||||||
|
Handle,
|
||||||
|
Main,
|
||||||
|
initialValue = undefined,
|
||||||
|
size = undefined,
|
||||||
|
setSize = undefined,
|
||||||
|
}) {
|
||||||
const childrenArray = _.isArray(children) ? children : [children];
|
const childrenArray = _.isArray(children) ? children : [children];
|
||||||
if (childrenArray.length !== 1 && childrenArray.length != 2) {
|
if (childrenArray.length !== 1 && childrenArray.length != 2) {
|
||||||
throw new Error('Splitter must have 1 or 2 children');
|
throw new Error('Splitter must have 1 or 2 children');
|
||||||
}
|
}
|
||||||
const [refNode, dimensions] = useDimensions();
|
const [refNode, dimensions] = useDimensions();
|
||||||
const [height1, setHeight1] = React.useState(0);
|
const [mySize, setMySize] = React.useState(0);
|
||||||
|
const size1 = size === undefined ? mySize : size;
|
||||||
|
const setSize1 = setSize === undefined ? setMySize : setSize;
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
setHeight1(dimensions.height / 2);
|
if (_.isString(initialValue) && initialValue.endsWith('px')) setSize1(parseInt(initialValue.slice(0, -2)));
|
||||||
|
else if (_.isString(initialValue) && initialValue.endsWith('%'))
|
||||||
|
setSize1((dimensions[dimensionField] * parseFloat(initialValue.slice(0, -1))) / 100);
|
||||||
|
else setSize1(dimensions[dimensionField] / 2);
|
||||||
}, [dimensions]);
|
}, [dimensions]);
|
||||||
|
|
||||||
const handleResizeDown = useSplitterDrag('clientY', (diff) => setHeight1((v) => v + diff));
|
const handleResizeDown = useSplitterDrag(eventField, (diff) => setSize1((v) => v + diff));
|
||||||
|
|
||||||
const isSplitter = !!childrenArray[1];
|
const isSplitter = !!childrenArray[1];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MainContainer ref={refNode}>
|
<Main ref={refNode}>
|
||||||
<ChildContainer1 style={isSplitter ? { height: height1 } : { flex: '1' }}>{childrenArray[0]}</ChildContainer1>
|
<ChildContainer1 style={isSplitter ? { [styleField]: size1 } : { flex: '1' }}>{childrenArray[0]}</ChildContainer1>
|
||||||
{isSplitter && <VerticalSplitHandle onMouseDown={handleResizeDown} />}
|
{isSplitter && <Handle onMouseDown={handleResizeDown} />}
|
||||||
{isSplitter && <ChildContainer2>{childrenArray[1]}</ChildContainer2>}
|
{isSplitter && <ChildContainer2>{childrenArray[1]}</ChildContainer2>}
|
||||||
</MainContainer>
|
</Main>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function VerticalSplitter({ children, ...other }) {
|
||||||
|
return (
|
||||||
|
<SplitterCore
|
||||||
|
eventField="clientY"
|
||||||
|
dimensionField="height"
|
||||||
|
styleField="height"
|
||||||
|
Handle={VerticalSplitHandle}
|
||||||
|
Main={VerticalMainContainer}
|
||||||
|
{...other}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</SplitterCore>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function HorizontalSplitter({ children, ...other }) {
|
||||||
|
return (
|
||||||
|
<SplitterCore
|
||||||
|
eventField="clientX"
|
||||||
|
dimensionField="width"
|
||||||
|
styleField="width"
|
||||||
|
Handle={HorizontalSplitHandle}
|
||||||
|
Main={HorizontalMainContainer}
|
||||||
|
{...other}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</SplitterCore>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user