feat: restrict classification operators cannot be connected to Answer and other classification #918 (#1294)

### What problem does this PR solve?

feat: restrict classification operators cannot be connected to Answer
and other classification #918

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2024-06-27 14:57:40 +08:00
committed by GitHub
parent 0ce720a247
commit fbb8cbfc67
9 changed files with 193 additions and 42 deletions

View File

@@ -3,9 +3,13 @@ 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 { Connection, Edge, MarkerType, Node, Position } from 'reactflow';
import { v4 as uuidv4 } from 'uuid';
import { Operator, initialFormValuesMap } from './constant';
import {
Operator,
RestrictedUpstreamMap,
initialFormValuesMap,
} from './constant';
import { NodeData } from './interface';
const buildEdges = (
@@ -162,3 +166,14 @@ export const buildDslComponentsByGraph = (
return components;
};
export const getOperatorType = (id: string | null) => {
return id?.split(':')[0] as Operator | undefined;
};
// restricted lines cannot be connected successfully.
export const isValidConnection = (connection: Connection) => {
return RestrictedUpstreamMap[
getOperatorType(connection.source) as Operator
]?.every((x) => x !== getOperatorType(connection.target));
};