Dave Borowitz | 8cdc76b | 2018-03-26 10:04:27 -0400 | [diff] [blame] | 1 | /** |
| 2 | * @license |
Ben Rohlfs | 94fcbbc | 2022-05-27 10:45:03 +0200 | [diff] [blame] | 3 | * Copyright 2015 Google LLC |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
Dave Borowitz | 8cdc76b | 2018-03-26 10:04:27 -0400 | [diff] [blame] | 5 | */ |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 6 | import '../../plugins/gr-endpoint-decorator/gr-endpoint-decorator'; |
Ben Rohlfs | 0e30caa | 2021-12-08 08:48:52 +0100 | [diff] [blame] | 7 | import '../../plugins/gr-endpoint-param/gr-endpoint-param'; |
| 8 | import '../../plugins/gr-endpoint-slot/gr-endpoint-slot'; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 9 | import '../../shared/gr-account-chip/gr-account-chip'; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 10 | import '../../shared/gr-button/gr-button'; |
Chris Poucet | b7e9bb1 | 2022-07-22 14:11:03 +0200 | [diff] [blame] | 11 | import '../../shared/gr-icon/gr-icon'; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 12 | import '../../shared/gr-formatted-text/gr-formatted-text'; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 13 | import '../../shared/gr-account-list/gr-account-list'; |
| 14 | import '../gr-label-scores/gr-label-scores'; |
| 15 | import '../gr-thread-list/gr-thread-list'; |
| 16 | import '../../../styles/shared-styles'; |
Ben Rohlfs | 21220bf | 2022-11-04 08:53:30 +0100 | [diff] [blame] | 17 | import {GrReviewerSuggestionsProvider} from '../../../services/gr-reviewer-suggestions-provider/gr-reviewer-suggestions-provider'; |
Chris Poucet | c6e880b | 2021-11-15 19:57:06 +0100 | [diff] [blame] | 18 | import {getAppContext} from '../../../services/app-context'; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 19 | import { |
| 20 | ChangeStatus, |
| 21 | DraftsAction, |
| 22 | ReviewerState, |
| 23 | SpecialFilePath, |
| 24 | } from '../../../constants/constants'; |
Dhruv Srivastava | eeba456 | 2021-05-06 09:49:52 +0200 | [diff] [blame] | 25 | import { |
Dhruv Srivastava | a1882db | 2022-08-18 10:16:26 +0200 | [diff] [blame] | 26 | getUserId, |
Dhruv Srivastava | 4a9892e | 2022-08-03 17:27:18 +0200 | [diff] [blame] | 27 | isAccountNewlyAdded, |
Dhruv Srivastava | eeba456 | 2021-05-06 09:49:52 +0200 | [diff] [blame] | 28 | removeServiceUsers, |
Dhruv Srivastava | 4a9892e | 2022-08-03 17:27:18 +0200 | [diff] [blame] | 29 | toReviewInput, |
Dhruv Srivastava | eeba456 | 2021-05-06 09:49:52 +0200 | [diff] [blame] | 30 | } from '../../../utils/account-util'; |
Ben Rohlfs | a7ab950 | 2021-02-15 17:45:45 +0100 | [diff] [blame] | 31 | import {TargetElement} from '../../../api/plugin'; |
Ben Rohlfs | f3dc4cf | 2023-03-02 12:49:34 +0100 | [diff] [blame^] | 32 | import {isDefined, ParsedChangeInfo} from '../../../types/types'; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 33 | import { |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 34 | AccountInfoInput, |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 35 | AccountInput, |
Dhruv | 569d616 | 2022-04-08 10:21:00 +0200 | [diff] [blame] | 36 | AccountInputDetail, |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 37 | GrAccountList, |
| 38 | GroupInfoInput, |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 39 | RawAccountInput, |
| 40 | } from '../../shared/gr-account-list/gr-account-list'; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 41 | import { |
| 42 | AccountId, |
| 43 | AccountInfo, |
| 44 | AttentionSetInput, |
| 45 | ChangeInfo, |
Dhruv Srivastava | 65edec8 | 2023-02-28 19:37:59 +0100 | [diff] [blame] | 46 | CommentThread, |
| 47 | DraftInfo, |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 48 | GroupInfo, |
| 49 | isAccount, |
Frank Borden | 891b73e | 2021-01-29 16:43:50 -0800 | [diff] [blame] | 50 | isDetailedLabelInfo, |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 51 | isReviewerAccountSuggestion, |
| 52 | isReviewerGroupSuggestion, |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 53 | ParsedJSON, |
Dhruv Srivastava | 88ff8ac | 2021-07-02 16:23:04 +0200 | [diff] [blame] | 54 | ReviewerInput, |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 55 | ReviewInput, |
| 56 | ReviewResult, |
| 57 | ServerInfo, |
Dhruv | 2235ecb | 2022-04-07 11:58:19 +0200 | [diff] [blame] | 58 | SuggestedReviewerGroupInfo, |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 59 | Suggestion, |
Dhruv Srivastava | 462eb39 | 2022-08-18 10:42:11 +0200 | [diff] [blame] | 60 | UserId, |
Dhruv Srivastava | 4e27dc4 | 2023-03-01 10:49:49 +0100 | [diff] [blame] | 61 | UnsavedInfo, |
| 62 | isDraft, |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 63 | } from '../../../types/common'; |
| 64 | import {GrButton} from '../../shared/gr-button/gr-button'; |
| 65 | import {GrLabelScores} from '../gr-label-scores/gr-label-scores'; |
| 66 | import {GrLabelScoreRow} from '../gr-label-score-row/gr-label-score-row'; |
Ben Rohlfs | d6a4766 | 2020-10-01 14:42:47 +0200 | [diff] [blame] | 67 | import { |
| 68 | areSetsEqual, |
Ben Rohlfs | c1c6afd | 2021-02-18 13:13:22 +0100 | [diff] [blame] | 69 | assertIsDefined, |
Ben Rohlfs | d6a4766 | 2020-10-01 14:42:47 +0200 | [diff] [blame] | 70 | containsAll, |
Dhruv Srivastava | f189ec8 | 2022-08-04 14:33:46 +0200 | [diff] [blame] | 71 | difference, |
Dhruv Srivastava | 5dbf467 | 2021-06-29 09:06:20 +0200 | [diff] [blame] | 72 | queryAndAssert, |
Ben Rohlfs | d6a4766 | 2020-10-01 14:42:47 +0200 | [diff] [blame] | 73 | } from '../../../utils/common-util'; |
Dhruv Srivastava | e75f6f7 | 2022-08-25 10:14:37 +0200 | [diff] [blame] | 74 | import { |
Dhruv Srivastava | 625a0a0 | 2022-11-28 12:13:51 +0100 | [diff] [blame] | 75 | createPatchsetLevelUnsavedDraft, |
Dhruv Srivastava | dc2b34b | 2022-09-01 09:20:32 +0200 | [diff] [blame] | 76 | getFirstComment, |
Dhruv Srivastava | dc2b34b | 2022-09-01 09:20:32 +0200 | [diff] [blame] | 77 | isPatchsetLevel, |
Dhruv Srivastava | e75f6f7 | 2022-08-25 10:14:37 +0200 | [diff] [blame] | 78 | isUnresolved, |
Dhruv Srivastava | e75f6f7 | 2022-08-25 10:14:37 +0200 | [diff] [blame] | 79 | } from '../../../utils/comment-util'; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 80 | import {GrAccountChip} from '../../shared/gr-account-chip/gr-account-chip'; |
Frank Borden | 891b73e | 2021-01-29 16:43:50 -0800 | [diff] [blame] | 81 | import { |
Frank Borden | 891b73e | 2021-01-29 16:43:50 -0800 | [diff] [blame] | 82 | getApprovalInfo, |
| 83 | getMaxAccounts, |
Milutin Kristofic | bd44580 | 2021-10-20 21:00:21 +0200 | [diff] [blame] | 84 | StandardLabels, |
Frank Borden | 891b73e | 2021-01-29 16:43:50 -0800 | [diff] [blame] | 85 | } from '../../../utils/label-util'; |
Milutin Kristofic | 5b3f087 | 2020-12-05 22:08:09 +0100 | [diff] [blame] | 86 | import {pluralize} from '../../../utils/string-util'; |
Ben Rohlfs | 62278c8 | 2021-03-12 11:35:56 +0100 | [diff] [blame] | 87 | import { |
| 88 | fireAlert, |
Ben Rohlfs | 6bb9053 | 2023-02-17 18:55:56 +0100 | [diff] [blame] | 89 | fireError, |
Ben Rohlfs | 44f0104 | 2023-02-18 13:27:57 +0100 | [diff] [blame] | 90 | fire, |
| 91 | fireNoBubble, |
| 92 | fireNoBubbleNoCompose, |
Ben Rohlfs | 62278c8 | 2021-03-12 11:35:56 +0100 | [diff] [blame] | 93 | fireIronAnnounce, |
Ben Rohlfs | 66367b6 | 2021-04-30 10:06:32 +0200 | [diff] [blame] | 94 | fireReload, |
Ben Rohlfs | 62278c8 | 2021-03-12 11:35:56 +0100 | [diff] [blame] | 95 | fireServerError, |
| 96 | } from '../../../utils/event-util'; |
Ben Rohlfs | a7ab950 | 2021-02-15 17:45:45 +0100 | [diff] [blame] | 97 | import {ErrorCallback} from '../../../api/rest'; |
Dhruv Srivastava | 32c4508 | 2022-09-05 15:25:39 +0200 | [diff] [blame] | 98 | import {DelayedTask} from '../../../utils/async-util'; |
Milutin Kristofic | a7c24c1 | 2021-06-07 23:09:26 +0200 | [diff] [blame] | 99 | import {Interaction, Timing} from '../../../constants/reporting'; |
Dhruv Srivastava | 71007ec | 2022-09-09 09:03:42 +0200 | [diff] [blame] | 100 | import { |
| 101 | getMentionedReason, |
| 102 | getReplyByReason, |
| 103 | } from '../../../utils/attention-set-util'; |
Chris Poucet | c6e880b | 2021-11-15 19:57:06 +0100 | [diff] [blame] | 104 | import {RestApiService} from '../../../services/gr-rest-api/gr-rest-api'; |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 105 | import {resolve} from '../../../models/dependency'; |
Chris Poucet | bf65b8f | 2022-01-18 21:18:12 +0000 | [diff] [blame] | 106 | import {changeModelToken} from '../../../models/change/change-model'; |
Dhruv Srivastava | e75f6f7 | 2022-08-25 10:14:37 +0200 | [diff] [blame] | 107 | import { |
| 108 | ConfigInfo, |
| 109 | LabelNameToValuesMap, |
Dhruv Srivastava | b1679c8 | 2022-09-01 09:10:09 +0200 | [diff] [blame] | 110 | PatchSetNumber, |
Dhruv Srivastava | e75f6f7 | 2022-08-25 10:14:37 +0200 | [diff] [blame] | 111 | } from '../../../api/rest-api'; |
Dhruv Srivastava | 92b0c14 | 2022-11-21 20:33:10 +0530 | [diff] [blame] | 112 | import {css, html, PropertyValues, LitElement, nothing} from 'lit'; |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 113 | import {sharedStyles} from '../../../styles/shared-styles'; |
Frank Borden | 42c1a45 | 2022-08-11 16:27:20 +0200 | [diff] [blame] | 114 | import {when} from 'lit/directives/when.js'; |
| 115 | import {classMap} from 'lit/directives/class-map.js'; |
Ben Rohlfs | c368435 | 2023-02-17 16:01:39 +0100 | [diff] [blame] | 116 | import { |
| 117 | AddReviewerEvent, |
| 118 | RemoveReviewerEvent, |
| 119 | ValueChangedEvent, |
| 120 | } from '../../../types/events'; |
Frank Borden | 42c1a45 | 2022-08-11 16:27:20 +0200 | [diff] [blame] | 121 | import {customElement, property, state, query} from 'lit/decorators.js'; |
Frank Borden | 5980103 | 2022-05-06 14:37:18 +0200 | [diff] [blame] | 122 | import {subscribe} from '../../lit/subscription-controller'; |
Dhruv Srivastava | efe10d9c | 2022-06-28 12:22:48 +0200 | [diff] [blame] | 123 | import {configModelToken} from '../../../models/config/config-model'; |
Ben Rohlfs | ead9366 | 2022-08-05 09:09:15 +0200 | [diff] [blame] | 124 | import {hasHumanReviewer, isOwner} from '../../../utils/change-util'; |
Dhruv Srivastava | db01c60 | 2022-07-18 15:34:34 +0200 | [diff] [blame] | 125 | import {commentsModelToken} from '../../../models/comments/comments-model'; |
Dhruv Srivastava | ee018e9 | 2022-08-31 11:37:46 +0200 | [diff] [blame] | 126 | import { |
| 127 | CommentEditingChangedDetail, |
| 128 | GrComment, |
| 129 | } from '../../shared/gr-comment/gr-comment'; |
Dhruv Srivastava | e2cbb80 | 2022-09-07 14:15:48 +0200 | [diff] [blame] | 130 | import {ShortcutController} from '../../lit/shortcut-controller'; |
Dhruv Srivastava | 51b7009 | 2022-10-20 15:26:12 +0200 | [diff] [blame] | 131 | import {Key, Modifier, whenVisible} from '../../../utils/dom-util'; |
Milutin Kristofic | 944063a | 2022-09-14 13:49:55 +0200 | [diff] [blame] | 132 | import {GrThreadList} from '../gr-thread-list/gr-thread-list'; |
Chris Poucet | bb0cf83 | 2022-10-24 12:32:10 +0200 | [diff] [blame] | 133 | import {userModelToken} from '../../../models/user/user-model'; |
Chris Poucet | 4ed2c5d | 2022-10-24 22:28:15 +0200 | [diff] [blame] | 134 | import {accountsModelToken} from '../../../models/accounts-model/accounts-model'; |
Chris Poucet | e3d6686 | 2022-10-26 11:19:50 +0200 | [diff] [blame] | 135 | import {pluginLoaderToken} from '../../shared/gr-js-api-interface/gr-plugin-loader'; |
Dhruv Srivastava | d6bd9df | 2022-11-14 19:46:47 +0530 | [diff] [blame] | 136 | import {modalStyles} from '../../../styles/gr-modal-styles'; |
Ben Rohlfs | f3dc4cf | 2023-03-02 12:49:34 +0100 | [diff] [blame^] | 137 | import {ironAnnouncerRequestAvailability} from '../../polymer-util'; |
Wyatt Allen | 4f4b3a7 | 2016-07-28 12:05:53 -0700 | [diff] [blame] | 138 | |
Milutin Kristofic | bec88f1 | 2020-10-13 16:53:28 +0200 | [diff] [blame] | 139 | export enum FocusTarget { |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 140 | ANY = 'any', |
| 141 | BODY = 'body', |
| 142 | CCS = 'cc', |
| 143 | REVIEWERS = 'reviewers', |
| 144 | } |
Kasper Nilsson | a827155 | 2017-01-17 11:54:40 -0800 | [diff] [blame] | 145 | |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 146 | enum ReviewerType { |
| 147 | REVIEWER = 'REVIEWER', |
| 148 | CC = 'CC', |
| 149 | } |
Wyatt Allen | 6cf5875 | 2017-04-24 16:59:07 +0200 | [diff] [blame] | 150 | |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 151 | enum LatestPatchState { |
| 152 | LATEST = 'latest', |
| 153 | CHECKING = 'checking', |
| 154 | NOT_LATEST = 'not-latest', |
| 155 | } |
Kasper Nilsson | aa746bd | 2017-09-18 22:12:30 -0700 | [diff] [blame] | 156 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 157 | const ButtonLabels = { |
| 158 | START_REVIEW: 'Start review', |
| 159 | SEND: 'Send', |
| 160 | }; |
Wyatt Allen | f2247d4 | 2017-10-26 18:01:18 -0700 | [diff] [blame] | 161 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 162 | const ButtonTooltips = { |
Ben Rohlfs | afc9e1f | 2021-02-15 12:50:35 +0100 | [diff] [blame] | 163 | SAVE: 'Send changes and comments as work in progress but do not start review', |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 164 | START_REVIEW: 'Mark as ready for review and send reply', |
| 165 | SEND: 'Send reply', |
Milutin Kristofic | 216e885 | 2020-12-17 09:18:11 +0100 | [diff] [blame] | 166 | DISABLED_COMMENT_EDITING: 'Save draft comments to enable send', |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 167 | }; |
Kasper Nilsson | fb54dc6 | 2018-03-26 13:57:57 -0700 | [diff] [blame] | 168 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 169 | const EMPTY_REPLY_MESSAGE = 'Cannot send an empty reply.'; |
| 170 | |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 171 | @customElement('gr-reply-dialog') |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 172 | export class GrReplyDialog extends LitElement { |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 173 | FocusTarget = FocusTarget; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 174 | |
Chris Poucet | c6e880b | 2021-11-15 19:57:06 +0100 | [diff] [blame] | 175 | private readonly reporting = getAppContext().reportingService; |
Dmitrii Filippov | 3fd2b10 | 2019-11-15 16:16:46 +0100 | [diff] [blame] | 176 | |
Chris Poucet | bf65b8f | 2022-01-18 21:18:12 +0000 | [diff] [blame] | 177 | private readonly getChangeModel = resolve(this, changeModelToken); |
Dhruv Srivastava | f3cfbe3 | 2021-04-21 16:26:56 +0200 | [diff] [blame] | 178 | |
Chris Poucet | bb0cf83 | 2022-10-24 12:32:10 +0200 | [diff] [blame] | 179 | private readonly getCommentsModel = resolve(this, commentsModelToken); |
Dhruv Srivastava | db01c60 | 2022-07-18 15:34:34 +0200 | [diff] [blame] | 180 | |
Dhruv Srivastava | ed17395 | 2022-08-08 09:37:36 +0200 | [diff] [blame] | 181 | // TODO: update type to only ParsedChangeInfo |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 182 | @property({type: Object}) |
Dhruv Srivastava | ed17395 | 2022-08-08 09:37:36 +0200 | [diff] [blame] | 183 | change?: ParsedChangeInfo | ChangeInfo; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 184 | |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 185 | @property({type: Boolean}) |
| 186 | canBeStarted = false; |
| 187 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 188 | @property({type: Boolean, reflect: true}) |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 189 | disabled = false; |
| 190 | |
Dhruv Srivastava | 11d44e4 | 2022-08-30 14:29:22 +0200 | [diff] [blame] | 191 | @state() |
| 192 | draftCommentThreads: CommentThread[] = []; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 193 | |
| 194 | @property({type: Object}) |
Dhruv Srivastava | 276c6a9 | 2022-03-30 14:58:46 +0200 | [diff] [blame] | 195 | permittedLabels?: LabelNameToValuesMap; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 196 | |
| 197 | @property({type: Object}) |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 198 | projectConfig?: ConfigInfo; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 199 | |
Dhruv Srivastava | e8b8639 | 2022-10-20 17:17:21 +0200 | [diff] [blame] | 200 | @query('#patchsetLevelComment') patchsetLevelGrComment?: GrComment; |
| 201 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 202 | @query('#reviewers') reviewersList?: GrAccountList; |
| 203 | |
| 204 | @query('#ccs') ccsList?: GrAccountList; |
| 205 | |
| 206 | @query('#cancelButton') cancelButton?: GrButton; |
| 207 | |
| 208 | @query('#sendButton') sendButton?: GrButton; |
| 209 | |
| 210 | @query('#labelScores') labelScores?: GrLabelScores; |
| 211 | |
Dhruv Srivastava | d6bd9df | 2022-11-14 19:46:47 +0530 | [diff] [blame] | 212 | @query('#reviewerConfirmationModal') |
| 213 | reviewerConfirmationModal?: HTMLDialogElement; |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 214 | |
Paladox none | d1e1617 | 2023-02-22 19:00:06 +0000 | [diff] [blame] | 215 | @state() latestPatchNum?: PatchSetNumber; |
| 216 | |
Dhruv Srivastava | efe10d9c | 2022-06-28 12:22:48 +0200 | [diff] [blame] | 217 | @state() serverConfig?: ServerInfo; |
| 218 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 219 | @state() |
Chris Poucet | afd0f7c | 2022-10-04 10:04:43 +0000 | [diff] [blame] | 220 | patchsetLevelDraftMessage = ''; |
| 221 | |
| 222 | @state() |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 223 | filterReviewerSuggestion: (input: Suggestion) => boolean; |
| 224 | |
| 225 | @state() |
| 226 | filterCCSuggestion: (input: Suggestion) => boolean; |
| 227 | |
| 228 | @state() |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 229 | knownLatestState?: LatestPatchState; |
| 230 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 231 | @state() |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 232 | underReview = true; |
| 233 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 234 | @state() |
| 235 | account?: AccountInfo; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 236 | |
Dhruv Srivastava | db01c60 | 2022-07-18 15:34:34 +0200 | [diff] [blame] | 237 | get ccs() { |
Dhruv Srivastava | 0758a3c | 2022-08-12 09:53:02 +0200 | [diff] [blame] | 238 | return [ |
| 239 | ...this._ccs, |
| 240 | ...this.mentionedUsers.filter(v => !this.isAlreadyReviewerOrCC(v)), |
| 241 | ]; |
Dhruv Srivastava | db01c60 | 2022-07-18 15:34:34 +0200 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | /** |
| 245 | * We pass the ccs object to AccountInput for modifying where it needs to |
| 246 | * add a value to CC. The returned value contains both mentionedUsers and |
| 247 | * normal ccs hence separate the two when setting ccs. |
| 248 | */ |
| 249 | set ccs(ccs: AccountInput[]) { |
| 250 | this._ccs = ccs.filter( |
| 251 | cc => |
| 252 | !this.mentionedUsers.some( |
Dhruv Srivastava | a1882db | 2022-08-18 10:16:26 +0200 | [diff] [blame] | 253 | mentionedCC => getUserId(mentionedCC) === getUserId(cc) |
Dhruv Srivastava | db01c60 | 2022-07-18 15:34:34 +0200 | [diff] [blame] | 254 | ) |
| 255 | ); |
| 256 | this.requestUpdate('ccs', ccs); |
| 257 | } |
| 258 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 259 | @state() |
Dhruv Srivastava | db01c60 | 2022-07-18 15:34:34 +0200 | [diff] [blame] | 260 | _ccs: AccountInput[] = []; |
| 261 | |
| 262 | /** |
| 263 | * Maintain a separate list of users added to cc due to being mentioned in |
| 264 | * unresolved drafts. |
| 265 | * If the draft is discarded or edited to remove the mention then we want to |
| 266 | * remove the user from being added to CC. |
| 267 | * Instead of figuring out when we should remove the mentioned user ie when |
| 268 | * they get removed from the last comment, we recompute this property when |
| 269 | * any of the draft comments change. |
| 270 | * If we add the user to the existing ccs object then we cannot differentiate |
| 271 | * if the user was added manually to CC or added due to being mentioned hence |
| 272 | * we cannot reset the mentioned ccs when drafts change. |
| 273 | */ |
| 274 | @state() |
| 275 | mentionedUsers: AccountInput[] = []; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 276 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 277 | @state() |
Dhruv Srivastava | 3ffc5ba | 2022-09-15 11:19:52 +0200 | [diff] [blame] | 278 | mentionedUsersInUnresolvedDrafts: AccountInfo[] = []; |
| 279 | |
| 280 | @state() |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 281 | attentionCcsCount = 0; |
Ben Rohlfs | 25937b1 | 2020-10-06 15:12:53 +0200 | [diff] [blame] | 282 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 283 | @state() |
| 284 | ccPendingConfirmation: SuggestedReviewerGroupInfo | null = null; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 285 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 286 | @state() |
| 287 | messagePlaceholder?: string; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 288 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 289 | @state() |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 290 | uploader?: AccountInfo; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 291 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 292 | @state() |
| 293 | pendingConfirmationDetails: SuggestedReviewerGroupInfo | null = null; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 294 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 295 | @state() |
| 296 | includeComments = true; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 297 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 298 | @state() reviewers: AccountInput[] = []; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 299 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 300 | @state() |
| 301 | reviewerPendingConfirmation: SuggestedReviewerGroupInfo | null = null; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 302 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 303 | @state() |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 304 | sendButtonLabel?: string; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 305 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 306 | @state() |
| 307 | savingComments = false; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 308 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 309 | @state() |
| 310 | reviewersMutated = false; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 311 | |
Ben Rohlfs | 21f18ab | 2020-10-13 23:03:08 +0200 | [diff] [blame] | 312 | /** |
| 313 | * Signifies that the user has changed their vote on a label or (if they have |
| 314 | * not yet voted on a label) if a selected vote is different from the default |
| 315 | * vote. |
| 316 | */ |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 317 | @state() |
| 318 | labelsChanged = false; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 319 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 320 | @state() |
| 321 | readonly saveTooltip: string = ButtonTooltips.SAVE; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 322 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 323 | @state() |
| 324 | pluginMessage = ''; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 325 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 326 | @state() |
| 327 | commentEditing = false; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 328 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 329 | @state() |
| 330 | attentionExpanded = false; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 331 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 332 | @state() |
Dhruv Srivastava | 462eb39 | 2022-08-18 10:42:11 +0200 | [diff] [blame] | 333 | currentAttentionSet: Set<UserId> = new Set(); |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 334 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 335 | @state() |
Dhruv Srivastava | 462eb39 | 2022-08-18 10:42:11 +0200 | [diff] [blame] | 336 | newAttentionSet: Set<UserId> = new Set(); |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 337 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 338 | @state() |
| 339 | sendDisabled?: boolean; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 340 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 341 | @state() |
Dhruv Srivastava | 463bb33 | 2022-08-31 13:00:49 +0200 | [diff] [blame] | 342 | patchsetLevelDraftIsResolved = true; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 343 | |
Dhruv Srivastava | e75f6f7 | 2022-08-25 10:14:37 +0200 | [diff] [blame] | 344 | @state() |
Chris Poucet | afd0f7c | 2022-10-04 10:04:43 +0000 | [diff] [blame] | 345 | patchsetLevelComment?: UnsavedInfo | DraftInfo; |
Dhruv Srivastava | e75f6f7 | 2022-08-25 10:14:37 +0200 | [diff] [blame] | 346 | |
Chris Poucet | c6e880b | 2021-11-15 19:57:06 +0100 | [diff] [blame] | 347 | private readonly restApiService: RestApiService = |
| 348 | getAppContext().restApiService; |
Ben Rohlfs | 43935a4 | 2020-12-01 19:14:09 +0100 | [diff] [blame] | 349 | |
Chris Poucet | e3d6686 | 2022-10-26 11:19:50 +0200 | [diff] [blame] | 350 | private readonly getPluginLoader = resolve(this, pluginLoaderToken); |
| 351 | |
Dhruv Srivastava | efe10d9c | 2022-06-28 12:22:48 +0200 | [diff] [blame] | 352 | private readonly getConfigModel = resolve(this, configModelToken); |
| 353 | |
Chris Poucet | 4ed2c5d | 2022-10-24 22:28:15 +0200 | [diff] [blame] | 354 | private readonly getAccountsModel = resolve(this, accountsModelToken); |
Dhruv Srivastava | 71007ec | 2022-09-09 09:03:42 +0200 | [diff] [blame] | 355 | |
Chris Poucet | bb0cf83 | 2022-10-24 12:32:10 +0200 | [diff] [blame] | 356 | private readonly getUserModel = resolve(this, userModelToken); |
| 357 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 358 | storeTask?: DelayedTask; |
Ben Rohlfs | f92d3b5 | 2021-03-10 23:13:03 +0100 | [diff] [blame] | 359 | |
Frank Borden | 5980103 | 2022-05-06 14:37:18 +0200 | [diff] [blame] | 360 | private isLoggedIn = false; |
| 361 | |
Dhruv Srivastava | 712f1d7 | 2022-09-07 10:05:24 +0200 | [diff] [blame] | 362 | private readonly shortcuts = new ShortcutController(this); |
Logan Hanks | add2bce | 2016-07-20 13:22:51 -0700 | [diff] [blame] | 363 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 364 | static override styles = [ |
| 365 | sharedStyles, |
Dhruv Srivastava | d6bd9df | 2022-11-14 19:46:47 +0530 | [diff] [blame] | 366 | modalStyles, |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 367 | css` |
| 368 | :host { |
| 369 | background-color: var(--dialog-background-color); |
| 370 | display: block; |
| 371 | max-height: 90vh; |
Dhruv | 8e9897f | 2022-05-05 11:27:37 +0200 | [diff] [blame] | 372 | --label-score-padding-left: var(--spacing-xl); |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 373 | } |
| 374 | :host([disabled]) { |
| 375 | pointer-events: none; |
| 376 | } |
| 377 | :host([disabled]) .container { |
| 378 | opacity: 0.5; |
| 379 | } |
| 380 | section { |
| 381 | border-top: 1px solid var(--border-color); |
| 382 | flex-shrink: 0; |
| 383 | padding: var(--spacing-m) var(--spacing-xl); |
| 384 | width: 100%; |
| 385 | } |
| 386 | section.labelsContainer { |
| 387 | /* We want the :hover highlight to extend to the border of the dialog. */ |
| 388 | padding: var(--spacing-m) 0; |
| 389 | } |
| 390 | .stickyBottom { |
| 391 | background-color: var(--dialog-background-color); |
| 392 | box-shadow: 0px 0px 8px 0px rgba(60, 64, 67, 0.15); |
| 393 | margin-top: var(--spacing-s); |
| 394 | bottom: 0; |
| 395 | position: sticky; |
| 396 | /* @see Issue 8602 */ |
| 397 | z-index: 1; |
| 398 | } |
| 399 | .stickyBottom.newReplyDialog { |
| 400 | margin-top: unset; |
| 401 | } |
| 402 | .actions { |
| 403 | display: flex; |
| 404 | justify-content: space-between; |
| 405 | } |
| 406 | .actions .right gr-button { |
| 407 | margin-left: var(--spacing-l); |
| 408 | } |
| 409 | .peopleContainer, |
| 410 | .labelsContainer { |
| 411 | flex-shrink: 0; |
| 412 | } |
| 413 | .peopleContainer { |
| 414 | border-top: none; |
| 415 | display: table; |
| 416 | } |
| 417 | .peopleList { |
| 418 | display: flex; |
| 419 | } |
| 420 | .peopleListLabel { |
| 421 | color: var(--deemphasized-text-color); |
| 422 | margin-top: var(--spacing-xs); |
| 423 | min-width: 6em; |
| 424 | padding-right: var(--spacing-m); |
| 425 | } |
| 426 | gr-account-list { |
| 427 | display: flex; |
| 428 | flex-wrap: wrap; |
| 429 | flex: 1; |
| 430 | } |
Dhruv Srivastava | d6bd9df | 2022-11-14 19:46:47 +0530 | [diff] [blame] | 431 | #reviewerConfirmationModal { |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 432 | padding: var(--spacing-l); |
| 433 | text-align: center; |
| 434 | } |
| 435 | .reviewerConfirmationButtons { |
| 436 | margin-top: var(--spacing-l); |
| 437 | } |
| 438 | .groupName { |
| 439 | font-weight: var(--font-weight-bold); |
| 440 | } |
| 441 | .groupSize { |
| 442 | font-style: italic; |
| 443 | } |
| 444 | .textareaContainer { |
| 445 | min-height: 12em; |
| 446 | position: relative; |
| 447 | } |
| 448 | .newReplyDialog.textareaContainer { |
| 449 | min-height: unset; |
| 450 | } |
| 451 | textareaContainer, |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 452 | gr-endpoint-decorator[name='reply-text'] { |
| 453 | display: flex; |
| 454 | width: 100%; |
| 455 | } |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 456 | gr-endpoint-decorator[name='reply-text'] { |
| 457 | flex-direction: column; |
| 458 | } |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 459 | #checkingStatusLabel, |
| 460 | #notLatestLabel { |
| 461 | margin-left: var(--spacing-l); |
| 462 | } |
| 463 | #checkingStatusLabel { |
| 464 | color: var(--deemphasized-text-color); |
| 465 | font-style: italic; |
| 466 | } |
| 467 | #notLatestLabel, |
| 468 | #savingLabel { |
| 469 | color: var(--error-text-color); |
| 470 | } |
| 471 | #savingLabel { |
| 472 | display: none; |
| 473 | } |
| 474 | #savingLabel.saving { |
| 475 | display: inline; |
| 476 | } |
| 477 | #pluginMessage { |
| 478 | color: var(--deemphasized-text-color); |
| 479 | margin-left: var(--spacing-l); |
| 480 | margin-bottom: var(--spacing-m); |
| 481 | } |
| 482 | #pluginMessage:empty { |
| 483 | display: none; |
| 484 | } |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 485 | .attention .edit-attention-button { |
| 486 | vertical-align: top; |
| 487 | --gr-button-padding: 0px 4px; |
| 488 | } |
Chris Poucet | b7e9bb1 | 2022-07-22 14:11:03 +0200 | [diff] [blame] | 489 | .attention .edit-attention-button gr-icon { |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 490 | color: inherit; |
Ben Rohlfs | b1b0ac9 | 2022-08-01 14:33:02 +0200 | [diff] [blame] | 491 | /* The line-height:26px hack (see below) requires us to do this. |
| 492 | Normally the gr-icon would account for a proper positioning |
| 493 | within the standard line-height:20px context. */ |
| 494 | top: 5px; |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 495 | } |
| 496 | .attention a, |
| 497 | .attention-detail a { |
| 498 | text-decoration: none; |
| 499 | } |
| 500 | .attentionSummary { |
| 501 | display: flex; |
| 502 | justify-content: space-between; |
| 503 | } |
| 504 | .attentionSummary { |
| 505 | /* The account label for selection is misbehaving currently: It consumes |
| 506 | 26px height instead of 20px, which is the default line-height and thus |
| 507 | the max that can be nicely fit into an inline layout flow. We |
| 508 | acknowledge that using a fixed 26px value here is a hack and not a |
| 509 | great solution. */ |
| 510 | line-height: 26px; |
| 511 | } |
| 512 | .attentionSummary gr-account-label, |
| 513 | .attention-detail gr-account-label { |
| 514 | --account-max-length: 120px; |
| 515 | display: inline-block; |
| 516 | padding: var(--spacing-xs) var(--spacing-m); |
| 517 | user-select: none; |
| 518 | --label-border-radius: 8px; |
| 519 | } |
| 520 | .attentionSummary gr-account-label { |
| 521 | margin: 0 var(--spacing-xs); |
| 522 | line-height: var(--line-height-normal); |
| 523 | vertical-align: top; |
| 524 | } |
| 525 | .attention-detail .peopleListValues { |
| 526 | line-height: calc(var(--line-height-normal) + 10px); |
| 527 | } |
| 528 | .attention-detail gr-account-label { |
| 529 | line-height: var(--line-height-normal); |
| 530 | } |
| 531 | .attentionSummary gr-account-label:focus, |
| 532 | .attention-detail gr-account-label:focus { |
| 533 | outline: none; |
| 534 | } |
| 535 | .attentionSummary gr-account-label:hover, |
| 536 | .attention-detail gr-account-label:hover { |
| 537 | box-shadow: var(--elevation-level-1); |
| 538 | cursor: pointer; |
| 539 | } |
| 540 | .attention-detail .attentionDetailsTitle { |
| 541 | display: flex; |
| 542 | justify-content: space-between; |
| 543 | } |
| 544 | .attention-detail .selectUsers { |
| 545 | color: var(--deemphasized-text-color); |
| 546 | margin-bottom: var(--spacing-m); |
| 547 | } |
| 548 | .attentionTip { |
| 549 | padding: var(--spacing-m); |
| 550 | border: 1px solid var(--border-color); |
| 551 | border-radius: var(--border-radius); |
| 552 | margin-top: var(--spacing-m); |
Kamil Musin | e062971 | 2023-02-06 15:06:25 +0100 | [diff] [blame] | 553 | background-color: var(--line-item-highlight-color); |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 554 | } |
Chris Poucet | b7e9bb1 | 2022-07-22 14:11:03 +0200 | [diff] [blame] | 555 | .attentionTip div gr-icon { |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 556 | margin-right: var(--spacing-s); |
| 557 | } |
| 558 | .patchsetLevelContainer { |
| 559 | width: 80ch; |
| 560 | border-radius: var(--border-radius); |
| 561 | box-shadow: var(--elevation-level-2); |
| 562 | } |
| 563 | .patchsetLevelContainer.resolved { |
| 564 | background-color: var(--comment-background-color); |
| 565 | } |
| 566 | .patchsetLevelContainer.unresolved { |
| 567 | background-color: var(--unresolved-comment-background-color); |
| 568 | } |
Ben Rohlfs | e48dece | 2022-11-24 11:11:43 +0000 | [diff] [blame] | 569 | .privateVisiblityInfo { |
Dhruv Srivastava | 92b0c14 | 2022-11-21 20:33:10 +0530 | [diff] [blame] | 570 | display: flex; |
| 571 | justify-content: center; |
| 572 | background-color: var(--info-background); |
| 573 | padding: var(--spacing-s) 0; |
| 574 | } |
Ben Rohlfs | e48dece | 2022-11-24 11:11:43 +0000 | [diff] [blame] | 575 | .privateVisiblityInfo gr-icon { |
Dhruv Srivastava | 92b0c14 | 2022-11-21 20:33:10 +0530 | [diff] [blame] | 576 | margin-right: var(--spacing-m); |
| 577 | color: var(--info-foreground); |
| 578 | } |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 579 | `, |
| 580 | ]; |
| 581 | |
Chris Poucet | 5ec77f0 | 2022-05-12 11:25:21 +0200 | [diff] [blame] | 582 | constructor() { |
| 583 | super(); |
| 584 | this.filterReviewerSuggestion = |
| 585 | this.filterReviewerSuggestionGenerator(false); |
| 586 | this.filterCCSuggestion = this.filterReviewerSuggestionGenerator(true); |
Dhruv Srivastava | 712f1d7 | 2022-09-07 10:05:24 +0200 | [diff] [blame] | 587 | |
| 588 | this.shortcuts.addLocal({key: Key.ESC}, () => this.cancel()); |
Dhruv Srivastava | e2cbb80 | 2022-09-07 14:15:48 +0200 | [diff] [blame] | 589 | this.shortcuts.addLocal( |
| 590 | {key: Key.ENTER, modifiers: [Modifier.CTRL_KEY]}, |
| 591 | () => this.submit() |
| 592 | ); |
| 593 | this.shortcuts.addLocal( |
| 594 | {key: Key.ENTER, modifiers: [Modifier.META_KEY]}, |
| 595 | () => this.submit() |
| 596 | ); |
Dhruv Srivastava | 712f1d7 | 2022-09-07 10:05:24 +0200 | [diff] [blame] | 597 | |
Chris Poucet | 5ec77f0 | 2022-05-12 11:25:21 +0200 | [diff] [blame] | 598 | subscribe( |
| 599 | this, |
Chris Poucet | bb0cf83 | 2022-10-24 12:32:10 +0200 | [diff] [blame] | 600 | () => this.getUserModel().loggedIn$, |
Chris Poucet | 5ec77f0 | 2022-05-12 11:25:21 +0200 | [diff] [blame] | 601 | isLoggedIn => (this.isLoggedIn = isLoggedIn) |
| 602 | ); |
Dhruv Srivastava | efe10d9c | 2022-06-28 12:22:48 +0200 | [diff] [blame] | 603 | subscribe( |
| 604 | this, |
| 605 | () => this.getConfigModel().serverConfig$, |
| 606 | config => { |
| 607 | this.serverConfig = config; |
| 608 | } |
| 609 | ); |
Dhruv Srivastava | ed17395 | 2022-08-08 09:37:36 +0200 | [diff] [blame] | 610 | subscribe( |
| 611 | this, |
| 612 | () => this.getChangeModel().change$, |
Dhruv Srivastava | db01c60 | 2022-07-18 15:34:34 +0200 | [diff] [blame] | 613 | x => (this.change = x) |
| 614 | ); |
| 615 | subscribe( |
| 616 | this, |
Dhruv Srivastava | b1679c8 | 2022-09-01 09:10:09 +0200 | [diff] [blame] | 617 | () => this.getChangeModel().latestPatchNum$, |
| 618 | x => (this.latestPatchNum = x) |
| 619 | ); |
| 620 | subscribe( |
| 621 | this, |
Dhruv Srivastava | db01c60 | 2022-07-18 15:34:34 +0200 | [diff] [blame] | 622 | () => this.getCommentsModel().mentionedUsersInDrafts$, |
Dhruv Srivastava | ed17395 | 2022-08-08 09:37:36 +0200 | [diff] [blame] | 623 | x => { |
Dhruv Srivastava | 0758a3c | 2022-08-12 09:53:02 +0200 | [diff] [blame] | 624 | this.mentionedUsers = x; |
Dhruv Srivastava | db01c60 | 2022-07-18 15:34:34 +0200 | [diff] [blame] | 625 | this.reviewersMutated = |
| 626 | this.reviewersMutated || this.mentionedUsers.length > 0; |
| 627 | } |
| 628 | ); |
| 629 | subscribe( |
| 630 | this, |
| 631 | () => this.getCommentsModel().mentionedUsersInUnresolvedDrafts$, |
| 632 | x => { |
Dhruv Srivastava | db01c60 | 2022-07-18 15:34:34 +0200 | [diff] [blame] | 633 | this.mentionedUsersInUnresolvedDrafts = x.filter( |
| 634 | v => !this.isAlreadyReviewerOrCC(v) |
| 635 | ); |
Dhruv Srivastava | ed17395 | 2022-08-08 09:37:36 +0200 | [diff] [blame] | 636 | } |
| 637 | ); |
Dhruv Srivastava | 4e5fd11 | 2022-08-25 12:01:22 +0200 | [diff] [blame] | 638 | subscribe( |
| 639 | this, |
| 640 | () => this.getCommentsModel().patchsetLevelDrafts$, |
Chris Poucet | afd0f7c | 2022-10-04 10:04:43 +0000 | [diff] [blame] | 641 | x => (this.patchsetLevelComment = x[0]) |
Dhruv Srivastava | 4e5fd11 | 2022-08-25 12:01:22 +0200 | [diff] [blame] | 642 | ); |
Dhruv Srivastava | 11d44e4 | 2022-08-30 14:29:22 +0200 | [diff] [blame] | 643 | subscribe( |
| 644 | this, |
| 645 | () => this.getCommentsModel().draftThreads$, |
Dhruv Srivastava | fb91ec9 | 2022-08-25 14:22:53 +0200 | [diff] [blame] | 646 | threads => |
| 647 | (this.draftCommentThreads = threads.filter( |
Dhruv Srivastava | dc2b34b | 2022-09-01 09:20:32 +0200 | [diff] [blame] | 648 | t => !(isDraft(getFirstComment(t)) && isPatchsetLevel(t)) |
Dhruv Srivastava | fb91ec9 | 2022-08-25 14:22:53 +0200 | [diff] [blame] | 649 | )) |
Dhruv Srivastava | 11d44e4 | 2022-08-30 14:29:22 +0200 | [diff] [blame] | 650 | ); |
Chris Poucet | 5ec77f0 | 2022-05-12 11:25:21 +0200 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | override connectedCallback() { |
| 654 | super.connectedCallback(); |
Ben Rohlfs | f3dc4cf | 2023-03-02 12:49:34 +0100 | [diff] [blame^] | 655 | ironAnnouncerRequestAvailability(); |
Chris Poucet | e3d6686 | 2022-10-26 11:19:50 +0200 | [diff] [blame] | 656 | |
| 657 | this.getPluginLoader().jsApiService.addElement( |
| 658 | TargetElement.REPLY_DIALOG, |
| 659 | this |
| 660 | ); |
| 661 | |
Chris Poucet | 5ec77f0 | 2022-05-12 11:25:21 +0200 | [diff] [blame] | 662 | this.restApiService.getAccount().then(account => { |
| 663 | if (account) this.account = account; |
| 664 | }); |
| 665 | |
Dhruv Srivastava | ee018e9 | 2022-08-31 11:37:46 +0200 | [diff] [blame] | 666 | this.addEventListener( |
| 667 | 'comment-editing-changed', |
| 668 | (e: CustomEvent<CommentEditingChangedDetail>) => { |
| 669 | // Patchset level comment is always in editing mode which means it would |
| 670 | // set commentEditing = true and the send button would be permanently |
| 671 | // disabled. |
| 672 | if (e.detail.path === SpecialFilePath.PATCHSET_LEVEL_COMMENTS) return; |
Milutin Kristofic | 944063a | 2022-09-14 13:49:55 +0200 | [diff] [blame] | 673 | const commentList = queryAndAssert<GrThreadList>(this, '#commentList'); |
| 674 | // It can be one or more comments were in editing mode. Wwitching one |
| 675 | // thread in editing, we need to check if there are still other threads |
| 676 | // in editing. |
| 677 | this.commentEditing = Array.from(commentList.threadElements ?? []).some( |
| 678 | thread => thread.editing |
| 679 | ); |
Dhruv Srivastava | ee018e9 | 2022-08-31 11:37:46 +0200 | [diff] [blame] | 680 | } |
| 681 | ); |
Chris Poucet | 5ec77f0 | 2022-05-12 11:25:21 +0200 | [diff] [blame] | 682 | |
| 683 | // Plugins on reply-reviewers endpoint can take advantage of these |
| 684 | // events to add / remove reviewers |
| 685 | |
Ben Rohlfs | c368435 | 2023-02-17 16:01:39 +0100 | [diff] [blame] | 686 | this.addEventListener('add-reviewer', (e: AddReviewerEvent) => { |
| 687 | const reviewer = e.detail.reviewer; |
Chris Poucet | 5ec77f0 | 2022-05-12 11:25:21 +0200 | [diff] [blame] | 688 | // Only support account type, see more from: |
| 689 | // elements/shared/gr-account-list/gr-account-list.js#addAccountItem |
| 690 | this.reviewersList?.addAccountItem({ |
Ben Rohlfs | c368435 | 2023-02-17 16:01:39 +0100 | [diff] [blame] | 691 | account: reviewer, |
Chris Poucet | 5ec77f0 | 2022-05-12 11:25:21 +0200 | [diff] [blame] | 692 | count: 1, |
| 693 | }); |
| 694 | }); |
| 695 | |
Ben Rohlfs | c368435 | 2023-02-17 16:01:39 +0100 | [diff] [blame] | 696 | this.addEventListener('remove-reviewer', (e: RemoveReviewerEvent) => { |
| 697 | const reviewer = e.detail.reviewer; |
| 698 | this.reviewersList?.removeAccount(reviewer); |
Chris Poucet | 5ec77f0 | 2022-05-12 11:25:21 +0200 | [diff] [blame] | 699 | }); |
| 700 | } |
| 701 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 702 | override willUpdate(changedProperties: PropertyValues) { |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 703 | if (changedProperties.has('ccPendingConfirmation')) { |
| 704 | this.pendingConfirmationUpdated(this.ccPendingConfirmation); |
| 705 | } |
| 706 | if (changedProperties.has('reviewerPendingConfirmation')) { |
| 707 | this.pendingConfirmationUpdated(this.reviewerPendingConfirmation); |
| 708 | } |
| 709 | if (changedProperties.has('change')) { |
| 710 | this.computeUploader(); |
Dhruv Srivastava | ed17395 | 2022-08-08 09:37:36 +0200 | [diff] [blame] | 711 | this.rebuildReviewerArrays(); |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 712 | } |
| 713 | if (changedProperties.has('canBeStarted')) { |
| 714 | this.computeMessagePlaceholder(); |
| 715 | this.computeSendButtonLabel(); |
| 716 | } |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 717 | if (changedProperties.has('sendDisabled')) { |
| 718 | this.sendDisabledChanged(); |
| 719 | } |
| 720 | if (changedProperties.has('attentionExpanded')) { |
| 721 | this.onAttentionExpandedChange(); |
| 722 | } |
| 723 | if ( |
| 724 | changedProperties.has('account') || |
| 725 | changedProperties.has('reviewers') || |
| 726 | changedProperties.has('ccs') || |
| 727 | changedProperties.has('change') || |
| 728 | changedProperties.has('draftCommentThreads') || |
Dhruv Srivastava | 3ffc5ba | 2022-09-15 11:19:52 +0200 | [diff] [blame] | 729 | changedProperties.has('mentionedUsersInUnresolvedDrafts') || |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 730 | changedProperties.has('includeComments') || |
| 731 | changedProperties.has('labelsChanged') || |
Chris Poucet | afd0f7c | 2022-10-04 10:04:43 +0000 | [diff] [blame] | 732 | changedProperties.has('patchsetLevelDraftMessage') || |
Dhruv Srivastava | db01c60 | 2022-07-18 15:34:34 +0200 | [diff] [blame] | 733 | changedProperties.has('mentionedCCs') |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 734 | ) { |
| 735 | this.computeNewAttention(); |
| 736 | } |
| 737 | } |
| 738 | |
Gerrit Code Review | 09637ae | 2021-08-19 14:34:39 +0000 | [diff] [blame] | 739 | override disconnectedCallback() { |
Dhruv | d543552 | 2022-06-22 14:58:47 +0200 | [diff] [blame] | 740 | this.storeTask?.flush(); |
Ben Rohlfs | 5f520da | 2021-03-10 14:58:43 +0100 | [diff] [blame] | 741 | super.disconnectedCallback(); |
Ben Rohlfs | 04fc1ca | 2021-02-13 13:06:53 +0100 | [diff] [blame] | 742 | } |
| 743 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 744 | override render() { |
| 745 | if (!this.change) return; |
| 746 | this.sendDisabled = this.computeSendButtonDisabled(); |
| 747 | return html` |
| 748 | <div tabindex="-1"> |
| 749 | <section class="peopleContainer"> |
| 750 | <gr-endpoint-decorator name="reply-reviewers"> |
| 751 | <gr-endpoint-param |
Milutin Kristofic | 8f69b30 | 2022-05-10 10:47:09 +0200 | [diff] [blame] | 752 | name="change" |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 753 | .value=${this.change} |
| 754 | ></gr-endpoint-param> |
Dhruv Srivastava | 418c48d | 2022-08-03 14:35:10 +0200 | [diff] [blame] | 755 | <gr-endpoint-param name="reviewers" .value=${[...this.reviewers]}> |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 756 | </gr-endpoint-param> |
| 757 | ${this.renderReviewerList()} |
| 758 | <gr-endpoint-slot name="below"></gr-endpoint-slot> |
| 759 | </gr-endpoint-decorator> |
| 760 | ${this.renderCCList()} ${this.renderReviewConfirmation()} |
Dhruv Srivastava | 92b0c14 | 2022-11-21 20:33:10 +0530 | [diff] [blame] | 761 | ${this.renderPrivateVisiblityInfo()} |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 762 | </section> |
| 763 | <section class="labelsContainer">${this.renderLabels()}</section> |
| 764 | <section class="newReplyDialog textareaContainer"> |
| 765 | ${this.renderReplyText()} |
| 766 | </section> |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 767 | ${this.renderDraftsSection()} |
| 768 | <div class="stickyBottom newReplyDialog"> |
| 769 | <gr-endpoint-decorator name="reply-bottom"> |
| 770 | <gr-endpoint-param |
Milutin Kristofic | 1116890 | 2022-05-10 10:51:18 +0200 | [diff] [blame] | 771 | name="change" |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 772 | .value=${this.change} |
| 773 | ></gr-endpoint-param> |
| 774 | ${this.renderAttentionSummarySection()} |
| 775 | ${this.renderAttentionDetailsSection()} |
| 776 | <gr-endpoint-slot name="above-actions"></gr-endpoint-slot> |
| 777 | ${this.renderActionsSection()} |
| 778 | </gr-endpoint-decorator> |
| 779 | </div> |
| 780 | </div> |
| 781 | `; |
| 782 | } |
| 783 | |
| 784 | private renderReviewerList() { |
| 785 | return html` |
| 786 | <div class="peopleList"> |
| 787 | <div class="peopleListLabel">Reviewers</div> |
| 788 | <gr-account-list |
| 789 | id="reviewers" |
Dhruv Srivastava | db01c60 | 2022-07-18 15:34:34 +0200 | [diff] [blame] | 790 | .accounts=${[...this.reviewers]} |
Dhruv Srivastava | 9a89815 | 2022-07-08 15:53:54 +0200 | [diff] [blame] | 791 | .change=${this.change} |
Dhruv Srivastava | 4a9892e | 2022-08-03 17:27:18 +0200 | [diff] [blame] | 792 | .reviewerState=${ReviewerState.REVIEWER} |
Dhruv Srivastava | db01c60 | 2022-07-18 15:34:34 +0200 | [diff] [blame] | 793 | @account-added=${this.handleAccountAdded} |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 794 | @accounts-changed=${this.handleReviewersChanged} |
| 795 | .removableValues=${this.change?.removable_reviewers} |
| 796 | .filter=${this.filterReviewerSuggestion} |
| 797 | .pendingConfirmation=${this.reviewerPendingConfirmation} |
| 798 | @pending-confirmation-changed=${this |
| 799 | .handleReviewersConfirmationChanged} |
| 800 | .placeholder=${'Add reviewer...'} |
| 801 | @account-text-changed=${this.handleAccountTextEntry} |
| 802 | .suggestionsProvider=${this.getReviewerSuggestionsProvider( |
| 803 | this.change |
| 804 | )} |
| 805 | > |
| 806 | </gr-account-list> |
| 807 | <gr-endpoint-slot name="right"></gr-endpoint-slot> |
| 808 | </div> |
| 809 | `; |
| 810 | } |
| 811 | |
| 812 | private renderCCList() { |
| 813 | return html` |
| 814 | <div class="peopleList"> |
| 815 | <div class="peopleListLabel">CC</div> |
| 816 | <gr-account-list |
| 817 | id="ccs" |
Dhruv Srivastava | db01c60 | 2022-07-18 15:34:34 +0200 | [diff] [blame] | 818 | .accounts=${[...this.ccs]} |
Dhruv Srivastava | 4a9892e | 2022-08-03 17:27:18 +0200 | [diff] [blame] | 819 | .change=${this.change} |
| 820 | .reviewerState=${ReviewerState.CC} |
Dhruv Srivastava | db01c60 | 2022-07-18 15:34:34 +0200 | [diff] [blame] | 821 | @account-added=${this.handleAccountAdded} |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 822 | @accounts-changed=${this.handleCcsChanged} |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 823 | .filter=${this.filterCCSuggestion} |
| 824 | .pendingConfirmation=${this.ccPendingConfirmation} |
| 825 | @pending-confirmation-changed=${this.handleCcsConfirmationChanged} |
| 826 | allow-any-input |
| 827 | .placeholder=${'Add CC...'} |
| 828 | @account-text-changed=${this.handleAccountTextEntry} |
| 829 | .suggestionsProvider=${this.getCcSuggestionsProvider(this.change)} |
| 830 | > |
| 831 | </gr-account-list> |
| 832 | </div> |
| 833 | `; |
| 834 | } |
| 835 | |
| 836 | private renderReviewConfirmation() { |
| 837 | return html` |
Dhruv Srivastava | d6bd9df | 2022-11-14 19:46:47 +0530 | [diff] [blame] | 838 | <dialog |
| 839 | tabindex="-1" |
| 840 | id="reviewerConfirmationModal" |
| 841 | @close=${this.cancelPendingReviewer} |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 842 | > |
| 843 | <div class="reviewerConfirmation"> |
| 844 | Group |
| 845 | <span class="groupName"> |
| 846 | ${this.pendingConfirmationDetails?.group.name} |
| 847 | </span> |
| 848 | has |
| 849 | <span class="groupSize"> |
| 850 | ${this.pendingConfirmationDetails?.count} |
| 851 | </span> |
| 852 | members. |
| 853 | <br /> |
| 854 | Are you sure you want to add them all? |
| 855 | </div> |
| 856 | <div class="reviewerConfirmationButtons"> |
| 857 | <gr-button @click=${this.confirmPendingReviewer}>Yes</gr-button> |
| 858 | <gr-button @click=${this.cancelPendingReviewer}>No</gr-button> |
| 859 | </div> |
Dhruv Srivastava | d6bd9df | 2022-11-14 19:46:47 +0530 | [diff] [blame] | 860 | </dialog> |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 861 | `; |
| 862 | } |
| 863 | |
Dhruv Srivastava | 92b0c14 | 2022-11-21 20:33:10 +0530 | [diff] [blame] | 864 | private renderPrivateVisiblityInfo() { |
| 865 | const addedAccounts = [ |
| 866 | ...(this.reviewersList?.additions() ?? []), |
| 867 | ...(this.ccsList?.additions() ?? []), |
| 868 | ]; |
| 869 | if (!this.change?.is_private || !addedAccounts.length) return nothing; |
| 870 | return html` |
Ben Rohlfs | e48dece | 2022-11-24 11:11:43 +0000 | [diff] [blame] | 871 | <div class="privateVisiblityInfo"> |
Dhruv Srivastava | 92b0c14 | 2022-11-21 20:33:10 +0530 | [diff] [blame] | 872 | <gr-icon icon="info"></gr-icon> |
| 873 | <div> |
| 874 | Adding a reviewer/CC will make this private change visible to them |
| 875 | </div> |
| 876 | </div> |
| 877 | `; |
| 878 | } |
| 879 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 880 | private renderLabels() { |
| 881 | if (!this.change || !this.account || !this.permittedLabels) return; |
| 882 | return html` |
| 883 | <gr-endpoint-decorator name="reply-label-scores"> |
| 884 | <gr-label-scores |
| 885 | id="labelScores" |
| 886 | .account=${this.account} |
| 887 | .change=${this.change} |
| 888 | @labels-changed=${this._handleLabelsChanged} |
| 889 | .permittedLabels=${this.permittedLabels} |
| 890 | ></gr-label-scores> |
| 891 | <gr-endpoint-param |
Milutin Kristofic | 1116890 | 2022-05-10 10:51:18 +0200 | [diff] [blame] | 892 | name="change" |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 893 | .value=${this.change} |
| 894 | ></gr-endpoint-param> |
| 895 | </gr-endpoint-decorator> |
| 896 | <div id="pluginMessage">${this.pluginMessage}</div> |
| 897 | `; |
| 898 | } |
| 899 | |
Dhruv Srivastava | e75f6f7 | 2022-08-25 10:14:37 +0200 | [diff] [blame] | 900 | private renderPatchsetLevelComment() { |
Chris Poucet | afd0f7c | 2022-10-04 10:04:43 +0000 | [diff] [blame] | 901 | if (!this.patchsetLevelComment) |
Dhruv Srivastava | 625a0a0 | 2022-11-28 12:13:51 +0100 | [diff] [blame] | 902 | this.patchsetLevelComment = createPatchsetLevelUnsavedDraft( |
| 903 | this.latestPatchNum, |
| 904 | this.patchsetLevelDraftMessage, |
| 905 | !this.patchsetLevelDraftIsResolved |
| 906 | ); |
Dhruv Srivastava | e75f6f7 | 2022-08-25 10:14:37 +0200 | [diff] [blame] | 907 | return html` |
| 908 | <gr-comment |
Dhruv Srivastava | 8bdda3b | 2022-08-30 19:11:31 +0200 | [diff] [blame] | 909 | id="patchsetLevelComment" |
Dhruv Srivastava | e75f6f7 | 2022-08-25 10:14:37 +0200 | [diff] [blame] | 910 | .comment=${this.patchsetLevelComment} |
| 911 | .comments=${[this.patchsetLevelComment]} |
Dhruv Srivastava | 463bb33 | 2022-08-31 13:00:49 +0200 | [diff] [blame] | 912 | @comment-unresolved-changed=${(e: ValueChangedEvent<boolean>) => { |
| 913 | this.patchsetLevelDraftIsResolved = !e.detail.value; |
| 914 | }} |
| 915 | @comment-text-changed=${(e: ValueChangedEvent<string>) => { |
Chris Poucet | afd0f7c | 2022-10-04 10:04:43 +0000 | [diff] [blame] | 916 | this.patchsetLevelDraftMessage = e.detail.value; |
Dhruv Srivastava | b619964 | 2022-08-30 18:49:32 +0200 | [diff] [blame] | 917 | }} |
Dhruv Srivastava | f007abc | 2022-09-06 11:18:57 +0200 | [diff] [blame] | 918 | .messagePlaceholder=${this.messagePlaceholder} |
Dhruv Srivastava | e75f6f7 | 2022-08-25 10:14:37 +0200 | [diff] [blame] | 919 | hide-header |
Dhruv Srivastava | 4e5fd11 | 2022-08-25 12:01:22 +0200 | [diff] [blame] | 920 | permanent-editing-mode |
Dhruv Srivastava | e75f6f7 | 2022-08-25 10:14:37 +0200 | [diff] [blame] | 921 | ></gr-comment> |
| 922 | `; |
| 923 | } |
| 924 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 925 | private renderReplyText() { |
| 926 | if (!this.change) return; |
| 927 | return html` |
| 928 | <div |
| 929 | class=${classMap({ |
| 930 | patchsetLevelContainer: true, |
| 931 | [this.getUnresolvedPatchsetLevelClass( |
Dhruv Srivastava | 463bb33 | 2022-08-31 13:00:49 +0200 | [diff] [blame] | 932 | this.patchsetLevelDraftIsResolved |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 933 | )]: true, |
| 934 | })} |
| 935 | > |
| 936 | <gr-endpoint-decorator name="reply-text"> |
Dhruv Srivastava | e75f6f7 | 2022-08-25 10:14:37 +0200 | [diff] [blame] | 937 | ${this.renderPatchsetLevelComment()} |
Milutin Kristofic | 1116890 | 2022-05-10 10:51:18 +0200 | [diff] [blame] | 938 | <gr-endpoint-param name="change" .value=${this.change}> |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 939 | </gr-endpoint-param> |
| 940 | </gr-endpoint-decorator> |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 941 | </div> |
| 942 | `; |
| 943 | } |
| 944 | |
| 945 | private renderDraftsSection() { |
| 946 | if (this.computeHideDraftList(this.draftCommentThreads)) return; |
| 947 | return html` |
| 948 | <section class="draftsContainer"> |
| 949 | <div class="includeComments"> |
| 950 | <input |
| 951 | type="checkbox" |
| 952 | id="includeComments" |
| 953 | @change=${this.handleIncludeCommentsChanged} |
| 954 | ?checked=${this.includeComments} |
| 955 | /> |
| 956 | <label for="includeComments" |
| 957 | >Publish ${this.computeDraftsTitle(this.draftCommentThreads)}</label |
| 958 | > |
| 959 | </div> |
| 960 | ${when( |
| 961 | this.includeComments, |
| 962 | () => html` |
| 963 | <gr-thread-list |
| 964 | id="commentList" |
Dhruv Srivastava | 11d44e4 | 2022-08-30 14:29:22 +0200 | [diff] [blame] | 965 | .threads=${this.draftCommentThreads} |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 966 | hide-dropdown |
| 967 | > |
| 968 | </gr-thread-list> |
| 969 | ` |
| 970 | )} |
| 971 | <span |
| 972 | id="savingLabel" |
| 973 | class=${this.computeSavingLabelClass(this.savingComments)} |
| 974 | > |
| 975 | Saving comments... |
| 976 | </span> |
| 977 | </section> |
| 978 | `; |
| 979 | } |
| 980 | |
| 981 | private renderAttentionSummarySection() { |
| 982 | if (this.attentionExpanded) return; |
| 983 | return html` |
| 984 | <section class="attention"> |
| 985 | <div class="attentionSummary"> |
| 986 | <div> |
| 987 | ${when( |
| 988 | this.computeShowNoAttentionUpdate(), |
| 989 | () => html` <span>${this.computeDoNotUpdateMessage()}</span> ` |
| 990 | )} |
| 991 | ${when( |
| 992 | !this.computeShowNoAttentionUpdate(), |
| 993 | () => html` |
| 994 | <span>Bring to attention of</span> |
| 995 | ${this.computeNewAttentionAccounts().map( |
| 996 | account => html` |
| 997 | <gr-account-label |
| 998 | .account=${account} |
| 999 | .forceAttention=${this.computeHasNewAttention(account)} |
| 1000 | .selected=${this.computeHasNewAttention(account)} |
| 1001 | .hideHovercard=${true} |
| 1002 | .selectionChipStyle=${true} |
| 1003 | @click=${this.handleAttentionClick} |
| 1004 | ></gr-account-label> |
| 1005 | ` |
| 1006 | )} |
| 1007 | ` |
| 1008 | )} |
| 1009 | <gr-tooltip-content |
| 1010 | has-tooltip |
| 1011 | title=${this.computeAttentionButtonTitle()} |
| 1012 | > |
| 1013 | <gr-button |
| 1014 | class="edit-attention-button" |
| 1015 | @click=${this.handleAttentionModify} |
| 1016 | ?disabled=${this.sendDisabled} |
| 1017 | link |
| 1018 | position-below |
| 1019 | data-label="Edit" |
| 1020 | data-action-type="change" |
| 1021 | data-action-key="edit" |
| 1022 | role="button" |
| 1023 | tabindex="0" |
| 1024 | > |
Ben Rohlfs | b1b0ac9 | 2022-08-01 14:33:02 +0200 | [diff] [blame] | 1025 | <div> |
| 1026 | <gr-icon icon="edit" filled small></gr-icon> |
| 1027 | <span>Modify</span> |
| 1028 | </div> |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1029 | </gr-button> |
| 1030 | </gr-tooltip-content> |
| 1031 | </div> |
| 1032 | <div> |
| 1033 | <a |
| 1034 | href="https://gerrit-review.googlesource.com/Documentation/user-attention-set.html" |
| 1035 | target="_blank" |
| 1036 | > |
Chris Poucet | b7e9bb1 | 2022-07-22 14:11:03 +0200 | [diff] [blame] | 1037 | <gr-icon icon="help" title="read documentation"></gr-icon> |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1038 | </a> |
| 1039 | </div> |
| 1040 | </div> |
| 1041 | </section> |
| 1042 | `; |
| 1043 | } |
| 1044 | |
| 1045 | private renderAttentionDetailsSection() { |
| 1046 | if (!this.attentionExpanded) return; |
| 1047 | return html` |
| 1048 | <section class="attention-detail"> |
| 1049 | <div class="attentionDetailsTitle"> |
| 1050 | <div> |
| 1051 | <span>Modify attention to</span> |
| 1052 | </div> |
| 1053 | <div></div> |
| 1054 | <div> |
| 1055 | <a |
| 1056 | href="https://gerrit-review.googlesource.com/Documentation/user-attention-set.html" |
| 1057 | target="_blank" |
| 1058 | > |
Chris Poucet | b7e9bb1 | 2022-07-22 14:11:03 +0200 | [diff] [blame] | 1059 | <gr-icon icon="help" title="read documentation"></gr-icon> |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1060 | </a> |
| 1061 | </div> |
| 1062 | </div> |
| 1063 | <div class="selectUsers"> |
| 1064 | <span |
| 1065 | >Select chips to set who will be in the attention set after sending |
| 1066 | this reply</span |
| 1067 | > |
| 1068 | </div> |
| 1069 | <div class="peopleList"> |
| 1070 | <div class="peopleListLabel">Owner</div> |
| 1071 | <div class="peopleListValues"> |
| 1072 | <gr-account-label |
Dhruv Srivastava | fcb6350 | 2022-07-11 14:42:00 +0200 | [diff] [blame] | 1073 | .account=${this.change?.owner} |
| 1074 | ?forceAttention=${this.computeHasNewAttention(this.change?.owner)} |
| 1075 | .selected=${this.computeHasNewAttention(this.change?.owner)} |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1076 | .hideHovercard=${true} |
| 1077 | .selectionChipStyle=${true} |
| 1078 | @click=${this.handleAttentionClick} |
| 1079 | > |
| 1080 | </gr-account-label> |
| 1081 | </div> |
| 1082 | </div> |
| 1083 | ${when( |
| 1084 | this.uploader, |
| 1085 | () => html` |
| 1086 | <div class="peopleList"> |
| 1087 | <div class="peopleListLabel">Uploader</div> |
| 1088 | <div class="peopleListValues"> |
| 1089 | <gr-account-label |
| 1090 | .account=${this.uploader} |
| 1091 | ?forceAttention=${this.computeHasNewAttention(this.uploader)} |
| 1092 | .selected=${this.computeHasNewAttention(this.uploader)} |
| 1093 | .hideHovercard=${true} |
| 1094 | .selectionChipStyle=${true} |
| 1095 | @click=${this.handleAttentionClick} |
| 1096 | > |
| 1097 | </gr-account-label> |
| 1098 | </div> |
| 1099 | </div> |
| 1100 | ` |
| 1101 | )} |
| 1102 | <div class="peopleList"> |
| 1103 | <div class="peopleListLabel">Reviewers</div> |
| 1104 | <div class="peopleListValues"> |
Dhruv Srivastava | 517a786 | 2022-08-03 14:46:21 +0200 | [diff] [blame] | 1105 | ${removeServiceUsers(this.reviewers).map( |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1106 | account => html` |
| 1107 | <gr-account-label |
| 1108 | .account=${account} |
| 1109 | ?forceAttention=${this.computeHasNewAttention(account)} |
| 1110 | .selected=${this.computeHasNewAttention(account)} |
| 1111 | .hideHovercard=${true} |
| 1112 | .selectionChipStyle=${true} |
| 1113 | @click=${this.handleAttentionClick} |
| 1114 | > |
| 1115 | </gr-account-label> |
| 1116 | ` |
| 1117 | )} |
| 1118 | </div> |
| 1119 | </div> |
| 1120 | |
| 1121 | ${when( |
| 1122 | this.attentionCcsCount, |
| 1123 | () => html` |
| 1124 | <div class="peopleList"> |
| 1125 | <div class="peopleListLabel">CC</div> |
| 1126 | <div class="peopleListValues"> |
Dhruv Srivastava | 517a786 | 2022-08-03 14:46:21 +0200 | [diff] [blame] | 1127 | ${removeServiceUsers(this.ccs).map( |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1128 | account => html` |
| 1129 | <gr-account-label |
| 1130 | .account=${account} |
| 1131 | ?forceAttention=${this.computeHasNewAttention(account)} |
| 1132 | .selected=${this.computeHasNewAttention(account)} |
| 1133 | .hideHovercard=${true} |
| 1134 | .selectionChipStyle=${true} |
| 1135 | @click=${this.handleAttentionClick} |
| 1136 | > |
| 1137 | </gr-account-label> |
| 1138 | ` |
| 1139 | )} |
| 1140 | </div> |
| 1141 | </div> |
| 1142 | ` |
| 1143 | )} |
| 1144 | ${when( |
Dhruv Srivastava | 4a03a14 | 2022-07-11 11:34:50 +0200 | [diff] [blame] | 1145 | this.computeShowAttentionTip(), |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1146 | () => html` |
| 1147 | <div class="attentionTip"> |
Chris Poucet | b7e9bb1 | 2022-07-22 14:11:03 +0200 | [diff] [blame] | 1148 | <gr-icon icon="lightbulb"></gr-icon> |
Dhruv | c22bd65 | 2022-07-04 11:38:30 +0200 | [diff] [blame] | 1149 | Please be mindful of requiring attention from too many users. |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1150 | </div> |
| 1151 | ` |
| 1152 | )} |
| 1153 | </section> |
| 1154 | `; |
| 1155 | } |
| 1156 | |
| 1157 | private renderActionsSection() { |
| 1158 | return html` |
| 1159 | <section class="actions"> |
| 1160 | <div class="left"> |
| 1161 | ${when( |
| 1162 | this.knownLatestState === LatestPatchState.CHECKING, |
| 1163 | () => html` |
| 1164 | <span id="checkingStatusLabel"> |
Paladox none | d1e1617 | 2023-02-22 19:00:06 +0000 | [diff] [blame] | 1165 | Checking whether patch ${this.latestPatchNum} is latest... |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1166 | </span> |
| 1167 | ` |
| 1168 | )} |
| 1169 | ${when( |
| 1170 | this.knownLatestState === LatestPatchState.NOT_LATEST, |
| 1171 | () => html` |
| 1172 | <span id="notLatestLabel"> |
| 1173 | ${this.computePatchSetWarning()} |
| 1174 | <gr-button link @click=${this._reload}>Reload</gr-button> |
| 1175 | </span> |
| 1176 | ` |
| 1177 | )} |
| 1178 | </div> |
| 1179 | <div class="right"> |
| 1180 | <gr-button |
| 1181 | link |
| 1182 | id="cancelButton" |
| 1183 | class="action cancel" |
| 1184 | @click=${this.cancelTapHandler} |
| 1185 | >Cancel</gr-button |
| 1186 | > |
| 1187 | ${when( |
| 1188 | this.canBeStarted, |
| 1189 | () => html` |
| 1190 | <!-- Use 'Send' here as the change may only about reviewers / ccs |
| 1191 | and when this button is visible, the next button will always |
| 1192 | be 'Start review' --> |
| 1193 | <gr-tooltip-content has-tooltip title=${this.saveTooltip}> |
| 1194 | <gr-button |
| 1195 | link |
| 1196 | ?disabled=${this.knownLatestState === |
| 1197 | LatestPatchState.NOT_LATEST} |
| 1198 | class="action save" |
| 1199 | @click=${this.saveClickHandler} |
| 1200 | >Send As WIP</gr-button |
| 1201 | > |
| 1202 | </gr-tooltip-content> |
| 1203 | ` |
| 1204 | )} |
| 1205 | <gr-tooltip-content |
| 1206 | has-tooltip |
| 1207 | title=${this.computeSendButtonTooltip( |
| 1208 | this.canBeStarted, |
| 1209 | this.commentEditing |
| 1210 | )} |
| 1211 | > |
| 1212 | <gr-button |
| 1213 | id="sendButton" |
| 1214 | primary |
| 1215 | ?disabled=${this.sendDisabled} |
| 1216 | class="action send" |
| 1217 | @click=${this.sendTapHandler} |
| 1218 | >${this.sendButtonLabel} |
| 1219 | </gr-button> |
| 1220 | </gr-tooltip-content> |
| 1221 | </div> |
| 1222 | </section> |
| 1223 | `; |
| 1224 | } |
| 1225 | |
Ben Rohlfs | 0004965 | 2021-10-25 16:40:38 +0200 | [diff] [blame] | 1226 | /** |
| 1227 | * Note that this method is not actually *opening* the dialog. Opening and |
| 1228 | * showing the dialog is dealt with by the overlay. This method is used by the |
| 1229 | * change view for initializing the dialog after opening the overlay. Maybe it |
| 1230 | * should be called `onOpened()` or `initialize()`? |
| 1231 | */ |
| 1232 | open(focusTarget?: FocusTarget, quote?: string) { |
Ben Rohlfs | c1c6afd | 2021-02-18 13:13:22 +0100 | [diff] [blame] | 1233 | assertIsDefined(this.change, 'change'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1234 | this.knownLatestState = LatestPatchState.CHECKING; |
Chris Poucet | bf65b8f | 2022-01-18 21:18:12 +0000 | [diff] [blame] | 1235 | this.getChangeModel() |
| 1236 | .fetchChangeUpdates(this.change) |
| 1237 | .then(result => { |
| 1238 | this.knownLatestState = result.isLatest |
| 1239 | ? LatestPatchState.LATEST |
| 1240 | : LatestPatchState.NOT_LATEST; |
| 1241 | }); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1242 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1243 | this.focusOn(focusTarget); |
Ben Rohlfs | 0004965 | 2021-10-25 16:40:38 +0200 | [diff] [blame] | 1244 | if (quote?.length) { |
| 1245 | // If a reply quote has been provided, use it. |
Chris Poucet | afd0f7c | 2022-10-04 10:04:43 +0000 | [diff] [blame] | 1246 | this.patchsetLevelDraftMessage = quote; |
Dmitrii Filippov | 3fd2b10 | 2019-11-15 16:16:46 +0100 | [diff] [blame] | 1247 | } |
Ben Rohlfs | 43935a4 | 2020-12-01 19:14:09 +0100 | [diff] [blame] | 1248 | if (this.restApiService.hasPendingDiffDrafts()) { |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1249 | this.savingComments = true; |
Ben Rohlfs | 43935a4 | 2020-12-01 19:14:09 +0100 | [diff] [blame] | 1250 | this.restApiService.awaitPendingDiffDrafts().then(() => { |
Ben Rohlfs | 44f0104 | 2023-02-18 13:27:57 +0100 | [diff] [blame] | 1251 | fire(this, 'comment-refresh', {}); |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1252 | this.savingComments = false; |
Dmitrii Filippov | b82003c | 2019-11-05 17:02:59 +0100 | [diff] [blame] | 1253 | }); |
Dmitrii Filippov | 3fd2b10 | 2019-11-15 16:16:46 +0100 | [diff] [blame] | 1254 | } |
Dmitrii Filippov | 3fd2b10 | 2019-11-15 16:16:46 +0100 | [diff] [blame] | 1255 | } |
| 1256 | |
Chris Poucet | 54d2abc | 2022-04-28 11:51:35 +0200 | [diff] [blame] | 1257 | hasDrafts() { |
Dhruv Srivastava | 463bb33 | 2022-08-31 13:00:49 +0200 | [diff] [blame] | 1258 | return ( |
Chris Poucet | afd0f7c | 2022-10-04 10:04:43 +0000 | [diff] [blame] | 1259 | this.patchsetLevelDraftMessage.length > 0 || |
Dhruv Srivastava | 463bb33 | 2022-08-31 13:00:49 +0200 | [diff] [blame] | 1260 | this.draftCommentThreads.length > 0 |
| 1261 | ); |
Dhruv Srivastava | 568feec | 2020-10-30 20:05:04 +0100 | [diff] [blame] | 1262 | } |
| 1263 | |
Gerrit Code Review | 09637ae | 2021-08-19 14:34:39 +0000 | [diff] [blame] | 1264 | override focus() { |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1265 | this.focusOn(FocusTarget.ANY); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1266 | } |
| 1267 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1268 | private handleIncludeCommentsChanged(e: Event) { |
| 1269 | if (!(e.target instanceof HTMLInputElement)) return; |
| 1270 | this.includeComments = e.target.checked; |
| 1271 | } |
| 1272 | |
| 1273 | setLabelValue(label: string, value: string): void { |
Frank Borden | c3705eb | 2021-11-29 18:29:11 +0100 | [diff] [blame] | 1274 | const selectorEl = |
| 1275 | this.getLabelScores().shadowRoot?.querySelector<GrLabelScoreRow>( |
| 1276 | `gr-label-score-row[name="${label}"]` |
| 1277 | ); |
| 1278 | selectorEl?.setSelectedValue(value); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1279 | } |
| 1280 | |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1281 | getLabelValue(label: string) { |
Frank Borden | c3705eb | 2021-11-29 18:29:11 +0100 | [diff] [blame] | 1282 | const selectorEl = |
| 1283 | this.getLabelScores().shadowRoot?.querySelector<GrLabelScoreRow>( |
| 1284 | `gr-label-score-row[name="${label}"]` |
| 1285 | ); |
| 1286 | return selectorEl?.selectedValue; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1287 | } |
| 1288 | |
Frank Borden | 7281dbb | 2022-05-16 10:52:54 +0200 | [diff] [blame] | 1289 | // TODO: Combine logic into handleReviewersChanged & handleCCsChanged and |
| 1290 | // remove account-added event from GrAccountList. |
Dhruv Srivastava | db01c60 | 2022-07-18 15:34:34 +0200 | [diff] [blame] | 1291 | handleAccountAdded(e: CustomEvent<AccountInputDetail>) { |
Dhruv | 569d616 | 2022-04-08 10:21:00 +0200 | [diff] [blame] | 1292 | const account = e.detail.account; |
Dhruv Srivastava | a1882db | 2022-08-18 10:16:26 +0200 | [diff] [blame] | 1293 | const key = getUserId(account); |
Dhruv | 569d616 | 2022-04-08 10:21:00 +0200 | [diff] [blame] | 1294 | const reviewerType = |
| 1295 | (e.target as GrAccountList).getAttribute('id') === 'ccs' |
| 1296 | ? ReviewerType.CC |
| 1297 | : ReviewerType.REVIEWER; |
| 1298 | const isReviewer = ReviewerType.REVIEWER === reviewerType; |
Dhruv Srivastava | 31caeec | 2022-08-05 14:39:34 +0200 | [diff] [blame] | 1299 | const reviewerList = isReviewer ? this.ccsList : this.reviewersList; |
| 1300 | // Remove any accounts that already exist as a CC for reviewer |
| 1301 | // or vice versa. |
| 1302 | if (reviewerList?.removeAccount(account)) { |
Dhruv | 569d616 | 2022-04-08 10:21:00 +0200 | [diff] [blame] | 1303 | const moveFrom = isReviewer ? 'CC' : 'reviewer'; |
| 1304 | const moveTo = isReviewer ? 'reviewer' : 'CC'; |
| 1305 | const id = account.name || key; |
| 1306 | const message = `${id} moved from ${moveFrom} to ${moveTo}.`; |
| 1307 | fireAlert(this, message); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1308 | } |
| 1309 | } |
| 1310 | |
Dhruv Srivastava | 463bb33 | 2022-08-31 13:00:49 +0200 | [diff] [blame] | 1311 | getUnresolvedPatchsetLevelClass(patchsetLevelDraftIsResolved: boolean) { |
| 1312 | return patchsetLevelDraftIsResolved ? 'resolved' : 'unresolved'; |
Dhruv Srivastava | 5dbf467 | 2021-06-29 09:06:20 +0200 | [diff] [blame] | 1313 | } |
| 1314 | |
Dhruv Srivastava | 82f6b20 | 2022-08-03 15:22:20 +0200 | [diff] [blame] | 1315 | computeReviewers() { |
Dhruv Srivastava | 88ff8ac | 2021-07-02 16:23:04 +0200 | [diff] [blame] | 1316 | const reviewers: ReviewerInput[] = []; |
Dhruv Srivastava | 4a9892e | 2022-08-03 17:27:18 +0200 | [diff] [blame] | 1317 | const reviewerAdditions = this.reviewersList?.additions() ?? []; |
| 1318 | reviewers.push( |
| 1319 | ...reviewerAdditions.map(v => toReviewInput(v, ReviewerState.REVIEWER)) |
| 1320 | ); |
Dhruv Srivastava | 82f6b20 | 2022-08-03 15:22:20 +0200 | [diff] [blame] | 1321 | |
Dhruv Srivastava | 4a9892e | 2022-08-03 17:27:18 +0200 | [diff] [blame] | 1322 | const ccAdditions = this.ccsList?.additions() ?? []; |
| 1323 | reviewers.push(...ccAdditions.map(v => toReviewInput(v, ReviewerState.CC))); |
| 1324 | |
| 1325 | // ignore removal from reviewer request if being added as CC |
| 1326 | let removals = difference( |
| 1327 | this.reviewersList?.removals() ?? [], |
| 1328 | ccAdditions, |
Dhruv Srivastava | a1882db | 2022-08-18 10:16:26 +0200 | [diff] [blame] | 1329 | (a, b) => getUserId(a) === getUserId(b) |
Dhruv Srivastava | 4a9892e | 2022-08-03 17:27:18 +0200 | [diff] [blame] | 1330 | ).map(v => toReviewInput(v, ReviewerState.REMOVED)); |
Dhruv Srivastava | 82f6b20 | 2022-08-03 15:22:20 +0200 | [diff] [blame] | 1331 | reviewers.push(...removals); |
| 1332 | |
Dhruv Srivastava | 4a9892e | 2022-08-03 17:27:18 +0200 | [diff] [blame] | 1333 | // ignore removal from CC request if being added as reviewer |
| 1334 | removals = difference( |
| 1335 | this.ccsList?.removals() ?? [], |
| 1336 | reviewerAdditions, |
Dhruv Srivastava | a1882db | 2022-08-18 10:16:26 +0200 | [diff] [blame] | 1337 | (a, b) => getUserId(a) === getUserId(b) |
Dhruv Srivastava | 4a9892e | 2022-08-03 17:27:18 +0200 | [diff] [blame] | 1338 | ).map(v => toReviewInput(v, ReviewerState.REMOVED)); |
Dhruv Srivastava | 82f6b20 | 2022-08-03 15:22:20 +0200 | [diff] [blame] | 1339 | reviewers.push(...removals); |
| 1340 | |
Dhruv Srivastava | ca3d495 | 2022-08-08 20:58:04 +0200 | [diff] [blame] | 1341 | // The owner is returned as a reviewer in the ChangeInfo object in some |
| 1342 | // cases, and trying to remove the owner as a reviewer returns in a |
| 1343 | // 500 server error. |
| 1344 | return reviewers.filter( |
| 1345 | reviewerInput => |
| 1346 | !( |
| 1347 | this.change?.owner._account_id === reviewerInput.reviewer && |
| 1348 | reviewerInput.state === ReviewerState.REMOVED |
| 1349 | ) |
| 1350 | ); |
Dhruv Srivastava | 88ff8ac | 2021-07-02 16:23:04 +0200 | [diff] [blame] | 1351 | } |
| 1352 | |
Dhruv Srivastava | 8bdda3b | 2022-08-30 19:11:31 +0200 | [diff] [blame] | 1353 | async send(includeComments: boolean, startReview: boolean) { |
Milutin Kristofic | 48a0f43 | 2021-03-16 22:53:08 +0100 | [diff] [blame] | 1354 | this.reporting.time(Timing.SEND_REPLY); |
Dhruv Srivastava | 5dbf467 | 2021-06-29 09:06:20 +0200 | [diff] [blame] | 1355 | const labels = this.getLabelScores().getLabelValues(); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1356 | |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1357 | const reviewInput: ReviewInput = { |
| 1358 | drafts: includeComments |
| 1359 | ? DraftsAction.PUBLISH_ALL_REVISIONS |
| 1360 | : DraftsAction.KEEP, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1361 | labels, |
| 1362 | }; |
| 1363 | |
| 1364 | if (startReview) { |
Dmitrii Filippov | 50aa4c2 | 2020-03-18 16:05:11 +0100 | [diff] [blame] | 1365 | reviewInput.ready = true; |
Dhruv Srivastava | f970bf1 | 2022-11-28 14:35:23 +0100 | [diff] [blame] | 1366 | } else if (this.change?.work_in_progress) { |
Dhruv Srivastava | 753895c | 2022-11-26 00:30:23 +0530 | [diff] [blame] | 1367 | const addedAccounts = [ |
| 1368 | ...(this.reviewersList?.additions() ?? []), |
| 1369 | ...(this.ccsList?.additions() ?? []), |
| 1370 | ]; |
| 1371 | if (addedAccounts.length > 0) { |
| 1372 | fireAlert(this, 'Reviewers are not notified for WIP changes'); |
| 1373 | } |
Dmitrii Filippov | 50aa4c2 | 2020-03-18 16:05:11 +0100 | [diff] [blame] | 1374 | } |
| 1375 | |
Dhruv Srivastava | 8bdda3b | 2022-08-30 19:11:31 +0200 | [diff] [blame] | 1376 | this.disabled = true; |
| 1377 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1378 | const reason = getReplyByReason(this.account, this.serverConfig); |
Ben Rohlfs | 1af9ec3 | 2020-08-26 12:51:06 +0200 | [diff] [blame] | 1379 | |
David Ostrovsky | 954e508 | 2021-05-05 12:28:13 +0200 | [diff] [blame] | 1380 | reviewInput.ignore_automatic_attention_set_rules = true; |
| 1381 | reviewInput.add_to_attention_set = []; |
Dhruv Srivastava | 71007ec | 2022-09-09 09:03:42 +0200 | [diff] [blame] | 1382 | const allAccounts = this.allAccounts(); |
| 1383 | |
| 1384 | const newAttentionSetAdditions: AccountInfo[] = Array.from( |
| 1385 | this.newAttentionSet |
| 1386 | ) |
| 1387 | .filter(user => !this.currentAttentionSet.has(user)) |
| 1388 | .map(user => allAccounts.find(a => getUserId(a) === user)) |
Ben Rohlfs | 9b2f740 | 2022-10-17 12:40:31 +0200 | [diff] [blame] | 1389 | .filter(isDefined); |
Dhruv Srivastava | 71007ec | 2022-09-09 09:03:42 +0200 | [diff] [blame] | 1390 | |
| 1391 | const newAttentionSetUsers = ( |
| 1392 | await Promise.all( |
Chris Poucet | 4ed2c5d | 2022-10-24 22:28:15 +0200 | [diff] [blame] | 1393 | newAttentionSetAdditions.map(a => |
| 1394 | this.getAccountsModel().fillDetails(a) |
| 1395 | ) |
Dhruv Srivastava | 71007ec | 2022-09-09 09:03:42 +0200 | [diff] [blame] | 1396 | ) |
Ben Rohlfs | 9b2f740 | 2022-10-17 12:40:31 +0200 | [diff] [blame] | 1397 | ).filter(isDefined); |
Dhruv Srivastava | 71007ec | 2022-09-09 09:03:42 +0200 | [diff] [blame] | 1398 | |
| 1399 | for (const user of newAttentionSetUsers) { |
Ben Rohlfs | b7082e1 | 2023-01-23 11:43:48 +0100 | [diff] [blame] | 1400 | const reason = |
| 1401 | getMentionedReason( |
| 1402 | this.draftCommentThreads, |
| 1403 | this.account, |
| 1404 | user, |
| 1405 | this.serverConfig |
| 1406 | ) ?? ''; |
Dhruv Srivastava | 71007ec | 2022-09-09 09:03:42 +0200 | [diff] [blame] | 1407 | reviewInput.add_to_attention_set.push({user: getUserId(user), reason}); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1408 | } |
David Ostrovsky | 954e508 | 2021-05-05 12:28:13 +0200 | [diff] [blame] | 1409 | reviewInput.remove_from_attention_set = []; |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1410 | for (const user of this.currentAttentionSet) { |
| 1411 | if (!this.newAttentionSet.has(user)) { |
David Ostrovsky | 954e508 | 2021-05-05 12:28:13 +0200 | [diff] [blame] | 1412 | reviewInput.remove_from_attention_set.push({user, reason}); |
| 1413 | } |
| 1414 | } |
| 1415 | this.reportAttentionSetChanges( |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1416 | this.attentionExpanded, |
David Ostrovsky | 954e508 | 2021-05-05 12:28:13 +0200 | [diff] [blame] | 1417 | reviewInput.add_to_attention_set, |
| 1418 | reviewInput.remove_from_attention_set |
| 1419 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1420 | |
Dhruv Srivastava | e8b8639 | 2022-10-20 17:17:21 +0200 | [diff] [blame] | 1421 | await this.patchsetLevelGrComment?.save(); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1422 | |
Dhruv Srivastava | 012e36a | 2021-05-14 12:09:44 +0200 | [diff] [blame] | 1423 | assertIsDefined(this.change, 'change'); |
Dhruv Srivastava | 82f6b20 | 2022-08-03 15:22:20 +0200 | [diff] [blame] | 1424 | reviewInput.reviewers = this.computeReviewers(); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1425 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1426 | const errFn = (r?: Response | null) => this.handle400Error(r); |
| 1427 | return this.saveReview(reviewInput, errFn) |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1428 | .then(response => { |
| 1429 | if (!response) { |
| 1430 | // Null or undefined response indicates that an error handler |
| 1431 | // took responsibility, so just return. |
Dhruv Srivastava | 57ae747 | 2021-05-05 11:42:03 +0200 | [diff] [blame] | 1432 | return; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1433 | } |
| 1434 | if (!response.ok) { |
Ben Rohlfs | ea4cb7e | 2020-12-03 16:00:00 +0100 | [diff] [blame] | 1435 | fireServerError(response); |
Dhruv Srivastava | 57ae747 | 2021-05-05 11:42:03 +0200 | [diff] [blame] | 1436 | return; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1437 | } |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1438 | |
Chris Poucet | afd0f7c | 2022-10-04 10:04:43 +0000 | [diff] [blame] | 1439 | this.patchsetLevelDraftMessage = ''; |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1440 | this.includeComments = true; |
Ben Rohlfs | 44f0104 | 2023-02-18 13:27:57 +0100 | [diff] [blame] | 1441 | fireNoBubble(this, 'send', {}); |
Ben Rohlfs | 62278c8 | 2021-03-12 11:35:56 +0100 | [diff] [blame] | 1442 | fireIronAnnounce(this, 'Reply sent'); |
Dhruv Srivastava | 57ae747 | 2021-05-05 11:42:03 +0200 | [diff] [blame] | 1443 | return; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1444 | }) |
| 1445 | .then(result => { |
| 1446 | this.disabled = false; |
| 1447 | return result; |
| 1448 | }) |
| 1449 | .catch(err => { |
| 1450 | this.disabled = false; |
| 1451 | throw err; |
| 1452 | }); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1453 | } |
| 1454 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1455 | focusOn(section?: FocusTarget) { |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1456 | // Safeguard- always want to focus on something. |
| 1457 | if (!section || section === FocusTarget.ANY) { |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1458 | section = this.chooseFocusTarget(); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1459 | } |
Dhruv Srivastava | 51b7009 | 2022-10-20 15:26:12 +0200 | [diff] [blame] | 1460 | whenVisible(this, () => { |
| 1461 | if (section === FocusTarget.REVIEWERS) { |
| 1462 | const reviewerEntry = this.reviewersList?.focusStart; |
| 1463 | reviewerEntry?.focus(); |
| 1464 | } else if (section === FocusTarget.CCS) { |
| 1465 | const ccEntry = this.ccsList?.focusStart; |
| 1466 | ccEntry?.focus(); |
Dhruv Srivastava | e8b8639 | 2022-10-20 17:17:21 +0200 | [diff] [blame] | 1467 | } else { |
| 1468 | this.patchsetLevelGrComment?.focus(); |
Dhruv Srivastava | 51b7009 | 2022-10-20 15:26:12 +0200 | [diff] [blame] | 1469 | } |
| 1470 | }); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1471 | } |
| 1472 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1473 | chooseFocusTarget() { |
Ben Rohlfs | ead9366 | 2022-08-05 09:09:15 +0200 | [diff] [blame] | 1474 | if (!isOwner(this.change, this.account)) return FocusTarget.BODY; |
| 1475 | if (hasHumanReviewer(this.change)) return FocusTarget.BODY; |
| 1476 | return FocusTarget.REVIEWERS; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1477 | } |
| 1478 | |
Dhruv Srivastava | ed17395 | 2022-08-08 09:37:36 +0200 | [diff] [blame] | 1479 | isOwner(account?: AccountInfo, change?: ParsedChangeInfo | ChangeInfo) { |
Dmitrii Filippov | 50aa4c2 | 2020-03-18 16:05:11 +0100 | [diff] [blame] | 1480 | if (!account || !change || !change.owner) return false; |
| 1481 | return account._account_id === change.owner._account_id; |
| 1482 | } |
| 1483 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1484 | handle400Error(r?: Response | null) { |
David Ostrovsky | f91f966 | 2021-02-22 19:34:37 +0100 | [diff] [blame] | 1485 | if (!r) throw new Error('Response is empty.'); |
Ben Rohlfs | ea4cb7e | 2020-12-03 16:00:00 +0100 | [diff] [blame] | 1486 | let response: Response = r; |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1487 | // A call to saveReview could fail with a server error if erroneous |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1488 | // reviewers were requested. This is signalled with a 400 Bad Request |
Ben Rohlfs | 9ead541 | 2021-01-22 22:11:36 +0100 | [diff] [blame] | 1489 | // status. The default gr-rest-api error handling would result in a large |
| 1490 | // JSON response body being displayed to the user in the gr-error-manager |
| 1491 | // toast. |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1492 | // |
| 1493 | // We can modify the error handling behavior by passing this function |
| 1494 | // through to restAPI as a custom error handling function. Since we're |
| 1495 | // short-circuiting restAPI we can do our own response parsing and fire |
| 1496 | // the server-error ourselves. |
| 1497 | // |
| 1498 | this.disabled = false; |
| 1499 | |
| 1500 | // Using response.clone() here, because getResponseObject() and |
| 1501 | // potentially the generic error handler will want to call text() on the |
| 1502 | // response object, which can only be done once per object. |
Ben Rohlfs | 43935a4 | 2020-12-01 19:14:09 +0100 | [diff] [blame] | 1503 | const jsonPromise = this.restApiService.getResponseObject(response.clone()); |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1504 | return jsonPromise.then((parsed: ParsedJSON) => { |
| 1505 | const result = parsed as ReviewResult; |
Frank Borden | de52af0 | 2022-05-12 10:14:14 +0200 | [diff] [blame] | 1506 | // Only perform custom error handling for 400s and a parsable |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1507 | // ReviewResult response. |
Ben Rohlfs | ea4cb7e | 2020-12-03 16:00:00 +0100 | [diff] [blame] | 1508 | if (response.status === 400 && result && result.reviewers) { |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1509 | const errors: string[] = []; |
| 1510 | const addReviewers = Object.values(result.reviewers); |
| 1511 | addReviewers.forEach(r => errors.push(r.error ?? 'no explanation')); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1512 | response = { |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1513 | ...response, |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1514 | ok: false, |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1515 | text: () => Promise.resolve(errors.join(', ')), |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1516 | }; |
| 1517 | } |
Ben Rohlfs | ea4cb7e | 2020-12-03 16:00:00 +0100 | [diff] [blame] | 1518 | fireServerError(response); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1519 | }); |
| 1520 | } |
| 1521 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1522 | computeHideDraftList(draftCommentThreads?: CommentThread[]) { |
Ben Rohlfs | 3cf22a7 | 2020-06-02 13:47:52 +0200 | [diff] [blame] | 1523 | return !draftCommentThreads || draftCommentThreads.length === 0; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1524 | } |
| 1525 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1526 | computeDraftsTitle(draftCommentThreads?: CommentThread[]) { |
Ben Rohlfs | 3cf22a7 | 2020-06-02 13:47:52 +0200 | [diff] [blame] | 1527 | const total = draftCommentThreads ? draftCommentThreads.length : 0; |
Milutin Kristofic | 5b3f087 | 2020-12-05 22:08:09 +0100 | [diff] [blame] | 1528 | return pluralize(total, 'Draft'); |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1529 | } |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1530 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1531 | computeMessagePlaceholder() { |
| 1532 | this.messagePlaceholder = this.canBeStarted |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1533 | ? 'Add a note for your reviewers...' |
| 1534 | : 'Say something nice...'; |
| 1535 | } |
| 1536 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1537 | rebuildReviewerArrays() { |
| 1538 | if (!this.change?.owner || !this.change?.reviewers) return; |
Dhruv Srivastava | ed17395 | 2022-08-08 09:37:36 +0200 | [diff] [blame] | 1539 | const getAccounts = (state: ReviewerState) => |
| 1540 | Object.values(this.change?.reviewers[state] ?? []).filter( |
| 1541 | account => account._account_id !== this.change!.owner._account_id |
| 1542 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1543 | |
Dhruv Srivastava | ed17395 | 2022-08-08 09:37:36 +0200 | [diff] [blame] | 1544 | this.ccs = getAccounts(ReviewerState.CC); |
| 1545 | this.reviewers = getAccounts(ReviewerState.REVIEWER); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1546 | } |
| 1547 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1548 | handleAttentionModify() { |
| 1549 | this.attentionExpanded = true; |
Ben Rohlfs | 6a0a107 | 2020-10-16 15:01:34 +0200 | [diff] [blame] | 1550 | } |
| 1551 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1552 | onAttentionExpandedChange() { |
Ben Rohlfs | 91675d7 | 2020-07-24 09:55:54 +0200 | [diff] [blame] | 1553 | // If the attention-detail section is expanded without dispatching this |
| 1554 | // event, then the dialog may expand beyond the screen's bottom border. |
Ben Rohlfs | 44f0104 | 2023-02-18 13:27:57 +0100 | [diff] [blame] | 1555 | fire(this, 'iron-resize', {}); |
Dmitrii Filippov | 50aa4c2 | 2020-03-18 16:05:11 +0100 | [diff] [blame] | 1556 | } |
| 1557 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1558 | computeAttentionButtonTitle(sendDisabled?: boolean) { |
Ben Rohlfs | 43f8e5f | 2020-10-09 10:36:29 +0200 | [diff] [blame] | 1559 | return sendDisabled |
| 1560 | ? 'Modify the attention set by adding a comment or use the account ' + |
| 1561 | 'hovercard in the change page.' |
| 1562 | : 'Edit attention set changes'; |
| 1563 | } |
| 1564 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1565 | handleAttentionClick(e: Event) { |
Dhruv Srivastava | 7f77a61 | 2022-08-17 11:38:03 +0200 | [diff] [blame] | 1566 | const targetAccount = (e.target as GrAccountChip)?.account; |
| 1567 | if (!targetAccount) return; |
Dhruv Srivastava | 462eb39 | 2022-08-18 10:42:11 +0200 | [diff] [blame] | 1568 | const id = getUserId(targetAccount); |
Dhruv Srivastava | 7f77a61 | 2022-08-17 11:38:03 +0200 | [diff] [blame] | 1569 | if (!id || !this.account || !this.change?.owner) return; |
Ben Rohlfs | 1af9ec3 | 2020-08-26 12:51:06 +0200 | [diff] [blame] | 1570 | |
Dhruv Srivastava | a1882db | 2022-08-18 10:16:26 +0200 | [diff] [blame] | 1571 | const self = id === getUserId(this.account) ? '_SELF' : ''; |
| 1572 | const role = id === getUserId(this.change.owner) ? 'OWNER' : '_REVIEWER'; |
Ben Rohlfs | 1af9ec3 | 2020-08-26 12:51:06 +0200 | [diff] [blame] | 1573 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1574 | if (this.newAttentionSet.has(id)) { |
| 1575 | this.newAttentionSet.delete(id); |
Milutin Kristofic | a7c24c1 | 2021-06-07 23:09:26 +0200 | [diff] [blame] | 1576 | this.reporting.reportInteraction(Interaction.ATTENTION_SET_CHIP, { |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1577 | action: `REMOVE${self}${role}`, |
| 1578 | }); |
Dmitrii Filippov | 50aa4c2 | 2020-03-18 16:05:11 +0100 | [diff] [blame] | 1579 | } else { |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1580 | this.newAttentionSet.add(id); |
Milutin Kristofic | a7c24c1 | 2021-06-07 23:09:26 +0200 | [diff] [blame] | 1581 | this.reporting.reportInteraction(Interaction.ATTENTION_SET_CHIP, { |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1582 | action: `ADD${self}${role}`, |
| 1583 | }); |
Dmitrii Filippov | 50aa4c2 | 2020-03-18 16:05:11 +0100 | [diff] [blame] | 1584 | } |
Ben Rohlfs | 1af9ec3 | 2020-08-26 12:51:06 +0200 | [diff] [blame] | 1585 | |
Dhruv Srivastava | 7a096c0 | 2022-07-11 10:22:51 +0200 | [diff] [blame] | 1586 | this.requestUpdate(); |
Dmitrii Filippov | 50aa4c2 | 2020-03-18 16:05:11 +0100 | [diff] [blame] | 1587 | } |
| 1588 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1589 | computeHasNewAttention(account?: AccountInfo) { |
Dhruv Srivastava | 664cbb8 | 2022-09-19 11:43:27 +0200 | [diff] [blame] | 1590 | return !!(account && this.newAttentionSet?.has(getUserId(account))); |
Dmitrii Filippov | 50aa4c2 | 2020-03-18 16:05:11 +0100 | [diff] [blame] | 1591 | } |
| 1592 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1593 | computeNewAttention() { |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1594 | if ( |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1595 | this.account?._account_id === undefined || |
| 1596 | this.change === undefined || |
Dhruv Srivastava | 11d44e4 | 2022-08-30 14:29:22 +0200 | [diff] [blame] | 1597 | this.includeComments === undefined |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1598 | ) { |
Dmitrii Filippov | 50aa4c2 | 2020-03-18 16:05:11 +0100 | [diff] [blame] | 1599 | return; |
| 1600 | } |
Ben Rohlfs | 31825d8 | 2020-10-02 18:08:04 +0200 | [diff] [blame] | 1601 | // The draft comments are only relevant for the attention set as long as the |
| 1602 | // user actually plans to publish their drafts. |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1603 | const draftCommentThreads = this.includeComments |
| 1604 | ? this.draftCommentThreads |
| 1605 | : []; |
| 1606 | const hasVote = !!this.labelsChanged; |
| 1607 | const isOwner = this.isOwner(this.account, this.change); |
| 1608 | const isUploader = this.uploader?._account_id === this.account._account_id; |
Dhruv Srivastava | db01c60 | 2022-07-18 15:34:34 +0200 | [diff] [blame] | 1609 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1610 | this.attentionCcsCount = removeServiceUsers(this.ccs).length; |
| 1611 | this.currentAttentionSet = new Set( |
| 1612 | Object.keys(this.change.attention_set || {}).map( |
| 1613 | id => Number(id) as AccountId |
| 1614 | ) |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1615 | ); |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1616 | const newAttention = new Set(this.currentAttentionSet); |
Dhruv Srivastava | db01c60 | 2022-07-18 15:34:34 +0200 | [diff] [blame] | 1617 | |
| 1618 | for (const user of this.mentionedUsersInUnresolvedDrafts) { |
Dhruv Srivastava | 664cbb8 | 2022-09-19 11:43:27 +0200 | [diff] [blame] | 1619 | newAttention.add(getUserId(user)); |
Dhruv Srivastava | db01c60 | 2022-07-18 15:34:34 +0200 | [diff] [blame] | 1620 | } |
| 1621 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1622 | if (this.change.status === ChangeStatus.NEW) { |
Ben Rohlfs | f8f0fa8 | 2020-08-11 16:18:58 +0200 | [diff] [blame] | 1623 | // Add everyone that the user is replying to in a comment thread. |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1624 | this.computeCommentAccounts(draftCommentThreads).forEach(id => |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1625 | newAttention.add(id) |
Ben Rohlfs | f8f0fa8 | 2020-08-11 16:18:58 +0200 | [diff] [blame] | 1626 | ); |
| 1627 | // Remove the current user. |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1628 | newAttention.delete(this.account._account_id); |
Ben Rohlfs | 834b591 | 2020-10-13 16:52:24 +0200 | [diff] [blame] | 1629 | // Add all new reviewers, but not the current reviewer, if they are also |
| 1630 | // sending a draft or a label vote. |
| 1631 | const notIsReviewerAndHasDraftOrLabel = (r: AccountInfo) => |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1632 | !( |
| 1633 | r._account_id === this.account!._account_id && |
Chris Poucet | 54d2abc | 2022-04-28 11:51:35 +0200 | [diff] [blame] | 1634 | (this.hasDrafts() || hasVote) |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1635 | ); |
| 1636 | this.reviewers |
| 1637 | .filter(r => isAccount(r)) |
Dhruv Srivastava | 4a9892e | 2022-08-03 17:27:18 +0200 | [diff] [blame] | 1638 | .filter( |
| 1639 | r => |
| 1640 | isAccountNewlyAdded(r, ReviewerState.REVIEWER, this.change) || |
| 1641 | (this.canBeStarted && isOwner) |
| 1642 | ) |
Ben Rohlfs | 834b591 | 2020-10-13 16:52:24 +0200 | [diff] [blame] | 1643 | .filter(notIsReviewerAndHasDraftOrLabel) |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1644 | .forEach(r => newAttention.add((r as AccountInfo)._account_id!)); |
Ben Rohlfs | 834b591 | 2020-10-13 16:52:24 +0200 | [diff] [blame] | 1645 | // Add owner and uploader, if someone else replies. |
Chris Poucet | 54d2abc | 2022-04-28 11:51:35 +0200 | [diff] [blame] | 1646 | if (this.hasDrafts() || hasVote) { |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1647 | if (this.uploader?._account_id && !isUploader) { |
| 1648 | newAttention.add(this.uploader._account_id); |
Ben Rohlfs | 834b591 | 2020-10-13 16:52:24 +0200 | [diff] [blame] | 1649 | } |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1650 | if (this.change.owner?._account_id && !isOwner) { |
| 1651 | newAttention.add(this.change.owner._account_id); |
Ben Rohlfs | f8f0fa8 | 2020-08-11 16:18:58 +0200 | [diff] [blame] | 1652 | } |
| 1653 | } |
| 1654 | } else { |
| 1655 | // The only reason for adding someone to the attention set for merged or |
Ben Rohlfs | 31825d8 | 2020-10-02 18:08:04 +0200 | [diff] [blame] | 1656 | // abandoned changes is that someone makes a comment thread unresolved. |
| 1657 | const hasUnresolvedDraft = draftCommentThreads.some(isUnresolved); |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1658 | if (this.change.owner && hasUnresolvedDraft) { |
| 1659 | // A change owner must have an account_id. |
| 1660 | newAttention.add(this.change.owner._account_id!); |
Dmitrii Filippov | 50aa4c2 | 2020-03-18 16:05:11 +0100 | [diff] [blame] | 1661 | } |
Ben Rohlfs | f8f0fa8 | 2020-08-11 16:18:58 +0200 | [diff] [blame] | 1662 | // Remove the current user. |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1663 | newAttention.delete(this.account._account_id); |
Dmitrii Filippov | 50aa4c2 | 2020-03-18 16:05:11 +0100 | [diff] [blame] | 1664 | } |
Ben Rohlfs | 116ca52 | 2020-07-28 16:50:45 +0200 | [diff] [blame] | 1665 | // Finally make sure that everyone in the attention set is still active as |
| 1666 | // owner, reviewer or cc. |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1667 | const allAccountIds = this.allAccounts() |
Dhruv Srivastava | 462eb39 | 2022-08-18 10:42:11 +0200 | [diff] [blame] | 1668 | .map(a => getUserId(a)) |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1669 | .filter(id => !!id); |
Dhruv Srivastava | db01c60 | 2022-07-18 15:34:34 +0200 | [diff] [blame] | 1670 | this.newAttentionSet = new Set([ |
| 1671 | ...[...newAttention].filter(id => allAccountIds.includes(id)), |
| 1672 | ]); |
| 1673 | |
Dhruv Srivastava | 4a03a14 | 2022-07-11 11:34:50 +0200 | [diff] [blame] | 1674 | this.attentionExpanded = this.computeShowAttentionTip(); |
Ben Rohlfs | 0a4705a | 2020-09-30 13:39:15 +0200 | [diff] [blame] | 1675 | } |
| 1676 | |
Dhruv Srivastava | 4a03a14 | 2022-07-11 11:34:50 +0200 | [diff] [blame] | 1677 | computeShowAttentionTip() { |
| 1678 | if ( |
| 1679 | !this.account || |
Dhruv Srivastava | fcb6350 | 2022-07-11 14:42:00 +0200 | [diff] [blame] | 1680 | !this.change?.owner || |
Dhruv Srivastava | 4a03a14 | 2022-07-11 11:34:50 +0200 | [diff] [blame] | 1681 | !this.currentAttentionSet || |
| 1682 | !this.newAttentionSet |
| 1683 | ) |
Ben Rohlfs | 0a4705a | 2020-09-30 13:39:15 +0200 | [diff] [blame] | 1684 | return false; |
Dhruv Srivastava | fcb6350 | 2022-07-11 14:42:00 +0200 | [diff] [blame] | 1685 | const isOwner = this.account._account_id === this.change.owner._account_id; |
Dhruv Srivastava | 4a03a14 | 2022-07-11 11:34:50 +0200 | [diff] [blame] | 1686 | const addedIds = [...this.newAttentionSet].filter( |
| 1687 | id => !this.currentAttentionSet.has(id) |
Ben Rohlfs | 0a4705a | 2020-09-30 13:39:15 +0200 | [diff] [blame] | 1688 | ); |
| 1689 | return isOwner && addedIds.length > 2; |
Ben Rohlfs | 116ca52 | 2020-07-28 16:50:45 +0200 | [diff] [blame] | 1690 | } |
| 1691 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1692 | computeCommentAccounts(threads: CommentThread[]) { |
Milutin Kristofic | bd44580 | 2021-10-20 21:00:21 +0200 | [diff] [blame] | 1693 | const crLabel = this.change?.labels?.[StandardLabels.CODE_REVIEW]; |
Ben Rohlfs | 31825d8 | 2020-10-02 18:08:04 +0200 | [diff] [blame] | 1694 | const maxCrVoteAccountIds = getMaxAccounts(crLabel).map(a => a._account_id); |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1695 | const accountIds = new Set<AccountId>(); |
Ben Rohlfs | 116ca52 | 2020-07-28 16:50:45 +0200 | [diff] [blame] | 1696 | threads.forEach(thread => { |
Ben Rohlfs | 31825d8 | 2020-10-02 18:08:04 +0200 | [diff] [blame] | 1697 | const unresolved = isUnresolved(thread); |
Ben Rohlfs | 116ca52 | 2020-07-28 16:50:45 +0200 | [diff] [blame] | 1698 | thread.comments.forEach(comment => { |
| 1699 | if (comment.author) { |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1700 | // A comment author must have an account_id. |
Ben Rohlfs | 31825d8 | 2020-10-02 18:08:04 +0200 | [diff] [blame] | 1701 | const authorId = comment.author._account_id!; |
| 1702 | const hasGivenMaxReviewVote = maxCrVoteAccountIds.includes(authorId); |
| 1703 | if (unresolved || !hasGivenMaxReviewVote) accountIds.add(authorId); |
Ben Rohlfs | 116ca52 | 2020-07-28 16:50:45 +0200 | [diff] [blame] | 1704 | } |
| 1705 | }); |
| 1706 | }); |
| 1707 | return accountIds; |
Dmitrii Filippov | 50aa4c2 | 2020-03-18 16:05:11 +0100 | [diff] [blame] | 1708 | } |
| 1709 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1710 | computeShowNoAttentionUpdate() { |
| 1711 | return this.sendDisabled || this.computeNewAttentionAccounts().length === 0; |
Ben Rohlfs | 91675d7 | 2020-07-24 09:55:54 +0200 | [diff] [blame] | 1712 | } |
| 1713 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1714 | computeDoNotUpdateMessage() { |
| 1715 | if (!this.currentAttentionSet || !this.newAttentionSet) return ''; |
| 1716 | if ( |
| 1717 | this.sendDisabled || |
| 1718 | areSetsEqual(this.currentAttentionSet, this.newAttentionSet) |
| 1719 | ) { |
Ben Rohlfs | d6a4766 | 2020-10-01 14:42:47 +0200 | [diff] [blame] | 1720 | return 'No changes to the attention set.'; |
| 1721 | } |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1722 | if (containsAll(this.currentAttentionSet, this.newAttentionSet)) { |
Ben Rohlfs | d6a4766 | 2020-10-01 14:42:47 +0200 | [diff] [blame] | 1723 | return 'No additions to the attention set.'; |
| 1724 | } |
Milutin Kristofic | 380b9f6 | 2020-12-03 09:24:17 +0100 | [diff] [blame] | 1725 | this.reporting.error( |
Kamil Musin | f0ece02 | 2022-10-14 15:22:44 +0200 | [diff] [blame] | 1726 | 'computeDoNotUpdateMessage', |
Milutin Kristofic | 380b9f6 | 2020-12-03 09:24:17 +0100 | [diff] [blame] | 1727 | new Error( |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1728 | 'computeDoNotUpdateMessage()' + |
Milutin Kristofic | 380b9f6 | 2020-12-03 09:24:17 +0100 | [diff] [blame] | 1729 | 'should not be called when users were added to the attention set.' |
| 1730 | ) |
Ben Rohlfs | d6a4766 | 2020-10-01 14:42:47 +0200 | [diff] [blame] | 1731 | ); |
| 1732 | return ''; |
| 1733 | } |
| 1734 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1735 | computeNewAttentionAccounts(): AccountInfo[] { |
| 1736 | if ( |
| 1737 | this.currentAttentionSet === undefined || |
| 1738 | this.newAttentionSet === undefined |
| 1739 | ) { |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1740 | return []; |
| 1741 | } |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1742 | return [...this.newAttentionSet] |
| 1743 | .filter(id => !this.currentAttentionSet.has(id)) |
| 1744 | .map(id => this.findAccountById(id)) |
| 1745 | .filter(account => !!account) as AccountInfo[]; |
Ben Rohlfs | 91675d7 | 2020-07-24 09:55:54 +0200 | [diff] [blame] | 1746 | } |
| 1747 | |
Dhruv Srivastava | 462eb39 | 2022-08-18 10:42:11 +0200 | [diff] [blame] | 1748 | findAccountById(userId: UserId) { |
Dhruv Srivastava | 664cbb8 | 2022-09-19 11:43:27 +0200 | [diff] [blame] | 1749 | return this.allAccounts().find(r => getUserId(r) === userId); |
Ben Rohlfs | 116ca52 | 2020-07-28 16:50:45 +0200 | [diff] [blame] | 1750 | } |
| 1751 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1752 | allAccounts() { |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1753 | let allAccounts: (AccountInfoInput | GroupInfoInput)[] = []; |
Ben Rohlfs | 91675d7 | 2020-07-24 09:55:54 +0200 | [diff] [blame] | 1754 | if (this.change && this.change.owner) allAccounts.push(this.change.owner); |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1755 | if (this.uploader) allAccounts.push(this.uploader); |
| 1756 | if (this.reviewers) allAccounts = [...allAccounts, ...this.reviewers]; |
| 1757 | if (this.ccs) allAccounts = [...allAccounts, ...this.ccs]; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1758 | return removeServiceUsers(allAccounts.filter(isAccount)); |
Ben Rohlfs | 417a3fd | 2020-08-11 16:53:20 +0200 | [diff] [blame] | 1759 | } |
| 1760 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1761 | computeUploader() { |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1762 | if ( |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1763 | !this.change?.current_revision || |
| 1764 | !this.change?.revisions?.[this.change.current_revision] |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1765 | ) { |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1766 | this.uploader = undefined; |
| 1767 | return; |
Ben Rohlfs | 116ca52 | 2020-07-28 16:50:45 +0200 | [diff] [blame] | 1768 | } |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1769 | const rev = this.change.revisions[this.change.current_revision]; |
Ben Rohlfs | 116ca52 | 2020-07-28 16:50:45 +0200 | [diff] [blame] | 1770 | |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1771 | if ( |
| 1772 | !rev.uploader || |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1773 | this.change?.owner._account_id === rev.uploader._account_id |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1774 | ) { |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1775 | this.uploader = undefined; |
| 1776 | return; |
Ben Rohlfs | 116ca52 | 2020-07-28 16:50:45 +0200 | [diff] [blame] | 1777 | } |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1778 | this.uploader = rev.uploader; |
Ben Rohlfs | 116ca52 | 2020-07-28 16:50:45 +0200 | [diff] [blame] | 1779 | } |
| 1780 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1781 | /** |
| 1782 | * Generates a function to filter out reviewer/CC entries. When isCCs is |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1783 | * truthy, the function filters out entries that already exist in this.ccs. |
| 1784 | * When falsy, the function filters entries that exist in this.reviewers. |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1785 | */ |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1786 | filterReviewerSuggestionGenerator( |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1787 | isCCs: boolean |
| 1788 | ): (input: Suggestion) => boolean { |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1789 | return suggestion => { |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1790 | let entry: AccountInfo | GroupInfo; |
| 1791 | if (isReviewerAccountSuggestion(suggestion)) { |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1792 | entry = suggestion.account; |
Dhruv Srivastava | fcb6350 | 2022-07-11 14:42:00 +0200 | [diff] [blame] | 1793 | if (entry._account_id === this.change?.owner?._account_id) { |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1794 | return false; |
| 1795 | } |
| 1796 | } else if (isReviewerGroupSuggestion(suggestion)) { |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1797 | entry = suggestion.group; |
| 1798 | } else { |
Ben Rohlfs | c0ca555 | 2021-06-08 09:47:40 +0200 | [diff] [blame] | 1799 | this.reporting.error( |
Kamil Musin | f0ece02 | 2022-10-14 15:22:44 +0200 | [diff] [blame] | 1800 | 'Reviewer Suggestion', |
Ben Rohlfs | c0ca555 | 2021-06-08 09:47:40 +0200 | [diff] [blame] | 1801 | new Error(`Suggestion is neither account nor group: ${suggestion}`) |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1802 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1803 | return false; |
| 1804 | } |
| 1805 | |
Dhruv Srivastava | a1882db | 2022-08-18 10:16:26 +0200 | [diff] [blame] | 1806 | const key = getUserId(entry); |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1807 | const finder = (entry: AccountInfo | GroupInfo) => |
Dhruv Srivastava | a1882db | 2022-08-18 10:16:26 +0200 | [diff] [blame] | 1808 | getUserId(entry) === key; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1809 | if (isCCs) { |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1810 | return this.ccs.find(finder) === undefined; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1811 | } |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1812 | return this.reviewers.find(finder) === undefined; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1813 | }; |
| 1814 | } |
| 1815 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1816 | cancelTapHandler(e: Event) { |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1817 | e.preventDefault(); |
| 1818 | this.cancel(); |
| 1819 | } |
| 1820 | |
Dhruv Srivastava | 8230214 | 2022-09-07 16:36:39 +0200 | [diff] [blame] | 1821 | async cancel() { |
Ben Rohlfs | c1c6afd | 2021-02-18 13:13:22 +0100 | [diff] [blame] | 1822 | assertIsDefined(this.change, 'change'); |
Dhruv Srivastava | fcb6350 | 2022-07-11 14:42:00 +0200 | [diff] [blame] | 1823 | if (!this.change?.owner) throw new Error('missing required owner property'); |
Ben Rohlfs | 44f0104 | 2023-02-18 13:27:57 +0100 | [diff] [blame] | 1824 | fireNoBubble(this, 'cancel', {}); |
Dhruv Srivastava | e8b8639 | 2022-10-20 17:17:21 +0200 | [diff] [blame] | 1825 | await this.patchsetLevelGrComment?.save(); |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1826 | this.rebuildReviewerArrays(); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1827 | } |
| 1828 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1829 | saveClickHandler(e: Event) { |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1830 | e.preventDefault(); |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1831 | if (!this.ccsList?.submitEntryText()) { |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1832 | // Do not proceed with the save if there is an invalid email entry in |
| 1833 | // the text field of the CC entry. |
| 1834 | return; |
| 1835 | } |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1836 | this.send(this.includeComments, false); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1837 | } |
| 1838 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1839 | sendTapHandler(e: Event) { |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1840 | e.preventDefault(); |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1841 | this.submit(); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1842 | } |
| 1843 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1844 | submit() { |
| 1845 | if (!this.ccsList?.submitEntryText()) { |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1846 | // Do not proceed with the send if there is an invalid email entry in |
| 1847 | // the text field of the CC entry. |
| 1848 | return; |
| 1849 | } |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1850 | if (this.sendDisabled) { |
Milutin Kristofic | 860fe4d | 2020-11-23 16:13:45 +0100 | [diff] [blame] | 1851 | fireAlert(this, EMPTY_REPLY_MESSAGE); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1852 | return; |
| 1853 | } |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1854 | return this.send(this.includeComments, this.canBeStarted).catch(err => { |
Ben Rohlfs | 6bb9053 | 2023-02-17 18:55:56 +0100 | [diff] [blame] | 1855 | fireError(this, `Error submitting review ${err}`); |
Dhruv Srivastava | 57ae747 | 2021-05-05 11:42:03 +0200 | [diff] [blame] | 1856 | }); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1857 | } |
| 1858 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1859 | saveReview(review: ReviewInput, errFn?: ErrorCallback) { |
Ben Rohlfs | c1c6afd | 2021-02-18 13:13:22 +0100 | [diff] [blame] | 1860 | assertIsDefined(this.change, 'change'); |
Paladox none | d1e1617 | 2023-02-22 19:00:06 +0000 | [diff] [blame] | 1861 | assertIsDefined(this.latestPatchNum, 'latestPatchNum'); |
Ben Rohlfs | 43935a4 | 2020-12-01 19:14:09 +0100 | [diff] [blame] | 1862 | return this.restApiService.saveChangeReview( |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1863 | this.change._number, |
Paladox none | d1e1617 | 2023-02-22 19:00:06 +0000 | [diff] [blame] | 1864 | this.latestPatchNum, |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1865 | review, |
| 1866 | errFn |
| 1867 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1868 | } |
| 1869 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1870 | pendingConfirmationUpdated(reviewer: RawAccountInput | null) { |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1871 | if (reviewer === null) { |
Dhruv Srivastava | d6bd9df | 2022-11-14 19:46:47 +0530 | [diff] [blame] | 1872 | this.reviewerConfirmationModal?.close(); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1873 | } else { |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1874 | this.pendingConfirmationDetails = |
| 1875 | this.ccPendingConfirmation || this.reviewerPendingConfirmation; |
Dhruv Srivastava | d6bd9df | 2022-11-14 19:46:47 +0530 | [diff] [blame] | 1876 | this.reviewerConfirmationModal?.showModal(); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1877 | } |
| 1878 | } |
| 1879 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1880 | confirmPendingReviewer() { |
Dhruv Srivastava | c2e3872 | 2023-01-02 11:46:27 +0100 | [diff] [blame] | 1881 | this.reviewerConfirmationModal?.close(); |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1882 | if (this.ccPendingConfirmation) { |
| 1883 | this.ccsList?.confirmGroup(this.ccPendingConfirmation.group); |
| 1884 | this.focusOn(FocusTarget.CCS); |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1885 | return; |
| 1886 | } |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1887 | if (this.reviewerPendingConfirmation) { |
| 1888 | this.reviewersList?.confirmGroup(this.reviewerPendingConfirmation.group); |
| 1889 | this.focusOn(FocusTarget.REVIEWERS); |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1890 | return; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1891 | } |
Milutin Kristofic | 380b9f6 | 2020-12-03 09:24:17 +0100 | [diff] [blame] | 1892 | this.reporting.error( |
Kamil Musin | f0ece02 | 2022-10-14 15:22:44 +0200 | [diff] [blame] | 1893 | 'confirmPendingReviewer', |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1894 | new Error('confirmPendingReviewer called without pending confirm') |
Milutin Kristofic | 380b9f6 | 2020-12-03 09:24:17 +0100 | [diff] [blame] | 1895 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1896 | } |
| 1897 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1898 | cancelPendingReviewer() { |
Dhruv Srivastava | c2e3872 | 2023-01-02 11:46:27 +0100 | [diff] [blame] | 1899 | this.reviewerConfirmationModal?.close(); |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1900 | this.ccPendingConfirmation = null; |
| 1901 | this.reviewerPendingConfirmation = null; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1902 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1903 | const target = this.ccPendingConfirmation |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1904 | ? FocusTarget.CCS |
| 1905 | : FocusTarget.REVIEWERS; |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1906 | this.focusOn(target); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1907 | } |
| 1908 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1909 | handleAccountTextEntry() { |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1910 | // When either of the account entries has input added to the autocomplete, |
| 1911 | // it should trigger the save button to enable/ |
| 1912 | // |
| 1913 | // Note: if the text is removed, the save button will not get disabled. |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1914 | this.reviewersMutated = true; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1915 | } |
| 1916 | |
Dhruv Srivastava | db01c60 | 2022-07-18 15:34:34 +0200 | [diff] [blame] | 1917 | private alreadyExists(ccs: AccountInput[], user: AccountInfoInput) { |
| 1918 | return ccs |
| 1919 | .filter(cc => isAccount(cc)) |
Dhruv Srivastava | 664cbb8 | 2022-09-19 11:43:27 +0200 | [diff] [blame] | 1920 | .some(cc => getUserId(cc) === getUserId(user)); |
Dhruv Srivastava | db01c60 | 2022-07-18 15:34:34 +0200 | [diff] [blame] | 1921 | } |
| 1922 | |
| 1923 | private isAlreadyReviewerOrCC(user: AccountInfo) { |
| 1924 | return ( |
| 1925 | this.alreadyExists(this.reviewers, user) || |
| 1926 | this.alreadyExists(this._ccs, user) |
| 1927 | ); |
| 1928 | } |
| 1929 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1930 | getLabelScores(): GrLabelScores { |
| 1931 | return this.labelScores || queryAndAssert(this, 'gr-label-scores'); |
Dhruv Srivastava | 5dbf467 | 2021-06-29 09:06:20 +0200 | [diff] [blame] | 1932 | } |
| 1933 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1934 | _handleLabelsChanged() { |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1935 | this.labelsChanged = |
Dhruv Srivastava | 5dbf467 | 2021-06-29 09:06:20 +0200 | [diff] [blame] | 1936 | Object.keys(this.getLabelScores().getLabelValues(false)).length !== 0; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1937 | } |
| 1938 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1939 | handleReviewersChanged(e: ValueChangedEvent<(AccountInfo | GroupInfo)[]>) { |
Dhruv Srivastava | db01c60 | 2022-07-18 15:34:34 +0200 | [diff] [blame] | 1940 | this.reviewers = [...e.detail.value]; |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1941 | this.reviewersMutated = true; |
Milutin Kristofic | 508d3eb | 2022-04-04 14:15:43 +0200 | [diff] [blame] | 1942 | } |
| 1943 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1944 | handleCcsChanged(e: ValueChangedEvent<(AccountInfo | GroupInfo)[]>) { |
Dhruv Srivastava | db01c60 | 2022-07-18 15:34:34 +0200 | [diff] [blame] | 1945 | this.ccs = [...e.detail.value]; |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1946 | this.reviewersMutated = true; |
Milutin Kristofic | 508d3eb | 2022-04-04 14:15:43 +0200 | [diff] [blame] | 1947 | } |
| 1948 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1949 | handleReviewersConfirmationChanged( |
Milutin Kristofic | 508d3eb | 2022-04-04 14:15:43 +0200 | [diff] [blame] | 1950 | e: ValueChangedEvent<SuggestedReviewerGroupInfo | null> |
| 1951 | ) { |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1952 | this.reviewerPendingConfirmation = e.detail.value; |
Milutin Kristofic | 508d3eb | 2022-04-04 14:15:43 +0200 | [diff] [blame] | 1953 | } |
| 1954 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1955 | handleCcsConfirmationChanged( |
Milutin Kristofic | 508d3eb | 2022-04-04 14:15:43 +0200 | [diff] [blame] | 1956 | e: ValueChangedEvent<SuggestedReviewerGroupInfo | null> |
| 1957 | ) { |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1958 | this.ccPendingConfirmation = e.detail.value; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | _reload() { |
Ben Rohlfs | 66367b6 | 2021-04-30 10:06:32 +0200 | [diff] [blame] | 1962 | fireReload(this, true); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1963 | this.cancel(); |
| 1964 | } |
| 1965 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1966 | computeSendButtonLabel() { |
| 1967 | this.sendButtonLabel = this.canBeStarted |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1968 | ? ButtonLabels.SEND + ' and ' + ButtonLabels.START_REVIEW |
| 1969 | : ButtonLabels.SEND; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1970 | } |
| 1971 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1972 | computeSendButtonTooltip(canBeStarted?: boolean, commentEditing?: boolean) { |
Milutin Kristofic | 216e885 | 2020-12-17 09:18:11 +0100 | [diff] [blame] | 1973 | if (commentEditing) { |
| 1974 | return ButtonTooltips.DISABLED_COMMENT_EDITING; |
| 1975 | } |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1976 | return canBeStarted ? ButtonTooltips.START_REVIEW : ButtonTooltips.SEND; |
| 1977 | } |
| 1978 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1979 | computeSavingLabelClass(savingComments: boolean) { |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1980 | return savingComments ? 'saving' : ''; |
| 1981 | } |
| 1982 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1983 | computeSendButtonDisabled() { |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1984 | if ( |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1985 | this.canBeStarted === undefined || |
Chris Poucet | afd0f7c | 2022-10-04 10:04:43 +0000 | [diff] [blame] | 1986 | this.patchsetLevelDraftMessage === undefined || |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1987 | this.reviewersMutated === undefined || |
| 1988 | this.labelsChanged === undefined || |
| 1989 | this.includeComments === undefined || |
| 1990 | this.disabled === undefined || |
| 1991 | this.commentEditing === undefined || |
| 1992 | this.change?.labels === undefined || |
| 1993 | this.account === undefined |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1994 | ) { |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 1995 | return undefined; |
| 1996 | } |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 1997 | if (this.commentEditing || this.disabled) { |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 1998 | return true; |
| 1999 | } |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 2000 | if (this.canBeStarted === true) { |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 2001 | return false; |
| 2002 | } |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 2003 | const existingVote = Object.values(this.change.labels).some( |
| 2004 | label => |
| 2005 | isDetailedLabelInfo(label) && getApprovalInfo(label, this.account!) |
Frank Borden | 891b73e | 2021-01-29 16:43:50 -0800 | [diff] [blame] | 2006 | ); |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 2007 | const revotingOrNewVote = this.labelsChanged || existingVote; |
Dhruv Srivastava | 0b1f229 | 2022-09-21 10:25:43 +0200 | [diff] [blame] | 2008 | const hasDrafts = |
| 2009 | (this.includeComments && this.draftCommentThreads.length > 0) || |
Chris Poucet | afd0f7c | 2022-10-04 10:04:43 +0000 | [diff] [blame] | 2010 | this.patchsetLevelDraftMessage.length > 0; |
| 2011 | return ( |
| 2012 | !hasDrafts && |
| 2013 | !this.patchsetLevelDraftMessage.length && |
| 2014 | !this.reviewersMutated && |
| 2015 | !revotingOrNewVote |
| 2016 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2017 | } |
| 2018 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 2019 | computePatchSetWarning() { |
Paladox none | d1e1617 | 2023-02-22 19:00:06 +0000 | [diff] [blame] | 2020 | let str = `Patch ${this.latestPatchNum} is not latest.`; |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 2021 | if (this.labelsChanged) { |
Dhruv Srivastava | 520ecb9 | 2021-06-17 10:56:26 +0200 | [diff] [blame] | 2022 | str += ' Voting may have no effect.'; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2023 | } |
| 2024 | return str; |
| 2025 | } |
| 2026 | |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 2027 | setPluginMessage(message: string) { |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 2028 | this.pluginMessage = message; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2029 | } |
| 2030 | |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 2031 | sendDisabledChanged() { |
Ben Rohlfs | 44f0104 | 2023-02-18 13:27:57 +0100 | [diff] [blame] | 2032 | fireNoBubbleNoCompose(this, 'send-disabled-changed', {}); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2033 | } |
| 2034 | |
Dhruv Srivastava | ed17395 | 2022-08-08 09:37:36 +0200 | [diff] [blame] | 2035 | getReviewerSuggestionsProvider(change?: ChangeInfo | ParsedChangeInfo) { |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 2036 | if (!change) return; |
Frank Borden | 5980103 | 2022-05-06 14:37:18 +0200 | [diff] [blame] | 2037 | const provider = new GrReviewerSuggestionsProvider( |
Ben Rohlfs | 43935a4 | 2020-12-01 19:14:09 +0100 | [diff] [blame] | 2038 | this.restApiService, |
Frank Borden | de52af0 | 2022-05-12 10:14:14 +0200 | [diff] [blame] | 2039 | ReviewerState.REVIEWER, |
Frank Borden | 5980103 | 2022-05-06 14:37:18 +0200 | [diff] [blame] | 2040 | this.serverConfig, |
| 2041 | this.isLoggedIn, |
Frank Borden | 84da89b | 2022-06-15 14:28:05 +0200 | [diff] [blame] | 2042 | change |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 2043 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2044 | return provider; |
| 2045 | } |
| 2046 | |
Dhruv Srivastava | ed17395 | 2022-08-08 09:37:36 +0200 | [diff] [blame] | 2047 | getCcSuggestionsProvider(change?: ChangeInfo | ParsedChangeInfo) { |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 2048 | if (!change) return; |
Frank Borden | 5980103 | 2022-05-06 14:37:18 +0200 | [diff] [blame] | 2049 | const provider = new GrReviewerSuggestionsProvider( |
Ben Rohlfs | 43935a4 | 2020-12-01 19:14:09 +0100 | [diff] [blame] | 2050 | this.restApiService, |
Frank Borden | de52af0 | 2022-05-12 10:14:14 +0200 | [diff] [blame] | 2051 | ReviewerState.CC, |
Frank Borden | 5980103 | 2022-05-06 14:37:18 +0200 | [diff] [blame] | 2052 | this.serverConfig, |
| 2053 | this.isLoggedIn, |
Frank Borden | 84da89b | 2022-06-15 14:28:05 +0200 | [diff] [blame] | 2054 | change |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 2055 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2056 | return provider; |
| 2057 | } |
| 2058 | |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 2059 | reportAttentionSetChanges( |
| 2060 | modified: boolean, |
| 2061 | addedSet?: AttentionSetInput[], |
| 2062 | removedSet?: AttentionSetInput[] |
| 2063 | ) { |
Ben Rohlfs | ebf6354 | 2020-07-03 12:13:07 +0200 | [diff] [blame] | 2064 | const actions = modified ? ['MODIFIED'] : ['NOT_MODIFIED']; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 2065 | const ownerId = |
| 2066 | (this.change && this.change.owner && this.change.owner._account_id) || -1; |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 2067 | const selfId = (this.account && this.account._account_id) || -1; |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 2068 | for (const added of addedSet || []) { |
Ben Rohlfs | ebf6354 | 2020-07-03 12:13:07 +0200 | [diff] [blame] | 2069 | const addedId = added.user; |
| 2070 | const self = addedId === selfId ? '_SELF' : ''; |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 2071 | const role = addedId === ownerId ? 'OWNER' : '_REVIEWER'; |
Ben Rohlfs | ebf6354 | 2020-07-03 12:13:07 +0200 | [diff] [blame] | 2072 | actions.push('ADD' + self + role); |
| 2073 | } |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 2074 | for (const removed of removedSet || []) { |
Ben Rohlfs | ebf6354 | 2020-07-03 12:13:07 +0200 | [diff] [blame] | 2075 | const removedId = removed.user; |
| 2076 | const self = removedId === selfId ? '_SELF' : ''; |
Dhruv | 80dd5ee | 2022-04-06 13:34:02 +0200 | [diff] [blame] | 2077 | const role = removedId === ownerId ? 'OWNER' : '_REVIEWER'; |
Ben Rohlfs | ebf6354 | 2020-07-03 12:13:07 +0200 | [diff] [blame] | 2078 | actions.push('REMOVE' + self + role); |
| 2079 | } |
| 2080 | this.reporting.reportInteraction('attention-set-actions', {actions}); |
| 2081 | } |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 2082 | } |
| 2083 | |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 2084 | declare global { |
| 2085 | interface HTMLElementTagNameMap { |
| 2086 | 'gr-reply-dialog': GrReplyDialog; |
| 2087 | } |
Ben Rohlfs | 5b3c655 | 2023-02-18 13:02:46 +0100 | [diff] [blame] | 2088 | interface HTMLElementEventMap { |
| 2089 | /** Fired when the user presses the cancel button. */ |
Ben Rohlfs | e421751 | 2023-02-20 22:38:24 +0100 | [diff] [blame] | 2090 | // prettier-ignore |
Ben Rohlfs | 5b3c655 | 2023-02-18 13:02:46 +0100 | [diff] [blame] | 2091 | 'cancel': CustomEvent<{}>; |
| 2092 | /** |
| 2093 | * Fires when the reply dialog believes that the server side diff drafts |
| 2094 | * have been updated and need to be refreshed. |
| 2095 | */ |
| 2096 | 'comment-refresh': CustomEvent<{}>; |
| 2097 | /** Fired when a reply is successfully sent. */ |
Ben Rohlfs | e421751 | 2023-02-20 22:38:24 +0100 | [diff] [blame] | 2098 | // prettier-ignore |
Ben Rohlfs | 5b3c655 | 2023-02-18 13:02:46 +0100 | [diff] [blame] | 2099 | 'send': CustomEvent<{}>; |
| 2100 | /** Fires when the state of the send button (enabled/disabled) changes. */ |
| 2101 | 'send-disabled-changed': CustomEvent<{}>; |
| 2102 | } |
Ben Rohlfs | badc134 | 2020-09-22 10:04:23 +0200 | [diff] [blame] | 2103 | } |