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
7 changes: 5 additions & 2 deletions ui/src/workflow/common/app-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,11 @@ class AppNodeModel extends HtmlResize.model {
if (targetNode.id == sourceNode.id) {
return false
}
const up_node_list = this.graphModel.getNodeIncomingNode(targetNode.id)
const is_c = up_node_list.find((up_node) => up_node.id == sourceNode.id)
const up_edge_list = this.graphModel.getNodeIncomingEdge(targetNode.id)
const is_c = up_edge_list.find(
(up_edge) =>
up_edge.targetAnchorId == targetAnchor.id && up_edge.sourceAnchorId == sourceAnchor.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 code you provided looks mostly intact, but there are some improvements that can be made:

  1. Function Documentation: Consider adding comments to explain the purpose of each function and its usage to improve readability.

  2. Variable Naming: While 'sourceAnchor' and 'targetAnchor' suggest they might represent anchors associated with nodes, make sure these names accurately reflect their roles if needed.

  3. Type Annotations: Using TypeScript or JavaScript's type system can help clarify the types of variables used, which could prevent errors during runtime.

  4. Code Readability: The comparison up_edge_list.find((up_edge) => ...) seems concise enough, but consider grouping related operations inside a helper function for better separation of concerns.

  5. Error Handling: If is_c could potentially be undefined, it'd be worth handling this case appropriately, perhaps returning a default value or throwing an error.

  6. Consistency: Ensure consistent spelling and formatting throughout the code for better maintainability.

Here's a slightly refined version of the code with these considerations:

class AppNodeModel extends HtmlResize.model {
  constructor(graphModel) {
    super();
    this.graphModel = graphModel;
  }

  updateTargetConnection(targetNode, sourceNode) {
    // Check for loop condition
    const isLoop = (nodeA, nodeB) => {
      let current = nodeB;
      while (current !== undefined && current.id !== nodeA) {
        current = this.graphModel.getNodeIncomingNode(current.id)[0] || null; // Simplified assumption
      }
      return current !== null;
    };

    // Return true if no cycle exists between targetNode and sourceNode
    const isValidConnection = () => {

      // Edge list approach
      const upEdgeList = this.graphModel.getNodeIncomingEdge(targetNode.id);
     
      // Filter edges based on anchor IDs
      const edgeForAnchors = upEdgeList?.find(
          (e) => e.targetAnchorId === targetAnchor.id && e.sourceAnchorId === sourceAnchor.id
      );

      // Return false if there's a direct path from source to target via anchor connections and not already connected
      return !edgeForAnchors && !isLoop(sourceNode.id, targetNode.id);
    };
    
    // Additional logic here...
  }
}

// Example usage
const appNodeModel = new AppNodeModel(new GraphModel());
appNodeModel.updateTargetConnection(nodeA, nodeB);

This refactoring improves the clarity and functionality of your code while enhancing maintainability and readability.

Expand Down
Loading