Improve Fix Suggestions UI
- hide fix suggestion when comment is collapsed
- show ML-Suggested Edit when fix suggestion is from ML
- extend suggestionsProvider
- getFixSuggestionTitle for option to have own title for fix
suggestion
- getDocumentationLink for ability to have own documentation link
Release-Notes: skip
Google-Bug-Id: b/326195247
Change-Id: I3cdf2eccc9864f5e1efc463b74a389d6733f4f1f
diff --git a/polygerrit-ui/app/api/suggestions.ts b/polygerrit-ui/app/api/suggestions.ts
index 3bc310c..b4158be 100644
--- a/polygerrit-ui/app/api/suggestions.ts
+++ b/polygerrit-ui/app/api/suggestions.ts
@@ -35,6 +35,21 @@
suggestCode?(commentData: SuggestCodeRequest): Promise<SuggestCodeResponse>;
suggestFix?(commentData: SuggestCodeRequest): Promise<SuggestedFixResponse>;
/**
+ * Gets the title to display on the fix suggestion preview.
+ *
+ * @param fix_suggestions A list of suggested fixes.
+ * @return The title string or empty to use the default title.
+ */
+ getFixSuggestionTitle?(fix_suggestions?: FixSuggestionInfo[]): string;
+ /**
+ * Gets a link to documentation for icon help next to title
+ *
+ * @param fix_suggestions A list of suggested fixes.
+ * @return The documentation URL string or empty to use the default link to
+ * gerrit documentation about fix suggestions.
+ */
+ getDocumentationLink?(fix_suggestions?: FixSuggestionInfo[]): string;
+ /**
* List of supported file extensions. If undefined, all file extensions supported.
*/
supportedFileExtensions?: string[];
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 1640b7a..9ac1879 100644
--- a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
+++ b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
@@ -1010,7 +1010,12 @@
}
private renderFixSuggestionPreview() {
- if (!this.comment?.fix_suggestions || this.editing || isRobot(this.comment))
+ if (
+ !this.comment?.fix_suggestions ||
+ this.editing ||
+ isRobot(this.comment) ||
+ this.collapsed
+ )
return nothing;
return html`<gr-fix-suggestions
.comment=${this.comment}
@@ -1104,7 +1109,9 @@
);
}}
/>
- Generate Suggestion
+ ${this.flagsService.isEnabled(KnownExperimentId.ML_SUGGESTED_EDIT_V2)
+ ? 'Attach ML-suggested edit'
+ : 'Generate Suggestion'}
${when(
this.suggestionLoading,
() => html`<span class="loadingSpin"></span>`,
@@ -1112,9 +1119,10 @@
)}
</label>
<a
- href=${getDocUrl(
+ href=${this.suggestionsProvider?.getDocumentationLink?.() ||
+ getDocUrl(
this.docsBaseUrl,
- 'user-suggest-edits.html#_generate_suggestion'
+ 'user-suggest-edits.html$_generate_suggestion'
)}
target="_blank"
rel="noopener noreferrer"
diff --git a/polygerrit-ui/app/elements/shared/gr-fix-suggestions/gr-fix-suggestions.ts b/polygerrit-ui/app/elements/shared/gr-fix-suggestions/gr-fix-suggestions.ts
index 02d64ff..4d5889f 100644
--- a/polygerrit-ui/app/elements/shared/gr-fix-suggestions/gr-fix-suggestions.ts
+++ b/polygerrit-ui/app/elements/shared/gr-fix-suggestions/gr-fix-suggestions.ts
@@ -18,6 +18,8 @@
import {changeModelToken} from '../../../models/change/change-model';
import {Comment, isDraft, PatchSetNumber} from '../../../types/common';
import {OpenFixPreviewEventDetail} from '../../../types/events';
+import {pluginLoaderToken} from '../gr-js-api-interface/gr-plugin-loader';
+import {SuggestionsProvider} from '../../../api/suggestions';
/**
* gr-fix-suggestions is UI for comment.fix_suggestions.
@@ -38,10 +40,15 @@
@state() latestPatchNum?: PatchSetNumber;
+ @state()
+ suggestionsProvider?: SuggestionsProvider;
+
private readonly getConfigModel = resolve(this, configModelToken);
private readonly getChangeModel = resolve(this, changeModelToken);
+ private readonly getPluginLoader = resolve(this, pluginLoaderToken);
+
constructor() {
super();
subscribe(
@@ -56,6 +63,18 @@
);
}
+ override connectedCallback() {
+ super.connectedCallback();
+ this.getPluginLoader()
+ .awaitPluginsLoaded()
+ .then(() => {
+ const suggestionsPlugins =
+ this.getPluginLoader().pluginsModel.getState().suggestionsPlugins;
+ // We currently support results from only 1 provider.
+ this.suggestionsProvider = suggestionsPlugins?.[0]?.provider;
+ });
+ }
+
static override get styles() {
return [
css`
@@ -79,11 +98,19 @@
}
override render() {
+ if (!this.comment?.fix_suggestions) return;
+ const fix_suggestions = this.comment.fix_suggestions;
return html`<div class="header">
<div class="title">
- <span>Suggested edit</span>
+ <span
+ >${this.suggestionsProvider?.getFixSuggestionTitle?.(
+ fix_suggestions
+ ) || 'Suggested edit'}</span
+ >
<a
- href=${getDocUrl(this.docsBaseUrl, 'user-suggest-edits.html')}
+ href=${this.suggestionsProvider?.getDocumentationLink?.(
+ fix_suggestions
+ ) || getDocUrl(this.docsBaseUrl, 'user-suggest-edits.html')}
target="_blank"
rel="noopener noreferrer"
><gr-icon icon="help" title="read documentation"></gr-icon