balibabu commited on
Commit
60dc256
·
1 Parent(s): 12f28d5

feat: node cannot connect to itself #918 (#1412)

Browse files

### What problem does this PR solve?

feat: node cannot connect to itself #918

### Type of change

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

web/src/pages/flow/constant.tsx CHANGED
@@ -254,6 +254,9 @@ export const RestrictedUpstreamMap = {
254
  Operator.Categorize,
255
  Operator.Relevant,
256
  ],
 
 
 
257
  };
258
 
259
  export const NodeMap = {
 
254
  Operator.Categorize,
255
  Operator.Relevant,
256
  ],
257
+ [Operator.KeywordExtract]: [Operator.Begin],
258
+ [Operator.Baidu]: [Operator.Begin],
259
+ [Operator.DuckDuckGo]: [Operator.Begin],
260
  };
261
 
262
  export const NodeMap = {
web/src/pages/flow/hooks.ts CHANGED
@@ -297,12 +297,16 @@ export const useValidateConnection = () => {
297
  // restricted lines cannot be connected successfully.
298
  const isValidConnection = useCallback(
299
  (connection: Connection) => {
 
 
 
300
  // limit the connection between two nodes to only one connection line in one direction
301
  const hasLine = edges.some(
302
  (x) => x.source === connection.source && x.target === connection.target,
303
  );
304
 
305
  const ret =
 
306
  !hasLine &&
307
  RestrictedUpstreamMap[
308
  getOperatorTypeFromId(connection.source) as Operator
 
297
  // restricted lines cannot be connected successfully.
298
  const isValidConnection = useCallback(
299
  (connection: Connection) => {
300
+ // node cannot connect to itself
301
+ const isSelfConnected = connection.target === connection.source;
302
+
303
  // limit the connection between two nodes to only one connection line in one direction
304
  const hasLine = edges.some(
305
  (x) => x.source === connection.source && x.target === connection.target,
306
  );
307
 
308
  const ret =
309
+ !isSelfConnected &&
310
  !hasLine &&
311
  RestrictedUpstreamMap[
312
  getOperatorTypeFromId(connection.source) as Operator