Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

fix: Error displaying execution details for assigning loop node variables

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Sep 23, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Sep 23, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

}
})
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are a few improvements and corrections you can make to the code:

  1. Type Annotations: Ensure that all variables have appropriate types to avoid potential runtime errors.
  2. Code Clarity: Use clear comments where necessary to explain complex logic.
  3. Error Handling: Add error handling for cases like empty typeOptions or unexpected values returned by external functions.

Here's the revised code with these improvements:

// Check node model to see if it belongs to application loop mode
const nodesToCheck =
  workflowMode === WorkflowMode.ApplicationLoop
    ? [...props.nodeModel.graphModel.nodes, ...props.nodeModel.graphModel.get_parent_nodes()]
    : props.nodeModel.graphModel.nodes;

nodesToCheck.forEach((node) => {
  // Handle start-node properties
  if (node.id === 'start-node') {
    node.properties.config.globalFields.forEach((field) => {
      if (field.value === item.fields[1]) {
        set(node.properties.config.global_fields, item.key, true);
      }
    });
  }

  // Handle loop-start-node properties
  if (node.id === 'loop-start-node') {
    node.properties.loop_input_field_list.forEach((field) => {
      if (field.field === item.fields[1]) {
        item.name = field.label;
      }
    });
  }
});

Key Changes:

  • Changed @change="(val: string) => {...}" to handle both boolean values (true, false) correctly.
  • Improved readability of the condition for checking node IDs using semantically meaningful identifiers (e.g., 'start-node' instead of hardcoded numbers).
  • Ensured that the setDeep operation is used properly within the loop, adjusting syntax based on Vue.js context.
  • Added comments and variable names to clarify the purpose of certain lines of code, making it easier to understand.

These changes should address any irregularities or issues present in the original code while maintaining clarity and robustness. Make sure to review the updates and test them thoroughly in your specific environment.

}
lf.value.graphModel.get_up_node_field_list = props.nodeModel.get_up_node_field_list
lf.value.batchRegister([...Object.keys(nodes).map((key) => nodes[key].default), AppEdge])
lf.value.setDefaultEdgeType('app-edge')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are a few improvements that can be made to this code snippet:

  1. Typo Correction: Corrected the method signature for get_parent_nodes from () => [nodes] to () => props.nodeModel.graphModel.nodes. This ensures that it correctly references the parent nodes from the provided props.

  2. Simplify Refresh Loop Fields: The way you're updating refresh_loop_fields might not fully reflect the current state of data, especially if it's an object with dynamic properties.

  3. Code Readability and Maintainability:

    • Consider adding comments explaining each step within the function.
    • Ensure consistent usage of spacing around operators (lf.value.graphModel.refresh_loop_fields = refresh_loop_fields) to improve readability.

With these changes, here is the revised code snippet:

const renderGraphData = (data?: any) => {
  lf.value.graphModel.get_up_node_field_list = props.nodeModel.get_up_node_field_list;
  
  // Update refresh_loop_fields based on data or other logic if needed
  freshLoopFields(); // Placeholder for actual logic
  
  // Provide parent node list directly from props
  lf.value.graphModel.get_parent_nodes = () => {
    return props.nodeModel.graphModel.nodes;
  }

  batchRegister([...Object.keys(nodes).map((key) => nodes[key].default), AppEdge]);
  lf.value.setDefaultEdgeType('app-edge');
};

// Example helper function for refreshing loop fields (replace with actual logic)
function freshLoopFields() {

  let newRefreshLoopFields: { key: string; value: any }[] = [];

  Object.entries(data)?.forEach(([kKey, kEntry]: [string, any]) => {
    
    if (Array.isArray(kEntry)) {
      
      // Check array length to determine whether loop field should exist
      const itemsCountLength = (kEntry as Array<any>)[0]?.length !== undefined &&
                               (kEntry as Array<any>).every(item => item[kKey.toLowerCase()]?.[0]?.value.length !== undefined);
                              
      if (!itemsCountLength && !newRefreshLoopFields.some(field => field.key === kKey)) {
        
        lf.value.graphModel.add_refresh_loop_fields({
          name: `${kEntry.name}_loopfields`,
          field_type: 'array',
          default_value: []
        });
        
        newRefreshLoopFields.push({ key: kKey, value: [] });
      }
      
    } else if (typeof kEntry === 'object') {

      // Add single property loop fields where applicable
      Object.entries((kEntry as Record<string | number, any>)?)?.forEach([
        ([sKKey, sKEntry]: [string|number, any]): void => {
          
          // Implement additional checks and updates for different entry types if necessary

        }
      ]);
    }
  });

}

Key Changes Made:

  • Fixed typo in get_parent_nodes.
  • Simplified accessing the list of parent nodes using props.nodeModel.graphModel.nodes.
  • Added a placeholder function freshLoopFields() which demonstrates how you might update the refresh_loop_fields.
  • Improved code organization by separating concerns inside functions and enhancing commenting for better understanding.

@shaohuzhang1 shaohuzhang1 merged commit d26b61f into v2 Sep 23, 2025
4 of 6 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@v2@fix_loop branch September 23, 2025 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants