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

### 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)
This commit is contained in:
balibabu 2024-07-08 11:42:12 +08:00 committed by GitHub
parent 1cff117dc9
commit 0f597b9817
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 0 deletions

View File

@ -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 = {

View File

@ -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