Add hasDrafts property to re-compute attention set "draft" property was incorrectly defined as boolean causing attention set recomputation every time the message was edited in the reply dialog. Define new property hasDrafts which attention set can now depend on. Issue: Bug 13613 Change-Id: I6f77da61b7b1bb9f6aa81169860a09014b7c2c91
diff --git a/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.ts b/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.ts index 687861d..7b34263 100644 --- a/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.ts +++ b/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.ts
@@ -240,6 +240,12 @@ @property({type: Boolean, reflectToAttribute: true}) disabled = false; + @property({ + type: Boolean, + computed: '_computeHasDrafts(draft, draftCommentThreads.*)', + }) + hasDrafts = false; + @property({type: String, observer: '_draftChanged'}) draft = ''; @@ -359,7 +365,7 @@ _sendDisabled?: boolean; @property({type: Array, observer: '_handleHeightChanged'}) - draftCommentThreads?: CommentThread[]; + draftCommentThreads: CommentThread[] | undefined; @property({type: Boolean}) _isResolvedPatchsetLevelComment = true; @@ -453,6 +459,17 @@ } } + _computeHasDrafts( + draft: string, + draftCommentThreads: PolymerDeepPropertyChange< + CommentThread[] | undefined, + CommentThread[] | undefined + > + ) { + if (draftCommentThreads.base === undefined) return false; + return draft.length > 0 || draftCommentThreads.base.length > 0; + } + focus() { this._focusOn(FocusTarget.ANY); } @@ -961,7 +978,7 @@ 'draftCommentThreads', '_includeComments', '_labelsChanged', - 'draft' + 'hasDrafts' ) _computeNewAttention( currentUser?: AccountInfo, @@ -974,7 +991,7 @@ draftCommentThreads?: CommentThread[], includeComments?: boolean, _labelsChanged?: boolean, - draft?: boolean + hasDrafts?: boolean ) { if ( currentUser === undefined || @@ -990,7 +1007,6 @@ // The draft comments are only relevant for the attention set as long as the // user actually plans to publish their drafts. draftCommentThreads = includeComments ? draftCommentThreads : []; - const hasDraft = draftCommentThreads.length > 0 || !!draft; const hasVote = !!_labelsChanged; const isOwner = this._isOwner(currentUser, change); const isUploader = this._uploader?._account_id === currentUser._account_id; @@ -1009,13 +1025,13 @@ // Add all new reviewers, but not the current reviewer, if they are also // sending a draft or a label vote. const notIsReviewerAndHasDraftOrLabel = (r: AccountInfo) => - !(r._account_id === currentUser._account_id && (hasDraft || hasVote)); + !(r._account_id === currentUser._account_id && (hasDrafts || hasVote)); reviewers.base .filter(r => r._pendingAdd && r._account_id) .filter(notIsReviewerAndHasDraftOrLabel) .forEach(r => newAttention.add(r._account_id!)); // Add owner and uploader, if someone else replies. - if (hasDraft || hasVote) { + if (hasDrafts || hasVote) { if (this._uploader?._account_id && !isUploader) { newAttention.add(this._uploader._account_id); }
diff --git a/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog_test.js b/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog_test.js index 7a89f3d..b612a57 100644 --- a/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog_test.js +++ b/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog_test.js
@@ -230,9 +230,12 @@ } element.change = change; element._reviewers = reviewers.base; + flush(); + const hasDrafts = draftThreads.length > 0; element._computeNewAttention( - user, reviewers, [], change, draftThreads, includeComments); + user, reviewers, [], change, draftThreads, includeComments, undefined, + hasDrafts); assert.sameMembers([...element._newAttentionSet], expectedIds); }