mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-24 15:15:59 +00:00
designer - output columns
This commit is contained in:
@@ -158,6 +158,31 @@ export default function Designer({ value, onChange }) {
|
|||||||
[onChange]
|
[onChange]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleChangeColumn = React.useCallback(
|
||||||
|
(column, changeFunc) => {
|
||||||
|
onChange((current) => {
|
||||||
|
const existing = (current.columns || []).find(
|
||||||
|
(x) => x.designerId == column.designerId && x.columnName == column.columnName
|
||||||
|
);
|
||||||
|
if (existing) {
|
||||||
|
return {
|
||||||
|
...current,
|
||||||
|
columns: current.columns.map((x) => (x == existing ? changeFunc(existing) : x)),
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
...current,
|
||||||
|
columns: [
|
||||||
|
...cleanupDesignColumns(current.columns),
|
||||||
|
changeFunc(_.pick(column, ['designerId', 'columnName'])),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[onChange]
|
||||||
|
);
|
||||||
|
|
||||||
// React.useEffect(() => {
|
// React.useEffect(() => {
|
||||||
// setTimeout(() => setChangeToken((x) => x + 1), 100);
|
// setTimeout(() => setChangeToken((x) => x + 1), 100);
|
||||||
// }, [value]);
|
// }, [value]);
|
||||||
@@ -185,6 +210,7 @@ export default function Designer({ value, onChange }) {
|
|||||||
setTargetDragColumn={setTargetDragColumn}
|
setTargetDragColumn={setTargetDragColumn}
|
||||||
onCreateReference={handleCreateReference}
|
onCreateReference={handleCreateReference}
|
||||||
onSelectColumn={handleSelectColumn}
|
onSelectColumn={handleSelectColumn}
|
||||||
|
onChangeColumn={handleChangeColumn}
|
||||||
table={table}
|
table={table}
|
||||||
onChangeTable={changeTable}
|
onChangeTable={changeTable}
|
||||||
onBringToFront={bringToFront}
|
onBringToFront={bringToFront}
|
||||||
@@ -194,6 +220,7 @@ export default function Designer({ value, onChange }) {
|
|||||||
onChangeDomTable={(table) => {
|
onChangeDomTable={(table) => {
|
||||||
domTablesRef.current[table.designerId] = table;
|
domTablesRef.current[table.designerId] = table;
|
||||||
}}
|
}}
|
||||||
|
designer={value}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</Canvas>
|
</Canvas>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { FontIcon } from '../icons';
|
|||||||
import useTheme from '../theme/useTheme';
|
import useTheme from '../theme/useTheme';
|
||||||
import DomTableRef from './DomTableRef';
|
import DomTableRef from './DomTableRef';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import { CheckboxField } from '../utility/inputs';
|
||||||
|
|
||||||
const Wrapper = styled.div`
|
const Wrapper = styled.div`
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@@ -86,6 +87,7 @@ export default function DesignerTable({
|
|||||||
onRemoveTable,
|
onRemoveTable,
|
||||||
onCreateReference,
|
onCreateReference,
|
||||||
onSelectColumn,
|
onSelectColumn,
|
||||||
|
onChangeColumn,
|
||||||
sourceDragColumn,
|
sourceDragColumn,
|
||||||
setSourceDragColumn,
|
setSourceDragColumn,
|
||||||
targetDragColumn,
|
targetDragColumn,
|
||||||
@@ -93,6 +95,7 @@ export default function DesignerTable({
|
|||||||
onChangeDomTable,
|
onChangeDomTable,
|
||||||
wrapperRef,
|
wrapperRef,
|
||||||
setChangeToken,
|
setChangeToken,
|
||||||
|
designer,
|
||||||
}) {
|
}) {
|
||||||
const { pureName, columns, left, top, designerId } = table;
|
const { pureName, columns, left, top, designerId } = table;
|
||||||
const [movingPosition, setMovingPosition] = React.useState(null);
|
const [movingPosition, setMovingPosition] = React.useState(null);
|
||||||
@@ -243,12 +246,38 @@ export default function DesignerTable({
|
|||||||
setSourceDragColumn(null);
|
setSourceDragColumn(null);
|
||||||
}}
|
}}
|
||||||
onMouseDown={(e) =>
|
onMouseDown={(e) =>
|
||||||
onSelectColumn({
|
onSelectColumn({
|
||||||
...column,
|
...column,
|
||||||
designerId,
|
designerId,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
<CheckboxField
|
||||||
|
checked={
|
||||||
|
!!(designer.columns || []).find(
|
||||||
|
(x) => x.designerId == designerId && x.columnName == column.columnName && x.isOutput
|
||||||
|
)
|
||||||
|
}
|
||||||
|
onChange={(e) => {
|
||||||
|
if (e.target.checked) {
|
||||||
|
onChangeColumn(
|
||||||
|
{
|
||||||
|
...column,
|
||||||
|
designerId,
|
||||||
|
},
|
||||||
|
(col) => ({ ...col, isOutput: true })
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
onChangeColumn(
|
||||||
|
{
|
||||||
|
...column,
|
||||||
|
designerId,
|
||||||
|
},
|
||||||
|
(col) => ({ ...col, isOutput: false })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
<ColumnLabel {...column} forceIcon />
|
<ColumnLabel {...column} forceIcon />
|
||||||
</ColumnLine>
|
</ColumnLine>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { dumpSqlSelect, Select, JoinType, Condition, Relation, mergeConditions } from 'dbgate-sqltree';
|
import { dumpSqlSelect, Select, JoinType, Condition, Relation, mergeConditions, Source } from 'dbgate-sqltree';
|
||||||
import { EngineDriver } from 'dbgate-types';
|
import { EngineDriver } from 'dbgate-types';
|
||||||
import { DesignerInfo, DesignerTableInfo, DesignerReferenceInfo, DesignerJoinType } from './types';
|
import { DesignerInfo, DesignerTableInfo, DesignerReferenceInfo, DesignerJoinType } from './types';
|
||||||
|
|
||||||
@@ -67,6 +67,14 @@ function findConnectingReference(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function findQuerySource(designer: DesignerInfo, designerId: string): Source {
|
||||||
|
const table = designer.tables.find((x) => x.designerId == designerId);
|
||||||
|
if (!table) return null;
|
||||||
|
return {
|
||||||
|
name: table,
|
||||||
|
alias: table.alias,
|
||||||
|
};
|
||||||
|
}
|
||||||
class DesignerComponentCreator {
|
class DesignerComponentCreator {
|
||||||
toAdd: DesignerTableInfo[];
|
toAdd: DesignerTableInfo[];
|
||||||
components: DesignerComponent[] = [];
|
components: DesignerComponent[] = [];
|
||||||
@@ -216,6 +224,22 @@ class DesignerQueryDumper {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const topLevelColumns = this.designer.columns.filter((col) =>
|
||||||
|
topLevelTables.find((tbl) => tbl.designerId == col.designerId)
|
||||||
|
);
|
||||||
|
const outputColumns = topLevelColumns.filter((x) => x.isOutput);
|
||||||
|
if (outputColumns.length == 0) {
|
||||||
|
res.selectAll = true;
|
||||||
|
} else {
|
||||||
|
res.columns = outputColumns.map((col) => ({
|
||||||
|
exprType: 'column',
|
||||||
|
columnName: col.columnName,
|
||||||
|
alias: col.alias,
|
||||||
|
source: findQuerySource(this.designer, col.designerId),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user