Remove ML Suggested Edit v1

This was still under feature flag. We now have v2 and v1 is obsolete.


Google-Bug-Id: b/322411847
Release-Notes: skip
Change-Id: Ie5ae678ae8747f36ebb947eedcc4e7f5abb54a11
diff --git a/polygerrit-ui/app/elements/settings/gr-preferences/gr-preferences.ts b/polygerrit-ui/app/elements/settings/gr-preferences/gr-preferences.ts
index 11c8e03..c97a036 100644
--- a/polygerrit-ui/app/elements/settings/gr-preferences/gr-preferences.ts
+++ b/polygerrit-ui/app/elements/settings/gr-preferences/gr-preferences.ts
@@ -124,10 +124,7 @@
       () => this.getConfigModel().docsBaseUrl$,
       docsBaseUrl => (this.docsBaseUrl = docsBaseUrl)
     );
-    if (
-      this.flagsService.isEnabled(KnownExperimentId.ML_SUGGESTED_EDIT) ||
-      this.flagsService.isEnabled(KnownExperimentId.ML_SUGGESTED_EDIT_V2)
-    ) {
+    if (this.flagsService.isEnabled(KnownExperimentId.ML_SUGGESTED_EDIT_V2)) {
       subscribe(
         this,
         () => this.getPluginLoader().pluginsModel.suggestionsPlugins$,
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 9313739..d238881 100644
--- a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
+++ b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
@@ -82,7 +82,6 @@
 import {Interaction, Timing} from '../../../constants/reporting';
 import {
   AutocompleteCommentResponse,
-  Suggestion,
   SuggestionsProvider,
 } from '../../../api/suggestions';
 import {when} from 'lit/directives/when.js';
@@ -251,9 +250,6 @@
   generateSuggestion = true;
 
   @state()
-  generatedSuggestion?: Suggestion;
-
-  @state()
   generatedFixSuggestion: FixSuggestionInfo | undefined =
     this.comment?.fix_suggestions?.[0];
 
@@ -379,9 +375,6 @@
     this.addEventListener('open-user-suggest-preview', e => {
       this.handleShowFix(e.detail.code);
     });
-    this.addEventListener('add-generated-suggestion', e => {
-      this.handleAddGeneratedSuggestion(e.detail.code);
-    });
     this.messagePlaceholder = 'Mention others with @';
     subscribe(
       this,
@@ -439,10 +432,7 @@
         this.autocompleteComment();
       }
     );
-    if (
-      this.flagsService.isEnabled(KnownExperimentId.ML_SUGGESTED_EDIT) ||
-      this.flagsService.isEnabled(KnownExperimentId.ML_SUGGESTED_EDIT_V2)
-    ) {
+    if (this.flagsService.isEnabled(KnownExperimentId.ML_SUGGESTED_EDIT_V2)) {
       subscribe(
         this,
         () =>
@@ -1156,8 +1146,7 @@
   // private but used in test
   showGeneratedSuggestion() {
     return (
-      (this.flagsService.isEnabled(KnownExperimentId.ML_SUGGESTED_EDIT) ||
-        this.flagsService.isEnabled(KnownExperimentId.ML_SUGGESTED_EDIT_V2)) &&
+      this.flagsService.isEnabled(KnownExperimentId.ML_SUGGESTED_EDIT_V2) &&
       this.suggestionsProvider &&
       this.editing &&
       !this.permanentEditingMode &&
@@ -1190,12 +1179,6 @@
         id="suggestionDiffPreview"
         .fixSuggestionInfo=${this.generatedFixSuggestion}
       ></gr-suggestion-diff-preview>`;
-    } else if (this.generatedSuggestion) {
-      return html`<gr-suggestion-diff-preview
-        .showAddSuggestionButton=${true}
-        .suggestion=${this.generatedSuggestion?.replacement}
-        .uuid=${this.generatedSuggestionId}
-      ></gr-suggestion-diff-preview>`;
     } else {
       return nothing;
     }
@@ -1272,85 +1255,19 @@
     if (!this.generateSuggestion) {
       return '';
     }
-    if (this.generatedSuggestion || this.generatedFixSuggestion) {
+    if (this.generatedFixSuggestion) {
       return '(1)';
     } else {
       return '(0)';
     }
   }
 
-  private handleAddGeneratedSuggestion(code: string) {
-    const addNewLine = this.messageText.length !== 0;
-    this.addedGeneratedSuggestion = `${
-      addNewLine ? '\n' : ''
-    }${USER_SUGGESTION_START_PATTERN}${code}${'\n```'}`;
-    this.messageText += this.addedGeneratedSuggestion;
-  }
-
   private generateSuggestEdit() {
     if (this.flagsService.isEnabled(KnownExperimentId.ML_SUGGESTED_EDIT_V2)) {
       this.generateSuggestEdit_v2();
-    } else if (
-      this.flagsService.isEnabled(KnownExperimentId.ML_SUGGESTED_EDIT)
-    ) {
-      this.generateSuggestEdit_v1();
     }
   }
 
-  private async generateSuggestEdit_v1() {
-    const suggestionsProvider = this.suggestionsProvider;
-    const changeInfo = this.getChangeModel().getChange();
-    if (
-      !suggestionsProvider?.suggestCode ||
-      !this.showGeneratedSuggestion() ||
-      !this.generateSuggestion ||
-      !changeInfo ||
-      !this.comment ||
-      !this.comment.patch_set ||
-      !this.comment.path ||
-      this.messageText.length === 0
-    )
-      return;
-    this.generatedSuggestionId = uuid();
-    this.reporting.reportInteraction(Interaction.GENERATE_SUGGESTION_REQUEST, {
-      uuid: this.generatedSuggestionId,
-      type: 'suggest-code',
-      commentId: this.comment.id,
-      fileExtension: getFileExtension(this.comment.path ?? ''),
-    });
-    this.suggestionLoading = true;
-    let suggestionResponse;
-    try {
-      suggestionResponse = await suggestionsProvider.suggestCode({
-        prompt: this.messageText,
-        changeInfo: changeInfo as ChangeInfo,
-        patchsetNumber: this.comment?.patch_set,
-        filePath: this.comment.path,
-        range: this.comment.range,
-        lineNumber: this.comment.line,
-      });
-    } finally {
-      this.suggestionLoading = false;
-    }
-
-    if (!suggestionResponse) return;
-    // TODO(milutin): The suggestionResponse can contain multiple suggestion
-    // options. We pick the first one for now. In future we shouldn't ignore
-    // other suggestions.
-    this.reporting.reportInteraction(Interaction.GENERATE_SUGGESTION_RESPONSE, {
-      uuid: this.generatedSuggestionId,
-      type: 'suggest-code',
-      commentId: this.comment.id,
-      response: suggestionResponse.responseCode,
-      numSuggestions: suggestionResponse.suggestions.length,
-      hasNewRange: suggestionResponse.suggestions?.[0]?.newRange !== undefined,
-      fileExtension: getFileExtension(this.comment.path ?? ''),
-    });
-    const suggestion = suggestionResponse.suggestions?.[0];
-    if (!suggestion?.replacement) return;
-    this.generatedSuggestion = suggestion;
-  }
-
   private async generateSuggestEdit_v2() {
     const suggestionsProvider = this.suggestionsProvider;
     const changeInfo = this.getChangeModel().getChange();
@@ -1405,6 +1322,7 @@
       return;
     }
     this.generatedFixSuggestion = suggestion;
+
     try {
       await waitUntil(() => this.getFixSuggestions() !== undefined);
       this.autoSaveTrigger$.next();
@@ -1584,16 +1502,8 @@
         whenVisible(this, () => this.textarea?.putCursorAtEnd());
       }
     }
-    if (
-      changed.has('changeNum') ||
-      changed.has('comment') ||
-      changed.has('generatedSuggestion')
-    ) {
-      if (
-        !this.changeNum ||
-        !this.comment ||
-        (!hasUserSuggestion(this.comment) && !this.generatedSuggestion)
-      )
+    if (changed.has('changeNum') || changed.has('comment')) {
+      if (!this.changeNum || !this.comment || !hasUserSuggestion(this.comment))
         return;
       (async () => {
         this.commentedText = await this.commentModel.getCommentedCode(
@@ -1887,7 +1797,6 @@
     } 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;
       }
@@ -1983,23 +1892,6 @@
     );
     this.closeDeleteCommentModal();
   }
-
-  private trackGeneratedSuggestionEdit() {
-    const hasUserSuggestion = this.messageText.includes(
-      USER_SUGGESTION_START_PATTERN
-    );
-    const wasGeneratedSuggestionEdited =
-      this.addedGeneratedSuggestion &&
-      hasUserSuggestion &&
-      !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 {
diff --git a/polygerrit-ui/app/elements/shared/gr-suggestion-diff-preview/gr-suggestion-diff-preview.ts b/polygerrit-ui/app/elements/shared/gr-suggestion-diff-preview/gr-suggestion-diff-preview.ts
index 48328ea..9b54db3 100644
--- a/polygerrit-ui/app/elements/shared/gr-suggestion-diff-preview/gr-suggestion-diff-preview.ts
+++ b/polygerrit-ui/app/elements/shared/gr-suggestion-diff-preview/gr-suggestion-diff-preview.ts
@@ -28,22 +28,10 @@
 import {commentModelToken} from '../gr-comment-model/gr-comment-model';
 import {navigationToken} from '../../core/gr-navigation/gr-navigation';
 import {fire} from '../../../utils/event-util';
-import {Interaction, Timing} from '../../../constants/reporting';
+import {Timing} from '../../../constants/reporting';
 import {createChangeUrl} from '../../../models/views/change';
 import {getFileExtension} from '../../../utils/file-util';
 
-declare global {
-  interface HTMLElementEventMap {
-    'add-generated-suggestion': AddGeneratedSuggestionEvent;
-  }
-}
-
-export type AddGeneratedSuggestionEvent =
-  CustomEvent<OpenUserSuggestionPreviewEventDetail>;
-export interface OpenUserSuggestionPreviewEventDetail {
-  code: string;
-}
-
 /**
  * Diff preview for
  * 1. code block suggestion vs commented Text
@@ -60,9 +48,6 @@
   @property({type: Object})
   fixSuggestionInfo?: FixSuggestionInfo;
 
-  @property({type: Boolean})
-  showAddSuggestionButton = false;
-
   @property({type: Boolean, attribute: 'previewed', reflect: true})
   previewed = false;
 
@@ -206,19 +191,6 @@
         () => this.renderDiff(),
         () => html`<code>${code}</code>`
       )}
-      ${when(
-        this.showAddSuggestionButton,
-        () =>
-          html`<div class="buttons">
-            <gr-button
-              link
-              class="action add-suggestion"
-              @click=${this.handleAddGeneratedSuggestion}
-            >
-              Add suggestion to comment
-            </gr-button>
-          </div>`
-      )}
     `;
   }
 
@@ -270,6 +242,7 @@
     if (currentPreviews.length > 0) {
       this.preview = currentPreviews[0];
       this.previewLoadedFor = this.suggestion;
+      this.previewed = true;
     }
 
     return res;
@@ -303,7 +276,6 @@
     if (currentPreviews.length > 0) {
       this.preview = currentPreviews[0];
       this.previewLoadedFor = this.fixSuggestionInfo;
-      this.previewed = true;
     }
 
     return res;
@@ -382,15 +354,6 @@
       line_wrapping: true,
     };
   }
-
-  handleAddGeneratedSuggestion() {
-    if (!this.suggestion) return;
-    this.reporting.reportInteraction(Interaction.GENERATE_SUGGESTION_ADDED, {
-      uuid: this.uuid,
-      commentId: this.comment?.id ?? '',
-    });
-    fire(this, 'add-generated-suggestion', {code: this.suggestion});
-  }
 }
 
 declare global {
diff --git a/polygerrit-ui/app/services/flags/flags.ts b/polygerrit-ui/app/services/flags/flags.ts
index 9431cf8..0bf3c97 100644
--- a/polygerrit-ui/app/services/flags/flags.ts
+++ b/polygerrit-ui/app/services/flags/flags.ts
@@ -19,7 +19,6 @@
   CHECKS_DEVELOPER = 'UiFeature__checks_developer',
   PUSH_NOTIFICATIONS_DEVELOPER = 'UiFeature__push_notifications_developer',
   PUSH_NOTIFICATIONS = 'UiFeature__push_notifications',
-  ML_SUGGESTED_EDIT = 'UiFeature__ml_suggested_edit',
   ML_SUGGESTED_EDIT_V2 = 'UiFeature__ml_suggested_edit_v2',
   REVISION_PARENTS_DATA = 'UiFeature__revision_parents_data',
   COMMENT_AUTOCOMPLETION = 'UiFeature__comment_autocompletion_enabled',