Skip to content

fix: On both workflow pages and standard tool editing pages: if you open the parameter editing window and then close it immediately without saving, any new parameters added subsequently will overwrite the parameters from the cancelled edit session. - #7886

Merged
shaohuzhang1 merged 1 commit into
v2from
pr@v2@fix_application_workflow
Nov 13, 2026

Conversation

@shaohuzhang1

Copy link
Copy Markdown
Contributor

fix: On both workflow pages and standard tool editing pages: if you open the parameter editing window and then close it immediately without saving, any new parameters added subsequently will overwrite the parameters from the cancelled edit session.

…pen the parameter editing window and then close it immediately without saving, any new parameters added subsequently will overwrite the parameters from the cancelled edit session.
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.

@shaohuzhang1
shaohuzhang1 merged commit f87edb2 into v2 Nov 13, 2026
4 of 5 checks passed
@shaohuzhang1
shaohuzhang1 deleted the pr@v2@fix_application_workflow branch November 13, 2026 03:31
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant