balibabu commited on
Commit
06a1fe2
·
1 Parent(s): 457b4e6

feat: delete the edge on the classification node anchor when the anch… (#1297)

Browse files

### What problem does this PR solve?

feat: delete the edge on the classification node anchor when the anchor
is connected to other nodes #918

### Type of change

- [x] New Feature (non-breaking change which adds functionality)

web/src/pages/flow/store.ts CHANGED
@@ -19,6 +19,7 @@ import { create } from 'zustand';
19
  import { devtools } from 'zustand/middleware';
20
  import { Operator } from './constant';
21
  import { NodeData } from './interface';
 
22
 
23
  export type RFState = {
24
  nodes: Node<NodeData>[];
@@ -35,6 +36,7 @@ export type RFState = {
35
  addNode: (nodes: Node) => void;
36
  getNode: (id: string) => Node | undefined;
37
  addEdge: (connection: Connection) => void;
 
38
  duplicateNode: (id: string) => void;
39
  deleteEdge: () => void;
40
  deleteEdgeById: (id: string) => void;
@@ -66,6 +68,7 @@ const useGraphStore = create<RFState>()(
66
  set({
67
  edges: addEdge(connection, get().edges),
68
  });
 
69
  },
70
  onSelectionChange: ({ nodes, edges }: OnSelectionChangeParams) => {
71
  set({
@@ -90,6 +93,23 @@ const useGraphStore = create<RFState>()(
90
  edges: addEdge(connection, get().edges),
91
  });
92
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  // addOnlyOneEdgeBetweenTwoNodes: (connection: Connection) => {
94
 
95
  // },
 
19
  import { devtools } from 'zustand/middleware';
20
  import { Operator } from './constant';
21
  import { NodeData } from './interface';
22
+ import { getOperatorTypeFromId } from './utils';
23
 
24
  export type RFState = {
25
  nodes: Node<NodeData>[];
 
36
  addNode: (nodes: Node) => void;
37
  getNode: (id: string) => Node | undefined;
38
  addEdge: (connection: Connection) => void;
39
+ deletePreviousEdgeOfClassificationNode: (connection: Connection) => void;
40
  duplicateNode: (id: string) => void;
41
  deleteEdge: () => void;
42
  deleteEdgeById: (id: string) => void;
 
68
  set({
69
  edges: addEdge(connection, get().edges),
70
  });
71
+ get().deletePreviousEdgeOfClassificationNode(connection);
72
  },
73
  onSelectionChange: ({ nodes, edges }: OnSelectionChangeParams) => {
74
  set({
 
93
  edges: addEdge(connection, get().edges),
94
  });
95
  },
96
+ deletePreviousEdgeOfClassificationNode: (connection: Connection) => {
97
+ // Delete the edge on the classification node anchor when the anchor is connected to other nodes
98
+ const { edges } = get();
99
+ if (getOperatorTypeFromId(connection.source) === Operator.Categorize) {
100
+ const previousEdge = edges.find(
101
+ (x) =>
102
+ x.source === connection.source &&
103
+ x.sourceHandle === connection.sourceHandle &&
104
+ x.target !== connection.target,
105
+ );
106
+ if (previousEdge) {
107
+ set({
108
+ edges: edges.filter((edge) => edge !== previousEdge),
109
+ });
110
+ }
111
+ }
112
+ },
113
  // addOnlyOneEdgeBetweenTwoNodes: (connection: Connection) => {
114
 
115
  // },
web/src/pages/flow/utils.ts CHANGED
@@ -167,13 +167,13 @@ export const buildDslComponentsByGraph = (
167
  return components;
168
  };
169
 
170
- export const getOperatorType = (id: string | null) => {
171
  return id?.split(':')[0] as Operator | undefined;
172
  };
173
 
174
  // restricted lines cannot be connected successfully.
175
  export const isValidConnection = (connection: Connection) => {
176
  return RestrictedUpstreamMap[
177
- getOperatorType(connection.source) as Operator
178
- ]?.every((x) => x !== getOperatorType(connection.target));
179
  };
 
167
  return components;
168
  };
169
 
170
+ export const getOperatorTypeFromId = (id: string | null) => {
171
  return id?.split(':')[0] as Operator | undefined;
172
  };
173
 
174
  // restricted lines cannot be connected successfully.
175
  export const isValidConnection = (connection: Connection) => {
176
  return RestrictedUpstreamMap[
177
+ getOperatorTypeFromId(connection.source) as Operator
178
+ ]?.every((x) => x !== getOperatorTypeFromId(connection.target));
179
  };