feat: run flow (#1076)

### What problem does this PR solve?

feat: run flow #918 

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2024-06-06 15:00:37 +08:00
committed by GitHub
parent d9dc183a0e
commit db35e9df4f
9 changed files with 88 additions and 20 deletions

View File

@@ -1,8 +1,11 @@
import { DSLComponents } from '@/interfaces/database/flow';
import { removeUselessFieldsFromValues } from '@/utils/form';
import dagre from 'dagre';
import { curry, isEmpty } from 'lodash';
import pipe from 'lodash/fp/pipe';
import { Edge, MarkerType, Node, Position } from 'reactflow';
import { v4 as uuidv4 } from 'uuid';
import { Operator, initialFormValuesMap } from './constant';
import { NodeData } from './interface';
const buildEdges = (
@@ -109,15 +112,27 @@ const buildComponentDownstreamOrUpstream = (
.map((y) => y[isBuildDownstream ? 'target' : 'source']);
};
const removeUselessDataInTheOperator = (
operatorName: string,
params: Record<string, unknown>,
) => {
if (operatorName === 'Generate') {
return removeUselessFieldsFromValues(params, '');
const removeUselessDataInTheOperator = curry(
(operatorName: string, params: Record<string, unknown>) => {
if (operatorName === Operator.Generate) {
return removeUselessFieldsFromValues(params, '');
}
return params;
},
);
// initialize data for operators without parameters
const initializeOperatorParams = curry((operatorName: string, values: any) => {
if (isEmpty(values)) {
return initialFormValuesMap[operatorName as Operator];
}
return params;
};
return values;
});
const buildOperatorParams = (operatorName: string) =>
pipe(
removeUselessDataInTheOperator(operatorName),
initializeOperatorParams(operatorName), // Final processing, for guarantee
);
// construct a dsl based on the node information of the graph
export const buildDslComponentsByGraph = (
@@ -132,9 +147,13 @@ export const buildDslComponentsByGraph = (
components[id] = {
obj: {
component_name: operatorName,
// params:
// removeUselessDataInTheOperator(
// operatorName,
// x.data.form as Record<string, unknown>,
// ) ?? {},
params:
removeUselessDataInTheOperator(
operatorName,
buildOperatorParams(operatorName)(
x.data.form as Record<string, unknown>,
) ?? {},
},