Skip to content

Commit

Permalink
feat: node cannot connect to itself infiniflow#918 (infiniflow#1412)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

feat: node cannot connect to itself infiniflow#918

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
  • Loading branch information
cike8899 authored Jul 8, 2024
1 parent 6d8ff2a commit 6acf03d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions web/src/pages/flow/constant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ export const RestrictedUpstreamMap = {
Operator.Categorize,
Operator.Relevant,
],
[Operator.KeywordExtract]: [Operator.Begin],
[Operator.Baidu]: [Operator.Begin],
[Operator.DuckDuckGo]: [Operator.Begin],
};

export const NodeMap = {
Expand Down
4 changes: 4 additions & 0 deletions web/src/pages/flow/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,16 @@ export const useValidateConnection = () => {
// restricted lines cannot be connected successfully.
const isValidConnection = useCallback(
(connection: Connection) => {
// node cannot connect to itself
const isSelfConnected = connection.target === connection.source;

// limit the connection between two nodes to only one connection line in one direction
const hasLine = edges.some(
(x) => x.source === connection.source && x.target === connection.target,
);

const ret =
!isSelfConnected &&
!hasLine &&
RestrictedUpstreamMap[
getOperatorTypeFromId(connection.source) as Operator
Expand Down

0 comments on commit 6acf03d

Please sign in to comment.