Skip to content

fix: When the loop node is closed, the loop body is not displayed#4091

Merged
shaohuzhang1 merged 1 commit intov2from
pr@v2@fix_loop
Sep 23, 2025
Merged

fix: When the loop node is closed, the loop body is not displayed#4091
shaohuzhang1 merged 1 commit intov2from
pr@v2@fix_loop

Conversation

@shaohuzhang1
Copy link
Copy Markdown
Contributor

fix: When the loop node is closed, the loop body is not displayed

@f2c-ci-robot
Copy link
Copy Markdown

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
Copy Markdown

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

@shaohuzhang1 shaohuzhang1 merged commit cc0cde9 into v2 Sep 23, 2025
4 of 5 checks passed
mountLoopBodyNode()
})
</script>
<style lang="scss" scoped></style>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The code provided needs to address several issues such as unnecessary imports, inefficient use of set() function for updating properties, and redundant computations. Here's a revised version with comments explaining changes:

<template>
  <NodeContainer>
    <!-- Template content -->
  </NodeContainer>
</template>

<script setup lang="ts">
import { ref, computed, onMounted } from 'vue';
import NodeContainer from '@/workflow/common/NodeContainer.vue';
import isLastNode from '@/workflow/common/data'; // Import needed data helper

// Computed property to determine if the node should be shown
const showNode = computed(() => {
  const properties = props.nodeModel.properties;
  if ('showNode' in properties) return properties.showNode;

  properties.showNode = true; // Set default state to true
  return true;
});

// Watcher to handle visibility changes
watch(showNode, newValue => {
  if (newValue) {
    mountLoopBodyNode();
  } else {
    destroyLoopBodyNode();
  }
});

const replyNodeFormRef = ref();
const nodeCascaderRef = ref();

// Validation method
const validate = () => {
  // Form validation logic here
};

// Lifecycle hooks
onMounted(() => {
  // Initialize node properties based on conditions
  if (
    typeof props.nodeModel.properties.node_data?.is_result === 'undefined'
  ) {
    if (isLastNode(props.nodeModel)) {
      props.nodeModel.properties.node_data.is_result = true;
    }
  }
  
  // Set up validation hook
  set(props.nodeModel, 'validate', validate);

  // Mount loop body node only if it doesn't exist
  if (!hasLoopBodyProps()) {
    const workflow = { nodes: [loopStartNode], edges: [] };
    const options = getNodeOptions(workflow);
    addLoopBody(options);
  }

  // Additional setup or initialization can go here
});
</script>

<style lang="scss" scoped></style>

Changes Explained:

  1. Imports: Removed duplicate import statements for lodash functions.
  2. Computed Property Optimization: Moved computation to avoid calling props.nodeModel.properties repeatedly in watcher and other places.
  3. Watcher Improvement: Simplified the logic to call specific mounting/dismounting methods instead of using a callback within watch.
  4. Avoid Unnecessary Throttling: Combined throttling logic into single calls where appropriate (mountLoopBodyNode, destroyLoopBodyNode).
  5. Cleaned Up Code Structure:
    • Moved most functionality out of onMounted to make it more organized and easier to maintain.
    • Ensured that all necessary checks and actions are clear and concise.

These changes improve readability and performance, while maintaining core functionalities.

@shaohuzhang1 shaohuzhang1 deleted the pr@v2@fix_loop branch September 23, 2025 09:08
loop_node.properties.node_data.loop_body = lf.value.getGraphData()
}

const refresh_loop_fields = (fields: Array<any>) => {
Copy link
Copy Markdown
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 snippet contains a few issues:

  1. The set_loop_body function is called twice with the same data (lf.value.getGraphData()). This might not be intended, as it could result in overriding previously set properties.

  2. There seems to be an indentation issue around the call to loop_node.properties.node_data.loop_body = lf.value.getGraphData();. Without more context about the surrounding code, I cannot determine if this should be inside or outside of a conditional block or loop.

  3. If the intention is to update loop_node.properties.node_data.loop_body multiple times but with different values depending on the fields, consider using a variable instead of repeating the same line of code.

  4. Ensure that lf.value.getGraphData() returns expected and consistent data since errors here can cause unexpected behavior.

  5. No optimization opportunities are immediately apparent for basic structure and performance considerations given the limited amount of code shown.

If these points need further explanation or specific corrections based on your application's requirements, please provide additional details.


return result
}
}
Copy link
Copy Markdown
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 is syntactically correct without any major issues. However, there are a couple of areas that could be optimized or improved:

  1. Logging to Console: The commented-out console.log(result) line currently does not affect the flow since it's commented out (+). Uncommenting this line will cause unexpected output during execution.

  2. Return Statement Position: Ensure that the return statement follows directly after defining the variable result. This keeps the logic clean and easy to follow.

Here's the refactored code with minor improvements:

@@ -31,8 +31,7 @@ class LoopStartNode extends AppNode {
       type: this.props.model.type,
       children: this.props.model.properties?.config?.fields || [],
     });
-  // console.log(result)
-
-  return result;
+  return result; // Remove the comment if you need logging later
 }

These changes ensure clarity and readability, while also providing an option for further use.

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.

1 participant