|
@@ -4,7 +4,6 @@ import {
|
|
|
PlusCircleOutlined,
|
|
|
EditOutlined
|
|
|
} from '@ant-design/icons';
|
|
|
-import { Node } from '@antv/x6';
|
|
|
import {
|
|
|
Button,
|
|
|
Form,
|
|
@@ -17,7 +16,7 @@ import {
|
|
|
message
|
|
|
} from 'antd';
|
|
|
import ScriptEditor from './ScriptEditor';
|
|
|
-import { getNodeResult } from './request';
|
|
|
+import { getNodeResult, getSqlDsTable } from './request';
|
|
|
|
|
|
const { Panel } = Collapse;
|
|
|
|
|
@@ -29,9 +28,8 @@ export default class ScriptNodeInfo extends React.Component<any, any> {
|
|
|
this.state = {
|
|
|
scriptModalVisible: false,
|
|
|
checking: false,
|
|
|
- inputNumber: 0,
|
|
|
- outputData: [],
|
|
|
- outputEditing: false,
|
|
|
+ inputNumber: 1,
|
|
|
+ outputNumber: 1,
|
|
|
columns: [],
|
|
|
tableData: []
|
|
|
};
|
|
@@ -48,6 +46,7 @@ export default class ScriptNodeInfo extends React.Component<any, any> {
|
|
|
const editorValue = (this.editorRef.current as any).state.editor.getValue();
|
|
|
this.props.nodeInfo.scriptText = editorValue;
|
|
|
this.setState({ scriptModalVisible: false });
|
|
|
+ this.props.changeStatus(this.props.nodeInfo.nodeId);
|
|
|
};
|
|
|
|
|
|
// 提交代码校验
|
|
@@ -60,28 +59,25 @@ export default class ScriptNodeInfo extends React.Component<any, any> {
|
|
|
componentDidMount(): void {
|
|
|
this.setState({
|
|
|
inputNumber: this.props.nodeInfo.inputNumber,
|
|
|
- outputData: this.props.nodeInfo.outputData
|
|
|
+ outputNumber: this.props.nodeInfo.outputNumber
|
|
|
});
|
|
|
}
|
|
|
|
|
|
submit() {
|
|
|
- const { nodeId, nodeName, outputData } = (this.formRef
|
|
|
- .current as any).getFieldsValue();
|
|
|
+ const { nodeId, nodeName } = (this.formRef.current as any).getFieldsValue();
|
|
|
if (nodeName) {
|
|
|
- const id = this.props.nodeInfo.id;
|
|
|
- const node = this.props.graph.getCellById(id);
|
|
|
this.props.nodeInfo.inputNumber = this.state.inputNumber;
|
|
|
- this.updateInputPorts(node, this.state.inputNumber);
|
|
|
this.props.nodeInfo.nodeName = nodeName;
|
|
|
this.props.nodeInfo.nodeId = nodeId;
|
|
|
- this.props.nodeInfo.outputData = outputData;
|
|
|
- this.updateOutputPorts(outputData);
|
|
|
+ this.props.nodeInfo.outputNumber = this.state.outputNumber;
|
|
|
+ this.updateInputPorts(this.state.inputNumber);
|
|
|
+ this.updateOutputPorts(this.state.outputNumber);
|
|
|
this.props.node.setData({ ...this.props.nodeInfo });
|
|
|
this.props.close();
|
|
|
+ this.props.changeStatus(this.props.nodeInfo.nodeId);
|
|
|
} else {
|
|
|
message.error('请输入节点名字');
|
|
|
}
|
|
|
- this.setState({ outputEditing: true });
|
|
|
}
|
|
|
|
|
|
onReset() {
|
|
@@ -90,19 +86,16 @@ export default class ScriptNodeInfo extends React.Component<any, any> {
|
|
|
'nodeName',
|
|
|
this.props.nodeInfo.nodeName
|
|
|
);
|
|
|
- console.log(
|
|
|
- this.props.nodeInfo,
|
|
|
- (this.formRef.current as any).getFieldsValue()
|
|
|
- );
|
|
|
this.setState({
|
|
|
inputNumber: this.props.nodeInfo.inputNumber,
|
|
|
- outputData: this.props.nodeInfo.outputData
|
|
|
+ outputNumber: this.props.nodeInfo.outputNumber
|
|
|
});
|
|
|
- this.setState({ outputEditing: false });
|
|
|
}
|
|
|
|
|
|
// 添加输入端点
|
|
|
- updateInputPorts = (node: Node, number: number) => {
|
|
|
+ updateInputPorts = (number: number) => {
|
|
|
+ const id = this.props.nodeInfo.id;
|
|
|
+ const node = this.props.graph.getCellById(id);
|
|
|
const currentInputPortsNumber = node
|
|
|
.getPorts()
|
|
|
.reduce((pre: number, item: any) => {
|
|
@@ -118,63 +111,59 @@ export default class ScriptNodeInfo extends React.Component<any, any> {
|
|
|
|
|
|
// 更新输入数量
|
|
|
updateNumber = (inputNumber: number) => {
|
|
|
- // const id = this.props.nodeInfo.id;
|
|
|
- // const node = this.props.graph.getCellById(id);
|
|
|
this.setState({ inputNumber });
|
|
|
- // this.props.nodeInfo.inputNumber = inputNumber;
|
|
|
- // this.updateInputPorts(node, inputNumber);
|
|
|
};
|
|
|
|
|
|
- updateOutputPorts = (outputData: any) => {
|
|
|
- const id = this.props.nodeInfo.id;
|
|
|
- const node = this.props.graph.getCellById(id);
|
|
|
- const currentOutputPorts = node.getPorts().reduce((pre: any, item: any) => {
|
|
|
- return item.group === 'bottom' ? pre.concat(item) : pre;
|
|
|
- }, []);
|
|
|
- currentOutputPorts.forEach((item: any) => {
|
|
|
- const index = outputData.findIndex(
|
|
|
- (output: any) => output.outputVar === item.id
|
|
|
- );
|
|
|
- if (index === -1) {
|
|
|
- node.removePort(item.id);
|
|
|
- }
|
|
|
- });
|
|
|
- outputData.forEach((item: any) => {
|
|
|
- const index = currentOutputPorts?.findIndex(
|
|
|
- (port: any) => port.id === item.outputVar
|
|
|
- );
|
|
|
- if (index === -1) {
|
|
|
- node.addPort({ group: 'bottom', id: item.outputVar });
|
|
|
- }
|
|
|
- });
|
|
|
+ updateOutputNumber = (outputNumber: number) => {
|
|
|
+ console.log(outputNumber);
|
|
|
+ this.setState({ outputNumber });
|
|
|
};
|
|
|
|
|
|
- enterOutputVar = (e: any) => {
|
|
|
- const value = e.target.value.trim();
|
|
|
- if (e.key === 'Enter' && value) {
|
|
|
- this.setState({ outputEditing: false });
|
|
|
- const outputData = [...this.state.outputData];
|
|
|
- outputData.push({ outputVar: value });
|
|
|
- this.setState({ outputData });
|
|
|
- // this.updateOutputPorts(outputData);
|
|
|
+ updateOutputPorts = (number: number) => {
|
|
|
+ const id = this.props.nodeInfo.id;
|
|
|
+ const node = this.props.graph.getCellById(id);
|
|
|
+ const currentOutputPortsNumber = node
|
|
|
+ .getPorts()
|
|
|
+ .reduce((pre: number, item: any) => {
|
|
|
+ return item.group === 'bottom' ? pre + 1 : pre;
|
|
|
+ }, 0);
|
|
|
+ for (let i = number; i < currentOutputPortsNumber; i++) {
|
|
|
+ node.removePort(`r${number}`);
|
|
|
+ }
|
|
|
+ for (let i = currentOutputPortsNumber; i < number; i++) {
|
|
|
+ node.addPort({ group: 'bottom', id: `r${i}` });
|
|
|
}
|
|
|
};
|
|
|
|
|
|
changeCollapse = async (val: any) => {
|
|
|
- const params = {
|
|
|
- dag_uuid: this.props.dagId,
|
|
|
- node_id: this.props.scriptInputs[val].nodeId,
|
|
|
- out_pin: this.props.scriptInputs[val].out_pin
|
|
|
- };
|
|
|
- const { data } = await getNodeResult(params);
|
|
|
- if (data.code === 200) {
|
|
|
- const { col, tableData } = this.formatTableData(data.data);
|
|
|
- this.setState({
|
|
|
- columns: col,
|
|
|
- tableData
|
|
|
- });
|
|
|
+ if (
|
|
|
+ this.props.scriptInputs[val].target_type === 'sql' &&
|
|
|
+ this.props.scriptInputs[val].source_type === 'InputSource'
|
|
|
+ ) {
|
|
|
+ const { data } = await getSqlDsTable(
|
|
|
+ this.props.scriptInputs[val].source_tableName
|
|
|
+ );
|
|
|
+ if (data.code === 200) {
|
|
|
+ const { col, tableData } = this.formatTableData(data.data);
|
|
|
+ this.setState({
|
|
|
+ columns: col,
|
|
|
+ tableData
|
|
|
+ });
|
|
|
+ }
|
|
|
} else {
|
|
|
- message.error(data.msg);
|
|
|
+ const params = {
|
|
|
+ dag_uuid: this.props.dagId,
|
|
|
+ node_id: this.props.scriptInputs[val].nodeId,
|
|
|
+ out_pin: this.props.scriptInputs[val].out_pin
|
|
|
+ };
|
|
|
+ const { data } = await getNodeResult(params);
|
|
|
+ if (data.code === 200) {
|
|
|
+ const { col, tableData } = this.formatTableData(data.data);
|
|
|
+ this.setState({
|
|
|
+ columns: col,
|
|
|
+ tableData
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -211,8 +200,7 @@ export default class ScriptNodeInfo extends React.Component<any, any> {
|
|
|
initialValues={{
|
|
|
nodeId: this.props.nodeInfo.nodeId,
|
|
|
paramText: this.props.nodeInfo.paramText,
|
|
|
- nodeName: this.props.nodeInfo.nodeName,
|
|
|
- outputData: this.props.nodeInfo.outputData
|
|
|
+ nodeName: this.props.nodeInfo.nodeName
|
|
|
}}
|
|
|
onValuesChange={(changedValue, values) => {
|
|
|
const paramText = values.paramText;
|
|
@@ -279,80 +267,42 @@ export default class ScriptNodeInfo extends React.Component<any, any> {
|
|
|
</Button>
|
|
|
</Form.Item>
|
|
|
<p>输出结果:</p>
|
|
|
- <Form.List name="outputData">
|
|
|
- {(fields, { add, remove }) => (
|
|
|
- <>
|
|
|
- {fields.map(({ key, name, ...restField }) => (
|
|
|
- <Space
|
|
|
- key={key}
|
|
|
- style={{
|
|
|
- display: 'flex',
|
|
|
- padding: '10px 10px 0',
|
|
|
- background: '#EDF0F6',
|
|
|
- marginBottom: '2px'
|
|
|
- }}
|
|
|
- align="baseline"
|
|
|
- >
|
|
|
- <Form.Item
|
|
|
- label={'输出结果'}
|
|
|
- {...restField}
|
|
|
- name={[name, 'outputVar']}
|
|
|
- >
|
|
|
- {/* <Input placeholder='请输入输出变量' onKeyUp={this.enterOutputVar}/> */}
|
|
|
- {this.state.outputEditing &&
|
|
|
- name === this.state.outputData.length ? (
|
|
|
- <Input
|
|
|
- placeholder="请输入输出变量"
|
|
|
- onKeyUp={this.enterOutputVar}
|
|
|
- />
|
|
|
- ) : (
|
|
|
- <Input
|
|
|
- placeholder="请输入输出变量"
|
|
|
- onKeyUp={this.enterOutputVar}
|
|
|
- disabled
|
|
|
- style={{
|
|
|
- color: 'black',
|
|
|
- border: 'none',
|
|
|
- background: '#edf0f6'
|
|
|
- }}
|
|
|
- />
|
|
|
- )}
|
|
|
- </Form.Item>
|
|
|
- <MinusCircleOutlined
|
|
|
- onClick={() => {
|
|
|
- const outputData = this.state.outputData;
|
|
|
- outputData.splice(name, 1);
|
|
|
- // this.updateOutputPorts(outputData);
|
|
|
- return remove(name);
|
|
|
- }}
|
|
|
- style={{ color: '#147BD1' }}
|
|
|
- />
|
|
|
- </Space>
|
|
|
- ))}
|
|
|
- {!(
|
|
|
- this.props.nodeInfo.label === 'sql' && fields.length > 0
|
|
|
- ) && (
|
|
|
- <Form.Item>
|
|
|
- <Button
|
|
|
- type="link"
|
|
|
- onClick={() => {
|
|
|
- if (this.state.outputEditing) {
|
|
|
- message.warning('请先确认前一个变量!');
|
|
|
- return;
|
|
|
- }
|
|
|
- this.setState({ outputEditing: true });
|
|
|
- return add();
|
|
|
- }}
|
|
|
- icon={<PlusCircleOutlined />}
|
|
|
- style={{ paddingLeft: 0, paddingRight: 0 }}
|
|
|
- >
|
|
|
- 添加输出
|
|
|
- </Button>
|
|
|
- </Form.Item>
|
|
|
- )}
|
|
|
- </>
|
|
|
- )}
|
|
|
- </Form.List>
|
|
|
+ {Array.from({ length: this.state.outputNumber }, (_, i) => (
|
|
|
+ <div
|
|
|
+ style={{
|
|
|
+ display: 'flex',
|
|
|
+ alignItems: 'center',
|
|
|
+ columnGap: '2px',
|
|
|
+ width: '30%',
|
|
|
+ marginBottom: '5px'
|
|
|
+ }}
|
|
|
+ key={i}
|
|
|
+ >
|
|
|
+ <Input disabled style={{ width: '70%' }} defaultValue={`r` + i} />
|
|
|
+ {i === this.state.outputNumber - 1 && (
|
|
|
+ <MinusCircleOutlined
|
|
|
+ onClick={() => {
|
|
|
+ this.updateOutputNumber(this.state.outputNumber - 1);
|
|
|
+ }}
|
|
|
+ style={{ color: '#147BD1' }}
|
|
|
+ />
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
+ ))}
|
|
|
+ {!(
|
|
|
+ this.props.nodeInfo.label === 'sql' && this.state.outputNumber > 0
|
|
|
+ ) && (
|
|
|
+ <Button
|
|
|
+ type="link"
|
|
|
+ onClick={() => {
|
|
|
+ this.updateOutputNumber(this.state.outputNumber + 1);
|
|
|
+ }}
|
|
|
+ icon={<PlusCircleOutlined />}
|
|
|
+ style={{ paddingLeft: 0, paddingRight: 0 }}
|
|
|
+ >
|
|
|
+ 添加输出
|
|
|
+ </Button>
|
|
|
+ )}
|
|
|
<Form.Item style={{ marginTop: '20px' }}>
|
|
|
<Space>
|
|
|
<Button
|
|
@@ -361,7 +311,7 @@ export default class ScriptNodeInfo extends React.Component<any, any> {
|
|
|
this.submit();
|
|
|
}}
|
|
|
>
|
|
|
- 保存
|
|
|
+ 确认
|
|
|
</Button>
|
|
|
<Button
|
|
|
onClick={() => {
|