Fix show edit for fix suggestions attached to comment
We have 2 APIs to preview and apply suggestions. One is /fixes/fixId
and another one is POST /fix:apply without use of fixId.
Gr-apply-fix-dialog uses latter when fixId is PROVIDED_FIX_ID
otherwise it uses former one.
Fix suggestions usually get NOOP fix_id from plugin or backend,
since we cannot use /fixes/fixId for our fix_id, we need to rewrite
fix_id to PROVIDED_FIX_ID to use POST /fix:apply
Another fix in this change improves description where we use same
description as title of <gr-fix-suggestion> component.
Release-Notes: skip
Google-Bug-Id: b/332726695
Change-Id: Ib5e98ff9dab069d3b47746c443aed1381906fabf
diff --git a/polygerrit-ui/app/elements/diff/gr-apply-fix-dialog/gr-apply-fix-dialog.ts b/polygerrit-ui/app/elements/diff/gr-apply-fix-dialog/gr-apply-fix-dialog.ts
index 3b679fd..0a31677 100644
--- a/polygerrit-ui/app/elements/diff/gr-apply-fix-dialog/gr-apply-fix-dialog.ts
+++ b/polygerrit-ui/app/elements/diff/gr-apply-fix-dialog/gr-apply-fix-dialog.ts
@@ -315,6 +315,8 @@
fixSuggestion.replacements
);
} else {
+ // TODO(b/227463363) Remove once Robot Comments are deprecated.
+ // We don't use this for user suggestions or comments.fix_suggestions.
res = await this.restApiService.getRobotCommentFixPreview(
this.changeNum,
this.patchNum,
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 4d5889f..9e78e2a 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
@@ -20,6 +20,7 @@
import {OpenFixPreviewEventDetail} from '../../../types/events';
import {pluginLoaderToken} from '../gr-js-api-interface/gr-plugin-loader';
import {SuggestionsProvider} from '../../../api/suggestions';
+import {PROVIDED_FIX_ID} from '../../../utils/comment-util';
/**
* gr-fix-suggestions is UI for comment.fix_suggestions.
@@ -149,7 +150,11 @@
fixSuggestions: this.comment.fix_suggestions.map(s => {
return {
...s,
- description: 'Suggested Edit from comment',
+ fix_id: PROVIDED_FIX_ID,
+ description:
+ this.suggestionsProvider?.getFixSuggestionTitle?.(
+ this.comment?.fix_suggestions
+ ) || 'Suggested edit',
};
}),
patchNum: this.comment.patch_set,