Track generated suggestion edit

For better understanding of usage of editing generated suggestions.

Release-Notes: skip
Google-Bug-Id: b/303611208
Change-Id: I48313de167d4f5f580f5b9f81259e284ebc3d6dd
diff --git a/polygerrit-ui/app/constants/reporting.ts b/polygerrit-ui/app/constants/reporting.ts
index dded0c6..37a17ba 100644
--- a/polygerrit-ui/app/constants/reporting.ts
+++ b/polygerrit-ui/app/constants/reporting.ts
@@ -146,6 +146,7 @@
   GENERATE_SUGGESTION_ENABLED = 'generate_suggestion_enabled',
   // User disabled generating suggestions
   GENERATE_SUGGESTION_DISABLED = 'generate_suggestion_disabled',
+  GENERATE_SUGGESTION_EDITED = 'generate_suggestion_edited',
   START_REVIEW = 'start-review',
   CODE_REVIEW_APPROVAL = 'code-review-approval',
   FILE_LIST_DIFF_COLLAPSED = 'file-list-diff-collapsed',
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 16a783c..48d7b1b 100644
--- a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
+++ b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
@@ -232,6 +232,9 @@
   generatedSuggestionId?: string;
 
   @state()
+  addedGeneratedSuggestion?: string;
+
+  @state()
   suggestionsProvider?: SuggestionsProvider;
 
   @state()
@@ -1149,9 +1152,10 @@
 
   private handleAddGeneratedSuggestion(code: string) {
     const addNewLine = this.messageText.length !== 0;
-    this.messageText += `${
+    this.addedGeneratedSuggestion = `${
       addNewLine ? '\n' : ''
     }${USER_SUGGESTION_START_PATTERN}${code}${'\n```'}`;
+    this.messageText += this.addedGeneratedSuggestion;
   }
 
   private generateSuggestEdit() {
@@ -1665,6 +1669,7 @@
     } else {
       // No need to make a backend call when nothing has changed.
       while (this.somethingToSave()) {
+        this.trackGeneratedSuggestionEdit();
         this.comment = await this.rawSave({showToast: true});
         if (isError(this.comment)) return;
       }
@@ -1746,6 +1751,19 @@
     );
     this.closeDeleteCommentModal();
   }
+
+  private trackGeneratedSuggestionEdit() {
+    const wasGeneratedSuggestionEdited =
+      this.addedGeneratedSuggestion &&
+      !this.messageText.includes(this.addedGeneratedSuggestion);
+    if (wasGeneratedSuggestionEdited) {
+      this.reporting.reportInteraction(Interaction.GENERATE_SUGGESTION_EDITED, {
+        uuid: this.generatedSuggestionId,
+        commentId: this.comment?.id ?? '',
+      });
+      this.addedGeneratedSuggestion = undefined;
+    }
+  }
 }
 
 declare global {