Repository navigation
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
Conversation
…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) | ||
| } | ||
|
|
There was a problem hiding this comment.
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
currentIndexremaining unchanged during certain interactions? - If
openAddDialogis intended only for creating new items or editing specific items in isolation, this change is fine. However, ifcurrentIndextracks state for other purposes, forcing it tonullmight 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.valueacceptsnull. - No other parts of the code depend on
currentIndexbeing preserved whenindexis undefined.
| currentIndex.value = typeof index !== 'undefined' ? index : null | ||
|
|
||
| FieldFormDialogRef.value.open(data) | ||
| } |
There was a problem hiding this comment.
Here is the review of the provided code snippet:
- Code Style/Readability: The new code uses a ternary operator, which is more concise but slightly less readable than the original
ifblock for this specific logic. The original was clearer in intent ("only update if index exists"). However, the new version explicitly setscurrentIndex.valuetonullwhenindexis undefined, which is often safer than leaving it unchanged (preventing stale data if the dialog is reopened without an index). - Type Safety:
currentIndex.valueis set tonull. Ensure thatcurrentIndexis typed to acceptnull(e.g.,Ref<number | null>). If it's typed asnumber, this will cause a TypeScript error. - Logic Clarity: If the intent is to clear the current selection when opening a "new/add" dialog (where
indexis not passed), setting it tonullis correct. If the intent was to preserve the previousindexwhen adding a new item, the originalifblock was buggy because it didn't updatecurrentIndexbut the caller might expect it to be reset. The new behavior impliesopenAddDialog(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.
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.