-
Notifications
You must be signed in to change notification settings - Fork 2.7k
fix: Workflow node search for several errors #4862
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 |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| <!-- 辅助工具栏 --> | ||
| <Control class="workflow-control" v-if="lf" :lf="lf"></Control> | ||
| <TeleportContainer :flow-id="flowId" /> | ||
| <NodeSearch :lf="lf"></NodeSearch> | ||
| <NodeSearch :lf="lf" ref="nodeSearchRef"></NodeSearch> | ||
| </template> | ||
| <script setup lang="ts"> | ||
| import LogicFlow from '@logicflow/core' | ||
|
|
@@ -23,7 +23,7 @@ import NodeSearch from '@/workflow/common/NodeSearch.vue' | |
| const nodes: any = import.meta.glob('./nodes/**/index.ts', { eager: true }) | ||
| const workflow_mode = inject('workflowMode') || WorkflowMode.Application | ||
| const loop_workflow_mode = inject('loopWorkflowMode') || WorkflowMode.ApplicationLoop | ||
|
|
||
| const nodeSearchRef = ref<InstanceType<typeof NodeSearch>>() | ||
| defineOptions({ name: 'WorkFlow' }) | ||
| const TeleportContainer = getTeleport() | ||
| const flowId = ref('') | ||
|
|
@@ -87,6 +87,9 @@ const renderGraphData = (data?: any) => { | |
| lf.value.on('graph:rendered', () => { | ||
| flowId.value = lf.value.graphModel.flowId | ||
| }) | ||
| lf.value.on('node:delete', () => { | ||
| nodeSearchRef.value?.reSearch() | ||
| }) | ||
| initDefaultShortcut(lf.value, lf.value.graphModel) | ||
| lf.value.batchRegister([ | ||
| ...Object.keys(nodes).map((key) => nodes[key].default), | ||
|
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. Here is a brief report on the code and some suggestions: Issues/Failures:
Suggestions:
import { Teleport } from '@vue/runtime-dom';
These changes should help enhance the robustness and performance of your workflow application. |
||
|
|
||
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 is mostly correct, but there are several areas that could be improved or optimized:
Null Checks: The use of
props.lfand method calls likegraphModel.getNodeModelById(...)can potentially throw null errors iflfis not defined or the node model does not exist.Type Checking and Defaults: Ensure that all properties used in
filter,find, etc., have defaults in case they might return undefined unexpectedly.Error Handling : Add try-catch blocks around complex operations to catch and handle runtime errors more gracefully.
Use Safe Navigation Operator (
?.): Always use safe navigation (??) instead of optional chaining (?) when accessing deep nested objects to avoid potential type errors.Here's an updated version with these improvements:
These changes add safety checks and improve best practices for dealing with data flow between components and state management in Vue.js. Additionally, I added a parameter check in
next()forselectedNodes, which avoids calling methods on an empty array causing errors and handles edge cases whereselectedIndexmay go below zero by setting it to zero initially rather than relying solely on conditional expressions.