mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 06:36:00 +00:00
master-detail view
This commit is contained in:
@@ -7,6 +7,15 @@ export interface GridConfigColumns {
|
|||||||
addedColumns: string[];
|
addedColumns: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface GridReferenceDefinition {
|
||||||
|
schemaName: string;
|
||||||
|
pureName: string;
|
||||||
|
columns: {
|
||||||
|
baseName: string;
|
||||||
|
refName: string;
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface GridConfig extends GridConfigColumns {
|
export interface GridConfig extends GridConfigColumns {
|
||||||
filters: { [uniqueName: string]: string };
|
filters: { [uniqueName: string]: string };
|
||||||
focusedColumn?: string;
|
focusedColumn?: string;
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ export class TableGridDisplay extends GridDisplay {
|
|||||||
for (const column of this.getGridColumns()) {
|
for (const column of this.getGridColumns()) {
|
||||||
if (column.foreignKey) {
|
if (column.foreignKey) {
|
||||||
const table = this.cache.tables[column.uniqueName];
|
const table = this.cache.tables[column.uniqueName];
|
||||||
if (table) {
|
if (table && table.columns && table.columns.length > 0) {
|
||||||
const hintColumn = table.columns.find((x) => x?.dataType?.toLowerCase()?.includes('char'));
|
const hintColumn = table.columns.find((x) => x?.dataType?.toLowerCase()?.includes('char'));
|
||||||
if (hintColumn) {
|
if (hintColumn) {
|
||||||
const parentUniqueName = column.uniquePath.slice(0, -1).join('.');
|
const parentUniqueName = column.uniquePath.slice(0, -1).join('.');
|
||||||
@@ -147,6 +147,7 @@ export class TableGridDisplay extends GridDisplay {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.requireFkTarget(column);
|
this.requireFkTarget(column);
|
||||||
|
this.isLoadedCorrectly = false;
|
||||||
res = 'loadRequired';
|
res = 'loadRequired';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
4
packages/filterparser/src/filterTool.ts
Normal file
4
packages/filterparser/src/filterTool.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
export function getFilterValueExpression(value) {
|
||||||
|
if (value == null) return 'NULL';
|
||||||
|
return `="${value}"`;
|
||||||
|
}
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
export * from './parseFilter';
|
export * from './parseFilter';
|
||||||
export * from './getFilterType';
|
export * from './getFilterType';
|
||||||
|
export * from './filterTool';
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
ManagerMainContainer,
|
ManagerMainContainer,
|
||||||
ManagerOuterContainer1,
|
ManagerOuterContainer1,
|
||||||
ManagerOuterContainer2,
|
ManagerOuterContainer2,
|
||||||
|
ManagerOuterContainerFull,
|
||||||
WidgetTitle,
|
WidgetTitle,
|
||||||
} from './ManagerStyles';
|
} from './ManagerStyles';
|
||||||
import ReferenceManager from './ReferenceManager';
|
import ReferenceManager from './ReferenceManager';
|
||||||
@@ -40,18 +41,21 @@ 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;
|
||||||
return (
|
return (
|
||||||
<MainContainer>
|
<MainContainer>
|
||||||
<LeftContainer>
|
<LeftContainer>
|
||||||
<ManagerMainContainer>
|
<ManagerMainContainer>
|
||||||
<ManagerOuterContainer1>
|
<Container1>
|
||||||
<WidgetTitle>Columns</WidgetTitle>
|
<WidgetTitle>Columns</WidgetTitle>
|
||||||
<ColumnManager {...props} />
|
<ColumnManager {...props} />
|
||||||
</ManagerOuterContainer1>
|
</Container1>
|
||||||
<ManagerOuterContainer2>
|
{props.showReferences && (
|
||||||
<WidgetTitle>References</WidgetTitle>
|
<ManagerOuterContainer2>
|
||||||
<ReferenceManager {...props} />
|
<WidgetTitle>References</WidgetTitle>
|
||||||
</ManagerOuterContainer2>
|
<ReferenceManager {...props} />
|
||||||
|
</ManagerOuterContainer2>
|
||||||
|
)}
|
||||||
</ManagerMainContainer>
|
</ManagerMainContainer>
|
||||||
</LeftContainer>
|
</LeftContainer>
|
||||||
|
|
||||||
|
|||||||
@@ -425,6 +425,10 @@ export default function DataGridCore(props) {
|
|||||||
}
|
}
|
||||||
}, [jslid]);
|
}, [jslid]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (props.onSelectedRowsChanged) props.onSelectedRowsChanged(getSelectedRowData())
|
||||||
|
}, [selectedCells]);
|
||||||
|
|
||||||
// const handleCloseInplaceEditor = React.useCallback(
|
// const handleCloseInplaceEditor = React.useCallback(
|
||||||
// mode => {
|
// mode => {
|
||||||
// const [row, col] = currentCell || [];
|
// const [row, col] = currentCell || [];
|
||||||
@@ -680,8 +684,16 @@ export default function DataGridCore(props) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSelectedRowIndexes() {
|
||||||
|
return _.uniq((selectedCells || []).map((x) => x[0]));
|
||||||
|
}
|
||||||
|
|
||||||
function getSelectedRowDefinitions() {
|
function getSelectedRowDefinitions() {
|
||||||
return getRowDefinitions(_.uniq((selectedCells || []).map((x) => x[0])));
|
return getRowDefinitions(getSelectedRowIndexes());
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSelectedRowData() {
|
||||||
|
return _.compact(getSelectedRowIndexes().map((index) => loadedRows && loadedRows[index]));
|
||||||
}
|
}
|
||||||
|
|
||||||
function revertRowChanges() {
|
function revertRowChanges() {
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ export const ManagerOuterContainer2 = styled(ManagerOuterContainer)`
|
|||||||
flex: 0 0 40%;
|
flex: 0 0 40%;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
export const ManagerOuterContainerFull = styled(ManagerOuterContainer)`
|
||||||
|
flex: 1;
|
||||||
|
`;
|
||||||
|
|
||||||
export const ManagerInnerContainer = styled.div`
|
export const ManagerInnerContainer = styled.div`
|
||||||
flex: 1 1;
|
flex: 1 1;
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
|
|||||||
@@ -31,9 +31,9 @@ const NameContainer = styled.div`
|
|||||||
margin-left: 5px;
|
margin-left: 5px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
function ManagerRow({ tableName, columns, Icon }) {
|
function ManagerRow({ tableName, columns, Icon, onClick }) {
|
||||||
return (
|
return (
|
||||||
<LinkContainer>
|
<LinkContainer onClick={onClick}>
|
||||||
<Icon />
|
<Icon />
|
||||||
<NameContainer>
|
<NameContainer>
|
||||||
{tableName} ({columns.map((x) => x.columnName).join(', ')})
|
{tableName} ({columns.map((x) => x.columnName).join(', ')})
|
||||||
@@ -60,7 +60,22 @@ export default function ReferenceManager(props) {
|
|||||||
<>
|
<>
|
||||||
<Header>References tables ({foreignKeys.length})</Header>
|
<Header>References tables ({foreignKeys.length})</Header>
|
||||||
{foreignKeys.map((fk) => (
|
{foreignKeys.map((fk) => (
|
||||||
<ManagerRow key={fk.constraintName} Icon={LinkIcon} tableName={fk.refTableName} columns={fk.columns} />
|
<ManagerRow
|
||||||
|
key={fk.constraintName}
|
||||||
|
Icon={LinkIcon}
|
||||||
|
tableName={fk.refTableName}
|
||||||
|
columns={fk.columns}
|
||||||
|
onClick={() =>
|
||||||
|
props.onReferenceClick({
|
||||||
|
schemaName: fk.refSchemaName,
|
||||||
|
pureName: fk.refTableName,
|
||||||
|
columns: fk.columns.map((col) => ({
|
||||||
|
baseName: col.columnName,
|
||||||
|
refName: col.refColumnName,
|
||||||
|
})),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
@@ -68,7 +83,22 @@ export default function ReferenceManager(props) {
|
|||||||
<>
|
<>
|
||||||
<Header>Dependend tables ({dependencies.length})</Header>
|
<Header>Dependend tables ({dependencies.length})</Header>
|
||||||
{dependencies.map((fk) => (
|
{dependencies.map((fk) => (
|
||||||
<ManagerRow key={fk.constraintName} Icon={ReferenceIcon} tableName={fk.pureName} columns={fk.columns} />
|
<ManagerRow
|
||||||
|
key={fk.constraintName}
|
||||||
|
Icon={ReferenceIcon}
|
||||||
|
tableName={fk.pureName}
|
||||||
|
columns={fk.columns}
|
||||||
|
onClick={() =>
|
||||||
|
props.onReferenceClick({
|
||||||
|
schemaName: fk.schemaName,
|
||||||
|
pureName: fk.pureName,
|
||||||
|
columns: fk.columns.map((col) => ({
|
||||||
|
baseName: col.refColumnName,
|
||||||
|
refName: col.columnName,
|
||||||
|
})),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import _ from 'lodash';
|
||||||
import DataGrid from './DataGrid';
|
import DataGrid from './DataGrid';
|
||||||
import { TableGridDisplay, createGridConfig, createGridCache } from '@dbgate/datalib';
|
import { TableGridDisplay, createGridConfig, createGridCache } from '@dbgate/datalib';
|
||||||
|
import { getFilterValueExpression } from '@dbgate/filterparser';
|
||||||
import { useConnectionInfo, getTableInfo } from '../utility/metadataLoaders';
|
import { useConnectionInfo, getTableInfo } from '../utility/metadataLoaders';
|
||||||
import engines from '@dbgate/engines';
|
import engines from '@dbgate/engines';
|
||||||
import useSocket from '../utility/SocketProvider';
|
import useSocket from '../utility/SocketProvider';
|
||||||
|
import { VerticalSplitter } from '../widgets/Splitter';
|
||||||
|
import stableStringify from 'json-stable-stringify';
|
||||||
|
|
||||||
export default function TableDataGrid({
|
export default function TableDataGrid({
|
||||||
conid,
|
conid,
|
||||||
@@ -12,14 +16,20 @@ export default function TableDataGrid({
|
|||||||
pureName,
|
pureName,
|
||||||
tabVisible,
|
tabVisible,
|
||||||
toolbarPortalRef,
|
toolbarPortalRef,
|
||||||
cache,
|
|
||||||
setCache,
|
|
||||||
changeSetState,
|
changeSetState,
|
||||||
dispatchChangeSet,
|
dispatchChangeSet,
|
||||||
|
config = undefined,
|
||||||
|
setConfig = undefined,
|
||||||
|
cache = undefined,
|
||||||
|
setCache = undefined,
|
||||||
}) {
|
}) {
|
||||||
const [config, setConfig] = React.useState(createGridConfig());
|
const [myConfig, setMyConfig] = React.useState(createGridConfig());
|
||||||
|
const [childConfig, setChildConfig] = React.useState(createGridConfig());
|
||||||
|
const [myCache, setMyCache] = React.useState(createGridCache());
|
||||||
|
const [childCache, setChildCache] = React.useState(createGridCache());
|
||||||
|
|
||||||
const connection = useConnectionInfo({ conid });
|
const connection = useConnectionInfo({ conid });
|
||||||
|
const [reference, setReference] = React.useState(null);
|
||||||
|
|
||||||
const display = React.useMemo(
|
const display = React.useMemo(
|
||||||
() =>
|
() =>
|
||||||
@@ -27,18 +37,18 @@ export default function TableDataGrid({
|
|||||||
? new TableGridDisplay(
|
? new TableGridDisplay(
|
||||||
{ schemaName, pureName },
|
{ schemaName, pureName },
|
||||||
engines(connection),
|
engines(connection),
|
||||||
config,
|
config || myConfig,
|
||||||
setConfig,
|
setConfig || setMyConfig,
|
||||||
cache,
|
cache || myCache,
|
||||||
setCache,
|
setCache || setMyCache,
|
||||||
(name) => getTableInfo({ conid, database, ...name })
|
(name) => getTableInfo({ conid, database, ...name })
|
||||||
)
|
)
|
||||||
: null,
|
: null,
|
||||||
[connection, config, cache]
|
[connection, config || myConfig, cache || myCache, conid, database, schemaName, pureName]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleDatabaseStructureChanged = React.useCallback(() => {
|
const handleDatabaseStructureChanged = React.useCallback(() => {
|
||||||
setCache(createGridCache());
|
(setCache || setMyCache)(createGridCache());
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const socket = useSocket();
|
const socket = useSocket();
|
||||||
@@ -54,18 +64,62 @@ export default function TableDataGrid({
|
|||||||
}
|
}
|
||||||
}, [conid, database, display]);
|
}, [conid, database, display]);
|
||||||
|
|
||||||
|
const handleSelectedRowsChanged = (selectedRows) => {
|
||||||
|
const filters = {
|
||||||
|
...(config || myConfig).filters,
|
||||||
|
..._.fromPairs(
|
||||||
|
reference.columns.map((col) => [
|
||||||
|
col.refName,
|
||||||
|
selectedRows.map((x) => getFilterValueExpression(x[col.baseName])).join(','),
|
||||||
|
])
|
||||||
|
),
|
||||||
|
};
|
||||||
|
if (stableStringify(filters) != stableStringify((config || myConfig).filters)) {
|
||||||
|
setChildConfig((cfg) => ({
|
||||||
|
...cfg,
|
||||||
|
filters,
|
||||||
|
}));
|
||||||
|
setChildCache((ca) => ({
|
||||||
|
...ca,
|
||||||
|
refreshTime: new Date().getTime(),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (!display) return null;
|
if (!display) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DataGrid
|
<VerticalSplitter>
|
||||||
// key={`${conid}, ${database}, ${schemaName}, ${pureName}`}
|
<DataGrid
|
||||||
conid={conid}
|
// key={`${conid}, ${database}, ${schemaName}, ${pureName}`}
|
||||||
database={database}
|
conid={conid}
|
||||||
display={display}
|
database={database}
|
||||||
tabVisible={tabVisible}
|
display={display}
|
||||||
changeSetState={changeSetState}
|
tabVisible={tabVisible}
|
||||||
dispatchChangeSet={dispatchChangeSet}
|
changeSetState={changeSetState}
|
||||||
toolbarPortalRef={toolbarPortalRef}
|
dispatchChangeSet={dispatchChangeSet}
|
||||||
/>
|
toolbarPortalRef={toolbarPortalRef}
|
||||||
|
showReferences
|
||||||
|
onReferenceClick={setReference}
|
||||||
|
onSelectedRowsChanged={reference ? handleSelectedRowsChanged : null}
|
||||||
|
/>
|
||||||
|
{reference && (
|
||||||
|
<TableDataGrid
|
||||||
|
key={`${reference.schemaName}.${reference.pureName}`}
|
||||||
|
conid={conid}
|
||||||
|
database={database}
|
||||||
|
pureName={reference.pureName}
|
||||||
|
schemaName={reference.schemaName}
|
||||||
|
changeSetState={changeSetState}
|
||||||
|
dispatchChangeSet={dispatchChangeSet}
|
||||||
|
toolbarPortalRef={toolbarPortalRef}
|
||||||
|
tabVisible={false}
|
||||||
|
config={childConfig}
|
||||||
|
setConfig={setChildConfig}
|
||||||
|
cache={childCache}
|
||||||
|
setCache={setChildCache}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</VerticalSplitter>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { GridDisplay, ChangeSet } from '@dbgate/datalib';
|
import { GridDisplay, ChangeSet, GridReferenceDefinition } from '@dbgate/datalib';
|
||||||
|
|
||||||
export interface DataGridProps {
|
export interface DataGridProps {
|
||||||
conid?: string;
|
conid?: string;
|
||||||
@@ -9,4 +9,7 @@ export interface DataGridProps {
|
|||||||
dispatchChangeSet?: Function;
|
dispatchChangeSet?: Function;
|
||||||
toolbarPortalRef?: any;
|
toolbarPortalRef?: any;
|
||||||
jslid?: string;
|
jslid?: string;
|
||||||
|
showReferences?: boolean;
|
||||||
|
onReferenceClick?: (def: GridReferenceDefinition) => void;
|
||||||
|
onSelectedRowsChanged?: Function;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import { useUpdateDatabaseForTab } from '../utility/globalState';
|
|||||||
import TableDataGrid from '../datagrid/TableDataGrid';
|
import TableDataGrid from '../datagrid/TableDataGrid';
|
||||||
|
|
||||||
export default function TableDataTab({ conid, database, schemaName, pureName, tabVisible, toolbarPortalRef }) {
|
export default function TableDataTab({ conid, database, schemaName, pureName, tabVisible, toolbarPortalRef }) {
|
||||||
const [cache, setCache] = React.useState(createGridCache());
|
|
||||||
const [changeSetState, dispatchChangeSet] = useUndoReducer(createChangeSet());
|
const [changeSetState, dispatchChangeSet] = useUndoReducer(createChangeSet());
|
||||||
useUpdateDatabaseForTab(tabVisible, conid, database);
|
useUpdateDatabaseForTab(tabVisible, conid, database);
|
||||||
|
|
||||||
@@ -18,8 +17,6 @@ export default function TableDataTab({ conid, database, schemaName, pureName, ta
|
|||||||
pureName={pureName}
|
pureName={pureName}
|
||||||
tabVisible={tabVisible}
|
tabVisible={tabVisible}
|
||||||
toolbarPortalRef={toolbarPortalRef}
|
toolbarPortalRef={toolbarPortalRef}
|
||||||
cache={cache}
|
|
||||||
setCache={setCache}
|
|
||||||
changeSetState={changeSetState}
|
changeSetState={changeSetState}
|
||||||
dispatchChangeSet={dispatchChangeSet}
|
dispatchChangeSet={dispatchChangeSet}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -11,20 +11,21 @@ const MainContainer = styled.div`
|
|||||||
const ChildContainer = styled.div`
|
const ChildContainer = styled.div`
|
||||||
flex: 1;
|
flex: 1;
|
||||||
// flex: 0 0 50%;
|
// flex: 0 0 50%;
|
||||||
// flex-basis: 100px;
|
// flex-basis: 100px;
|
||||||
// flex-grow: 1;
|
// flex-grow: 1;
|
||||||
display: flex;
|
display: flex;
|
||||||
position: relative;
|
position: relative;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export function VerticalSplitter({ children }) {
|
export function VerticalSplitter({ children }) {
|
||||||
if (!_.isArray(children) || children.length !== 2) {
|
const childrenArray = _.isArray(children) ? children : [children];
|
||||||
throw new Error('Splitter must have exactly 2 children');
|
if (childrenArray.length !== 1 && childrenArray.length != 2) {
|
||||||
|
throw new Error('Splitter must have 1 or 2 children');
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<MainContainer>
|
<MainContainer>
|
||||||
<ChildContainer>{children[0]}</ChildContainer>
|
<ChildContainer>{childrenArray[0]}</ChildContainer>
|
||||||
<ChildContainer>{children[1]}</ChildContainer>
|
{childrenArray[1] && <ChildContainer>{childrenArray[1]}</ChildContainer>}
|
||||||
</MainContainer>
|
</MainContainer>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user