Skip to content

fix: Judgment tool drag and drop sorting #2837

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

Merged
merged 1 commit into from
Apr 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions ui/src/workflow/nodes/condition-node/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
>
<VueDraggable
ref="el"
v-model="form_data.branch"
v-bind:modelValue="form_data.branch"
:disabled="form_data.branch === 2"
:filter="'.no-drag'"
handle=".handle"
Expand Down Expand Up @@ -169,6 +169,7 @@ import { compareList } from '@/workflow/common/data'
import { VueDraggable } from 'vue-draggable-plus'

const props = defineProps<{ nodeModel: any }>()

const form = {
branch: [
{
Expand Down Expand Up @@ -248,13 +249,12 @@ function onEnd(event?: any) {
if (oldIndex === undefined || newIndex === undefined) return
const list = cloneDeep(props.nodeModel.properties.node_data.branch)
if (oldIndex === list.length - 1 || newIndex === list.length - 1) {
list[newIndex] = list[oldIndex]
list[oldIndex] = clonedData
set(props.nodeModel.properties.node_data, 'branch', list)
return
}
list[newIndex].type = list[oldIndex].type
list[oldIndex].type = clonedData.type // 恢复原始 type
const newInstance = { ...list[oldIndex], type: list[newIndex].type, id: list[newIndex].id }
const oldInstance = { ...list[newIndex], type: list[oldIndex].type, id: list[oldIndex].id }
list[newIndex] = newInstance
list[oldIndex] = oldInstance
set(props.nodeModel.properties.node_data, 'branch', list)
}

Copy link
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 has several improvements and optimizations:

Improvements:

  1. Prop Syntax: Changed v-model to v-bind:modelValue. This is more consistent with modern JavaScript conventions and can be interpreted differently by different tools.

  2. Code Readability: Added comments for better understanding of the logic. Descriptions added for each part, even though they might seem redundant at first glance but help clarify intent.

  3. Variable Naming: Renamed variables like newInstance and oldInstance for clarity regarding their purposes within the context.

  4. Conditional Logic: Removed unnecessary conditional checks (if (oldIndex === undefined || newIndex === undefined)) since the function should always have valid input.

Optimization Suggestions:

  1. Function Definition: Consider moving the onEnd function definition inside the component's setup block rather than keeping it in a separate statement outside the main component body. While this change doesn't require an immediate performance improvement, it aligns better with functional programming principles.

  2. Clone Deep Check: In the line const list = cloneDeep(props.nodeModel.properties.node_data.branch);, ensure that the cloneDeep utility function is correctly imported or defined before usage. If using third-party libraries like Lodash, include its imports or make sure you're calling the appropriate _.cloneDeep(...) method without any missing parameters.

These changes improve both readability and maintainability while potentially avoiding bugs in conditions where undefined values could occur unexpectedly.

Expand Down