feat: Build the edges of Switch by form data #1739 (#2022)

### What problem does this PR solve?

feat: Build the edges of Switch  by form data #1739

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2024-08-20 19:27:49 +08:00
committed by GitHub
parent 7927d80a84
commit 96438ca821
6 changed files with 128 additions and 37 deletions

View File

@ -23,7 +23,7 @@ import { devtools } from 'zustand/middleware';
import { immer } from 'zustand/middleware/immer';
import { Operator } from './constant';
import { NodeData } from './interface';
import { isEdgeEqual } from './utils';
import { getOperatorIndex, isEdgeEqual } from './utils';
export type RFState = {
nodes: Node<NodeData>[];
@ -184,14 +184,19 @@ const useGraphStore = create<RFState>()(
'to',
]);
break;
// case Operator.Switch:
// if (sourceHandle)
// updateNodeForm(source, target, [
// 'conditions',
// sourceHandle,
// 'to',
// ]);
// break;
case Operator.Switch: {
if (sourceHandle) {
const operatorIndex = getOperatorIndex(sourceHandle);
if (operatorIndex) {
updateNodeForm(source, target, [
'conditions',
operatorIndex,
'to',
]);
}
}
break;
}
default:
break;
}
@ -201,7 +206,11 @@ const useGraphStore = create<RFState>()(
// Delete the edge on the classification node or relevant node anchor when the anchor is connected to other nodes
const { edges, getOperatorTypeFromId, deleteEdgeById } = get();
// the node containing the anchor
const anchoredNodes = [Operator.Categorize, Operator.Relevant];
const anchoredNodes = [
Operator.Categorize,
Operator.Relevant,
Operator.Switch,
];
if (
anchoredNodes.some(
(x) => x === getOperatorTypeFromId(connection.source),
@ -265,6 +274,19 @@ const useGraphStore = create<RFState>()(
'to',
]);
break;
case Operator.Switch: {
if (sourceHandle) {
const operatorIndex = getOperatorIndex(sourceHandle);
if (operatorIndex) {
updateNodeForm(source, undefined, [
'conditions',
operatorIndex,
'to',
]);
}
}
break;
}
default:
break;
}