Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ui/src/workflow/common/app-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,9 @@ class AppNodeModel extends HtmlResize.model {
this.sourceRules.push({
message: t('views.applicationWorkflow.tip.notRecyclable'),
validate: (sourceNode: any, targetNode: any, sourceAnchor: any, targetAnchor: any) => {
return !isLoop(sourceNode.id, targetNode.id)
const up_node_list = this.graphModel.getNodeIncomingNode(targetNode.id)
const is_c = up_node_list.find((up_node) => up_node.id == sourceNode.id)
return !is_c && !isLoop(sourceNode.id, targetNode.id)
},
})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code has a minor issue where it checks if there's a loop between nodes before determining if one node can be placed in another without causing recursion. This seems to unnecessarily double-check the non-loop condition.

Here is an improved version of the function:

validate: (
  sourceNode: any,
  targetNode: any,
  sourceAnchor: any,
  targetAnchor: any
) => {
  const up_nodes = this.graphModel.getNodeIncomingNodes(targetNode.id);
  const is_c_or_loop = up_nodes.some(up_node => up_node.id === sourceNode.id || isLoop(sourceNode.id, targetNode.id));
  return !is_c_or_loop;
}

By combining the two conditions into a single some call using logical OR (||), we avoid redundant checking. If either condition (up_node.id === sourceNode.id or isLoop) evaluates to true, the function returns false, meaning the placement is invalid due to recursion. Otherwise, it returns true.

Expand Down
Loading