Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ const ApiFieldFormDialogRef = ref()
const inputFieldList = ref<any[]>([])

function openAddDialog(data?: any, index?: any) {
if (typeof index !== 'undefined') {
currentIndex.value = index
}
currentIndex.value = typeof index !== 'undefined' ? index : null
ApiFieldFormDialogRef.value.open(data)
}

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.

Here is a review of the code snippet:

1. Potential Issue: Implicit State Side-Effect on "Close/Reset"
The original logic only updated currentIndex if index was provided. The new logic sets currentIndex to null even when index is undefined (e.g., opening a "New" item dialog).

  • Check: Does your application rely on currentIndex remaining unchanged during certain interactions?
  • If openAddDialog is intended only for creating new items or editing specific items in isolation, this change is fine. However, if currentIndex tracks state for other purposes, forcing it to null might break functionality that expects the previous index to persist when opening a non-specific dialog.

2. Type Safety Improvement
currentIndex.value = null may cause TypeScript errors if currentIndex is typed as Ref<number> or Ref<string> instead of Ref<number | null>. Ensure the type definition allows null.

3. Optimization/Readability
The change from a ternary/conditional block to a single assignment line improves conciseness and maintainability. It reduces branching logic and makes the intent clearer: "If an index is given, use it; otherwise, clear it."

Suggestion:
If the behavior matches your requirements (i.e., opening without an index should reset the current index context), this change is correct and cleaner. Just verify:

  • The type of currentIndex.value accepts null.
  • No other parts of the code depend on currentIndex being preserved when index is undefined.

Expand Down
4 changes: 1 addition & 3 deletions ui/src/workflow/nodes/tool-node/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ function submitCodemirrorEditor(val: string) {
}

function openAddDialog(data?: any, index?: any) {
if (typeof index !== 'undefined') {
currentIndex.value = index
}
currentIndex.value = typeof index !== 'undefined' ? index : null

FieldFormDialogRef.value.open(data)
}

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.

Here is the review of the provided code snippet:

  1. Code Style/Readability: The new code uses a ternary operator, which is more concise but slightly less readable than the original if block for this specific logic. The original was clearer in intent ("only update if index exists"). However, the new version explicitly sets currentIndex.value to null when index is undefined, which is often safer than leaving it unchanged (preventing stale data if the dialog is reopened without an index).
  2. Type Safety: currentIndex.value is set to null. Ensure that currentIndex is typed to accept null (e.g., Ref<number | null>). If it's typed as number, this will cause a TypeScript error.
  3. Logic Clarity: If the intent is to clear the current selection when opening a "new/add" dialog (where index is not passed), setting it to null is correct. If the intent was to preserve the previous index when adding a new item, the original if block was buggy because it didn't update currentIndex but the caller might expect it to be reset. The new behavior implies openAddDialog(data?) is for "add new" and should clear the edit context.

Optimization/Suggestion:
If currentIndex can be undefined or null, and you want strict boolean checks instead of just checking for undefined, consider using a clearer pattern if performance/readability is critical, but this change is functionally sound assuming null is a valid value.

✅ Verdict: The change is reasonable if currentIndex supports null. Ensure type definitions match.

Expand Down
Loading