-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat: Node execution conditions #1888
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 |
|---|---|---|
|
|
@@ -44,8 +44,8 @@ | |
| placement="bottom-start" | ||
| > | ||
| <el-button text> | ||
| <img src="@/assets/icon_or.svg" alt="" v-if="condition==='OR'"> | ||
| <img src="@/assets/icon_and.svg" alt="" v-if="condition==='AND'"> | ||
| <img src="@/assets/icon_or.svg" alt="" v-if="condition === 'OR'" /> | ||
| <img src="@/assets/icon_and.svg" alt="" v-if="condition === 'AND'" /> | ||
| </el-button> | ||
| <template #dropdown> | ||
| <div style="width: 280px" class="p-12-16"> | ||
|
|
@@ -152,8 +152,19 @@ const height = ref<{ | |
| }) | ||
| const showAnchor = ref<boolean>(false) | ||
| const anchorData = ref<any>() | ||
| const condition = ref('AND') | ||
|
|
||
| const condition = computed({ | ||
| set: (v) => { | ||
| set(props.nodeModel.properties, 'condition', v) | ||
| }, | ||
| get: () => { | ||
| if (props.nodeModel.properties.condition) { | ||
| return props.nodeModel.properties.condition | ||
| } | ||
| set(props.nodeModel.properties, 'condition', 'AND') | ||
| return true | ||
| } | ||
| }) | ||
| const showNode = computed({ | ||
| set: (v) => { | ||
| set(props.nodeModel.properties, 'showNode', v) | ||
|
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 you provided has some improvements and optimizations that can be made: Improvements:
Optimize Conditional Rendering:Instead of using conditional rendering inside the template directly (using Here's an updated version of your code incorporating these suggestions): <template>
<!-- Rest of the template remains unchanged -->
<script lang="ts">
import { defineComponent } from 'vue'
// Import other necessary components here
export default defineComponent({
setup(props) {
const set = (...args: any[]) => console.log(args) // Placeholder function
const height = ref<{ top?: number; bottom?: number }>({
// initialization
})
const showAnchor = ref(false)
const anchorData = ref({})
const condition = computed(() => {
return props.nodeModel.properties?.condition || 'AND'
})
const showNode = computed(() => {
return props.nodeModel.properties.showNode ?? true
})
// Other methods and computed properties...
}
})
</script>
<!-- Reset CSS and styling -->
<style scoped src="./YourStylesheet.css"></style>This revised approach maintains simplicity while improving robustness for future modifications. |
||
|
|
||
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.
This code snippet appears to implement a method that determines which nodes should be processed next based on certain conditions. Here are some potential problems and optimizations:
Potential Issues:
List Comprehension in Loop:
next_node = [node for node in self.flow.nodes if node.id == edge.targetNodeId]iterates over all nodes once per iteration of the main loop. This is unnecessary when you only need one target node from each connection.Multiple Returns:
targetNodeId, this code will append them all, but it won't stop after the first match. Consider adding a flag to break out of the function once a match is found to optimize performance for cases where duplicates exist.Condition Handling:
if next_node[0].properties.get('condition', "AND")). However, ifconditiondoesn't exist, it will use"AND"as default, assuming every condition has been met. Make sure this default behavior aligns with your needs.Code Reusability:
get_next_node_listcould benefit from reusing logic in helper functions like checking dependencies and getting node classes by ID.Suggestions:
Simplify Condition Check:
Use Helper Function for Node Retrieval:
Create a helper function
_get_target_nodesthat fetches and returns target nodes directly without iterating multiple times per edge.Add Debugging Information:
Insert print statements or logging to trace execution flow and identify bottlenecks more easily.
Overall, improving efficiency and ensuring robust conditional handling would make the code cleaner and potentially faster under certain scenarios.