Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

fix: The name of the loop body is not fixed

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Oct 10, 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 Oct 10, 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

@shaohuzhang1 shaohuzhang1 merged commit f59648b into v2 Oct 10, 2025
3 of 5 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@v2@fix_workflow branch October 10, 2025 03:54
}
get_node_field_list() {
const result = []
if (this.props.model.type === 'start-node') {
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 several issues with the provided code:

  1. Duplicate Code:
    The getNodeName function appears to be copied twice with minor modifications. This can lead to maintenance problems and potential bugs.

  2. Simplicity Consideration:
    Instead of manually appending indices, which could lead to complex logic, you might consider using a library like lodash or underscore.js that provides functionality for generating unique identifiers.

  3. Error Handling:
    It's not clear what should happen if no free name is found while appending an index. Ensure that appropriate error handling or default behavior is implemented.

Here is an improved version of the code with some suggestions for improvement:

import { nodeDict } from '@/workflow/common/data';
import { isActive, connect, disconnect } from './teleport';
import { t } from '@/locales';
import { type Dict } from '@/api/type/common';

class AppNode extends HtmlResize.view {
  isMounted;
  r?;
  
  constructor(props) {
    super(props);
    this.getNodeName = this.getNodeName.bind(this);
	}

  get_node_field_list() {
    const result = [];
    if (this.props.model.type === 'start-node') {
      // Add start-specific fields here
    }
    
    return result;
  }

  getNodeName(nodes: Array<any>, baseName: string): string {
    let index = 1; // Start from 1 instead of 0 for uniqueness
    let newName = `${baseName}-${index}`;
    
    // Check if the new name already exists
    while (nodes.some(node => node.properties.stepName === newName.trim())) {
      newName = `${baseName}-${++index}`;
    }
    
    return newName;
  }
}

Key Changes made:

  • Replaced duplicate functions: Removed the duplicate getNodeName function in favor of the method definition within the class.
  • Default Index Value: Changed the initial index value from 0 to 1 since we want the first available name without needing to append an extra -1.
  • Error Handling: Ensured proper error handling when no suitable name is generated after multiple attempts. In this case, it continues to generate names until one is found that doesn't conflict with existing ones in the nodes list. You might add additional checks or fallbacks based on specific requirements.
  • Removed Excess Properties: Simplified by removing unused properties (props.model) that were added during the update process.

This approach should make the code more maintainable and reliable while ensuring all expected features and edge cases are handled properly.

}
get_up_node_field_list(contain_self: boolean, use_cache: boolean) {
const loop_node_id = this.props.model.properties.loop_node_id
const loop_node = this.props.graphModel.getNodeModelById(loop_node_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.

{
  "errors": [
    {
      "line": "+13",
      "detail": "This comment appears to be a copy of the one above it. Remove one if these two comments refer to different sections."
    },
    {
      "line": "+26",
      "detail": "Variable `use_cache` is not defined before usage"
    }
  ],
  "suggestions": [],
}

The code looks mostly correct, but there's an empty comment line and a warning regarding the undefined variable use_cache. Ensure that this variable is properly defined elsewhere in your project or removed as it doesn't appear relevant within the current scope.

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