-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: When the loop node is closed, the loop body is not displayed #4091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,9 +71,9 @@ | |
| </NodeContainer> | ||
| </template> | ||
| <script setup lang="ts"> | ||
| import { set } from 'lodash' | ||
| import { set, throttle } from 'lodash' | ||
| import NodeContainer from '@/workflow/common/NodeContainer.vue' | ||
| import { ref, computed, onMounted } from 'vue' | ||
| import { ref, computed, onMounted, watch } from 'vue' | ||
| import { isLastNode } from '@/workflow/common/data' | ||
| import { loopBodyNode, loopStartNode } from '@/workflow/common/data' | ||
| import NodeCascader from '@/workflow/common/NodeCascader.vue' | ||
|
|
@@ -98,7 +98,20 @@ const form_data = computed({ | |
| set(props.nodeModel.properties, 'node_data', value) | ||
| }, | ||
| }) | ||
|
|
||
| const showNode = computed(() => { | ||
| if (props.nodeModel.properties.showNode !== undefined) { | ||
| return props.nodeModel.properties.showNode | ||
| } | ||
| set(props.nodeModel.properties, 'showNode', true) | ||
| return true | ||
| }) | ||
| watch(showNode, () => { | ||
| if (showNode.value) { | ||
| throttle(mountLoopBodyNode, 1000)() | ||
| } else { | ||
| throttle(destroyLoopBodyNode, 1000)() | ||
| } | ||
| }) | ||
| const replyNodeFormRef = ref() | ||
| const nodeCascaderRef = ref() | ||
| const validate = () => { | ||
|
|
@@ -109,14 +122,15 @@ const validate = () => { | |
| return Promise.reject({ node: props.nodeModel, errMessage: err }) | ||
| }) | ||
| } | ||
|
|
||
| onMounted(() => { | ||
| if (typeof props.nodeModel.properties.node_data?.is_result === 'undefined') { | ||
| if (isLastNode(props.nodeModel)) { | ||
| set(props.nodeModel.properties.node_data, 'is_result', true) | ||
| } | ||
| const destroyLoopBodyNode = () => { | ||
| const nodeOutgoingNode = props.nodeModel.graphModel.getNodeOutgoingNode(props.nodeModel.id) | ||
| const loopBody = nodeOutgoingNode.find((item: any) => item.type == loopBodyNode.type) | ||
| if (loopBody) { | ||
| loopBody.set_loop_body() | ||
| props.nodeModel.graphModel.deleteNode(loopBody.id) | ||
| } | ||
| set(props.nodeModel, 'validate', validate) | ||
| } | ||
| const mountLoopBodyNode = () => { | ||
| const nodeOutgoingNode = props.nodeModel.graphModel.getNodeOutgoingNode(props.nodeModel.id) | ||
| if (!nodeOutgoingNode.some((item: any) => item.type == loopBodyNode.type)) { | ||
| let workflow = { nodes: [loopStartNode], edges: [] } | ||
|
|
@@ -127,7 +141,7 @@ onMounted(() => { | |
| } | ||
| if (props.nodeModel.properties.node_data.loop) { | ||
| x = props.nodeModel.properties.node_data.loop.x | ||
| y = props.nodeModel.properties.node_data.loop.y | ||
| y = props.nodeModel.properties.node_data.loop.y - 330 | ||
| } | ||
| const nodeModel = props.nodeModel.graphModel.addNode({ | ||
| type: loopBodyNode.type, | ||
|
|
@@ -147,6 +161,16 @@ onMounted(() => { | |
| virtual: true, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| onMounted(() => { | ||
| if (typeof props.nodeModel.properties.node_data?.is_result === 'undefined') { | ||
| if (isLastNode(props.nodeModel)) { | ||
| set(props.nodeModel.properties.node_data, 'is_result', true) | ||
| } | ||
| } | ||
| set(props.nodeModel, 'validate', validate) | ||
| mountLoopBodyNode() | ||
| }) | ||
| </script> | ||
| <style lang="scss" scoped></style> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 <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:
These changes improve readability and performance, while maintaining core functionalities. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,7 @@ class LoopStartNode extends AppNode { | |
| type: this.props.model.type, | ||
| children: this.props.model.properties?.config?.fields || [], | ||
| }) | ||
| console.log(result) | ||
|
|
||
| return result | ||
| } | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
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. |
||
|
|
||
There was a problem hiding this comment.
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:
The
set_loop_bodyfunction is called twice with the same data (lf.value.getGraphData()). This might not be intended, as it could result in overriding previously set properties.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.If the intention is to update
loop_node.properties.node_data.loop_bodymultiple times but with different values depending on thefields, consider using a variable instead of repeating the same line of code.Ensure that
lf.value.getGraphData()returns expected and consistent data since errors here can cause unexpected behavior.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.