mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-27 13:46:00 +00:00
app object refactor finished
This commit is contained in:
@@ -1,15 +0,0 @@
|
|||||||
/** @param columnProps {import('dbgate-types').ColumnInfo} */
|
|
||||||
function getColumnIcon(columnProps) {
|
|
||||||
if (columnProps.autoIncrement) return 'img autoincrement';
|
|
||||||
return 'img column';
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param columnProps {import('dbgate-types').ColumnInfo} */
|
|
||||||
export default function columnAppObject(columnProps, { setOpenedTabs }) {
|
|
||||||
const title = columnProps.columnName;
|
|
||||||
const key = title;
|
|
||||||
const icon = getColumnIcon(columnProps);
|
|
||||||
const isBold = columnProps.notNull;
|
|
||||||
|
|
||||||
return { title, key, icon, isBold };
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
/** @param props {import('dbgate-types').ConstraintInfo} */
|
|
||||||
function getConstraintIcon(props) {
|
|
||||||
if (props.constraintType == 'primaryKey') return 'img primary-key';
|
|
||||||
if (props.constraintType == 'foreignKey') return 'img foreign-key';
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param props {import('dbgate-types').ConstraintInfo} */
|
|
||||||
export default function constraintAppObject(props, { setOpenedTabs }) {
|
|
||||||
const title = props.constraintName;
|
|
||||||
const key = title;
|
|
||||||
const icon = getConstraintIcon(props);
|
|
||||||
|
|
||||||
return { title, key, icon };
|
|
||||||
}
|
|
||||||
@@ -5,13 +5,13 @@ import styled from 'styled-components';
|
|||||||
import { FontIcon } from '../icons';
|
import { FontIcon } from '../icons';
|
||||||
|
|
||||||
const Label = styled.span`
|
const Label = styled.span`
|
||||||
font-weight: ${props => (props.notNull ? 'bold' : 'normal')};
|
font-weight: ${(props) => (props.notNull ? 'bold' : 'normal')};
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
/** @param column {import('dbgate-datalib').DisplayColumn|import('dbgate-types').ColumnInfo} */
|
/** @param column {import('dbgate-datalib').DisplayColumn|import('dbgate-types').ColumnInfo} */
|
||||||
export default function ColumnLabel(column) {
|
export default function ColumnLabel(column) {
|
||||||
let icon = null;
|
let icon = column.forceIcon ? 'img column' : null;
|
||||||
if (column.autoIncrement) icon = 'img autoincrement';
|
if (column.autoIncrement) icon = 'img autoincrement';
|
||||||
if (column.foreignKey) icon = 'img foreign-key';
|
if (column.foreignKey) icon = 'img foreign-key';
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ import styled from 'styled-components';
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import ObjectListControl from '../utility/ObjectListControl';
|
import ObjectListControl from '../utility/ObjectListControl';
|
||||||
import { TableColumn } from '../utility/TableControl';
|
import { TableColumn } from '../utility/TableControl';
|
||||||
import columnAppObject from '../appobj/columnAppObject';
|
|
||||||
import constraintAppObject from '../appobj/constraintAppObject';
|
|
||||||
import { useTableInfo, useDbCore } from '../utility/metadataLoaders';
|
import { useTableInfo, useDbCore } from '../utility/metadataLoaders';
|
||||||
import useTheme from '../theme/useTheme';
|
import useTheme from '../theme/useTheme';
|
||||||
|
import ColumnLabel from '../datagrid/ColumnLabel';
|
||||||
|
import { FontIcon } from '../icons';
|
||||||
|
|
||||||
const WhitePage = styled.div`
|
const WhitePage = styled.div`
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@@ -18,6 +18,25 @@ const WhitePage = styled.div`
|
|||||||
overflow: auto;
|
overflow: auto;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const IconTextSpan = styled.span`
|
||||||
|
white-space: nowrap;
|
||||||
|
`;
|
||||||
|
|
||||||
|
function getConstraintIcon(data) {
|
||||||
|
if (data.constraintType == 'primaryKey') return 'img primary-key';
|
||||||
|
if (data.constraintType == 'foreignKey') return 'img foreign-key';
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ConstraintLabel({ data }) {
|
||||||
|
const icon = getConstraintIcon(data);
|
||||||
|
return (
|
||||||
|
<IconTextSpan>
|
||||||
|
<FontIcon icon={icon} /> {data.constraintName}
|
||||||
|
</IconTextSpan>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export default function TableStructureTab({ conid, database, schemaName, pureName, objectTypeField = 'tables' }) {
|
export default function TableStructureTab({ conid, database, schemaName, pureName, objectTypeField = 'tables' }) {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const tableInfo = useDbCore({ conid, database, schemaName, pureName, objectTypeField });
|
const tableInfo = useDbCore({ conid, database, schemaName, pureName, objectTypeField });
|
||||||
@@ -27,7 +46,8 @@ export default function TableStructureTab({ conid, database, schemaName, pureNam
|
|||||||
<WhitePage theme={theme}>
|
<WhitePage theme={theme}>
|
||||||
<ObjectListControl
|
<ObjectListControl
|
||||||
collection={columns.map((x, index) => ({ ...x, ordinal: index + 1 }))}
|
collection={columns.map((x, index) => ({ ...x, ordinal: index + 1 }))}
|
||||||
makeAppObj={columnAppObject}
|
NameComponent={({ data }) => <ColumnLabel {...data} forceIcon />}
|
||||||
|
// makeAppObj={columnAppObject}
|
||||||
title="Columns"
|
title="Columns"
|
||||||
>
|
>
|
||||||
<TableColumn
|
<TableColumn
|
||||||
@@ -77,7 +97,7 @@ export default function TableStructureTab({ conid, database, schemaName, pureNam
|
|||||||
/> */}
|
/> */}
|
||||||
</ObjectListControl>
|
</ObjectListControl>
|
||||||
|
|
||||||
<ObjectListControl collection={_.compact([primaryKey])} makeAppObj={constraintAppObject} title="Primary key">
|
<ObjectListControl collection={_.compact([primaryKey])} NameComponent={ConstraintLabel} title="Primary key">
|
||||||
<TableColumn
|
<TableColumn
|
||||||
fieldName="columns"
|
fieldName="columns"
|
||||||
header="Columns"
|
header="Columns"
|
||||||
@@ -85,7 +105,7 @@ export default function TableStructureTab({ conid, database, schemaName, pureNam
|
|||||||
/>
|
/>
|
||||||
</ObjectListControl>
|
</ObjectListControl>
|
||||||
|
|
||||||
<ObjectListControl collection={foreignKeys} makeAppObj={constraintAppObject} title="Foreign keys">
|
<ObjectListControl collection={foreignKeys} NameComponent={ConstraintLabel} title="Foreign keys">
|
||||||
<TableColumn
|
<TableColumn
|
||||||
fieldName="baseColumns"
|
fieldName="baseColumns"
|
||||||
header="Base columns"
|
header="Base columns"
|
||||||
@@ -101,7 +121,7 @@ export default function TableStructureTab({ conid, database, schemaName, pureNam
|
|||||||
<TableColumn fieldName="deleteAction" header="ON DELETE" />
|
<TableColumn fieldName="deleteAction" header="ON DELETE" />
|
||||||
</ObjectListControl>
|
</ObjectListControl>
|
||||||
|
|
||||||
<ObjectListControl collection={dependencies} makeAppObj={constraintAppObject} title="Dependencies">
|
<ObjectListControl collection={dependencies} NameComponent={ConstraintLabel} title="Dependencies">
|
||||||
<TableColumn
|
<TableColumn
|
||||||
fieldName="baseColumns"
|
fieldName="baseColumns"
|
||||||
header="Base columns"
|
header="Base columns"
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ const ObjectListBody = styled.div`
|
|||||||
// margin-top: 3px;
|
// margin-top: 3px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export default function ObjectListControl({ collection = [], title, showIfEmpty = false, makeAppObj, children }) {
|
export default function ObjectListControl({ collection = [], title, showIfEmpty = false, NameComponent, children }) {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
if (collection.length == 0 && !showIfEmpty) return null;
|
if (collection.length == 0 && !showIfEmpty) return null;
|
||||||
|
|
||||||
@@ -36,11 +36,7 @@ export default function ObjectListControl({ collection = [], title, showIfEmpty
|
|||||||
</ObjectListHeader>
|
</ObjectListHeader>
|
||||||
<ObjectListBody>
|
<ObjectListBody>
|
||||||
<TableControl rows={collection}>
|
<TableControl rows={collection}>
|
||||||
<TableColumn
|
<TableColumn fieldName="displayName" header="Name" formatter={(data) => <NameComponent data={data} />} />
|
||||||
fieldName="displayName"
|
|
||||||
header="Name"
|
|
||||||
// formatter={(col) => <AppObjectControl data={col} makeAppObj={makeAppObj} component="span" />}
|
|
||||||
/>
|
|
||||||
{children}
|
{children}
|
||||||
</TableControl>
|
</TableControl>
|
||||||
</ObjectListBody>
|
</ObjectListBody>
|
||||||
|
|||||||
Reference in New Issue
Block a user