Preserve fix suggestion when editing draft comment Ensures that any attached AI-suggested fix on a draft comment is not lost when the user enters edit mode. This correctly repopulates the internal suggestion properties and checkboxes, allowing the snippet to be preserved and edited alongside the comment text instead of being cleared. Google-Bug-Id: b/469071313 Release-Notes: skip Change-Id: I39ff2e4efba7d69422640393010737107a815efb
diff --git a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts index 2881ac5..c2768ba 100644 --- a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts +++ b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
@@ -1476,6 +1476,11 @@ this.originalMessage = this.messageText; this.originalUnresolved = this.unresolved; } + if (this.comment?.fix_suggestions?.[0]) { + this.generatedFixSuggestion = this.comment.fix_suggestions[0]; + this.previewedGeneratedFixSuggestion = this.comment.fix_suggestions[0]; + this.generateSuggestion = true; + } } // Parent components such as the reply dialog might be interested in whether
diff --git a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment_test.ts b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment_test.ts index bf3a54d..41429b1 100644 --- a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment_test.ts +++ b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment_test.ts
@@ -1087,6 +1087,41 @@ ); }); + test('editing draft comment preserves fix suggestion', async () => { + const comment: DraftInfo = { + ...createDraft(), + author: { + name: 'Mr. Peanutbutter', + email: 'tenn1sballchaser@aol.com' as EmailAddress, + }, + line: 5, + path: 'test', + savingState: SavingState.OK, + message: 'hello world', + fix_suggestions: [generatedFixSuggestion], + }; + element = await fixture( + html`<gr-comment + .account=${account} + .showPatchset=${true} + .comment=${comment} + .initiallyCollapsed=${false} + ></gr-comment>` + ); + assert.isFalse(element.editing); + + element.edit(); + await element.updateComplete; + + assert.isTrue(element.editing); + assert.deepEqual(element.generatedFixSuggestion, generatedFixSuggestion); + assert.deepEqual( + element.previewedGeneratedFixSuggestion, + generatedFixSuggestion + ); + assert.isTrue(element.generateSuggestion); + }); + suite('save', () => { const savePromise = mockPromise<DraftInfo>(); let saveDraftStub: SinonStub;