fix(databases): clone enum elements to prevent mutation on cancel#3129
Open
okxint wants to merge 1 commit into
Open
fix(databases): clone enum elements to prevent mutation on cancel#3129okxint wants to merge 1 commit into
okxint wants to merge 1 commit into
Conversation
Editing enum column elements in the edit dialog mutated the source object in place because the form bound directly to selectedColumn. Introduce editingColumn as a deep-cloned local copy on dialog open so cancelled edits are discarded without touching the original data.
Contributor
Greptile SummaryThis PR isolates database column edits from the selected source column. The main changes are:
Confidence Score: 5/5This looks safe to merge after a small stale-state cleanup.
src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/edit.svelte Important Files Changed
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/edit.svelte:120-122
**Open Sheet Keeps Stale Column**
When the edit sheet is already open and `selectedColumn` changes without a `showEdit` false transition, this path does not refresh the cloned edit state or the original key. The next update can submit the previous column clone while the UI state points at a different selected column, which can update or rename the wrong column.
Reviews (1): Last reviewed commit: "fix(databases): clone enum elements arra..." | Re-trigger Greptile |
Comment on lines
120
to
+122
| if (show) { | ||
| currentColumn ??= { ...selectedColumn }; | ||
| editingColumn = deepCloneColumn(selectedColumn); | ||
| currentColumn ??= deepCloneColumn(selectedColumn); |
Contributor
There was a problem hiding this comment.
When the edit sheet is already open and selectedColumn changes without a showEdit false transition, this path does not refresh the cloned edit state or the original key. The next update can submit the previous column clone while the UI state points at a different selected column, which can update or rename the wrong column.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/edit.svelte
Line: 120-122
Comment:
**Open Sheet Keeps Stale Column**
When the edit sheet is already open and `selectedColumn` changes without a `showEdit` false transition, this path does not refresh the cloned edit state or the original key. The next update can submit the previous column clone while the UI state points at a different selected column, which can update or rename the wrong column.
How can I resolve this? If you propose a fix, please make it concise.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2245
Problem
The attribute edit dialog used a shallow spread (
{ ...selectedColumn }) to initialize a local copy, but theelementsarray inside was still shared by reference. Editing enum values in the dialog mutated the original source object immediately, so clicking Cancel had no effect — the changes were already written to the parent's data.Fix
Introduce a
deepCloneColumn()helper that spreads the column and copieselementswith[...col.elements]. On dialog open, botheditingColumnandcurrentColumnare deep-cloned fromselectedColumn. All form inputs and child components bind toeditingColumn— the originalselectedColumnis never touched untilsubmit()sends the cloned data to the API. On cancel/close,editingColumnis set tonull, discarding all edits.