Make generate suggestion checkbox persistent comment specific
With suggestions v2, suggestions are rejected by unchecking checkbox.
Therefore saving state of checkbox cannot be universal for all comments
but specific for each comment.
Users still have option to have checkbox disabled by default
in user settings.
We use comment.id in storage key.
Release-Notes: skip
Google-Bug-Id: b/328393134
Change-Id: If6a3d9192b9e8000545ae2261d6b3a9b9f903f44
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 bc9bd12..4504f5e 100644
--- a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
+++ b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
@@ -91,7 +91,7 @@
export const AUTO_SAVE_DEBOUNCE_DELAY_MS = 2000;
export const GENERATE_SUGGESTION_DEBOUNCE_DELAY_MS = 1500;
export const ENABLE_GENERATE_SUGGESTION_STORAGE_KEY =
- 'enableGenerateSuggestionStorageKey';
+ 'enableGenerateSuggestionStorageKeyForCommentWithId-';
declare global {
interface HTMLElementEventMap {
@@ -416,12 +416,14 @@
this.suggestionsProvider = suggestionsPlugins?.[0]?.provider;
});
- const generateSuggestionStoredContent =
- this.getStorage().getEditableContentItem(
- ENABLE_GENERATE_SUGGESTION_STORAGE_KEY
- );
- if (generateSuggestionStoredContent?.message === 'false') {
- this.generateSuggestion = false;
+ if (this.comment?.id) {
+ const generateSuggestionStoredContent =
+ this.getStorage().getEditableContentItem(
+ ENABLE_GENERATE_SUGGESTION_STORAGE_KEY + this.comment.id
+ );
+ if (generateSuggestionStoredContent?.message === 'false') {
+ this.generateSuggestion = false;
+ }
}
}
@@ -1063,10 +1065,12 @@
?checked=${this.generateSuggestion}
@change=${() => {
this.generateSuggestion = !this.generateSuggestion;
- this.getStorage().setEditableContentItem(
- ENABLE_GENERATE_SUGGESTION_STORAGE_KEY,
- this.generateSuggestion.toString()
- );
+ if (this.comment?.id) {
+ this.getStorage().setEditableContentItem(
+ ENABLE_GENERATE_SUGGESTION_STORAGE_KEY + this.comment.id,
+ this.generateSuggestion.toString()
+ );
+ }
if (this.generateSuggestion) {
this.generateSuggestionTrigger$.next();
} else {