Dave Borowitz | 8cdc76b | 2018-03-26 10:04:27 -0400 | [diff] [blame] | 1 | /** |
| 2 | * @license |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 3 | * Copyright (C) 2021 The Android Open Source Project |
Dave Borowitz | 8cdc76b | 2018-03-26 10:04:27 -0400 | [diff] [blame] | 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 17 | import './gr-related-change'; |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 18 | import '../../plugins/gr-endpoint-decorator/gr-endpoint-decorator'; |
| 19 | import '../../plugins/gr-endpoint-param/gr-endpoint-param'; |
| 20 | import '../../plugins/gr-endpoint-slot/gr-endpoint-slot'; |
Ben Rohlfs | e2b2f59 | 2021-09-07 08:47:53 +0000 | [diff] [blame^] | 21 | import {classMap} from 'lit/directives/class-map'; |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 22 | import {GrLitElement} from '../../lit/gr-lit-element'; |
Ben Rohlfs | e2b2f59 | 2021-09-07 08:47:53 +0000 | [diff] [blame^] | 23 | import {css, html, nothing, TemplateResult} from 'lit'; |
| 24 | import {customElement, property, state} from 'lit/decorators'; |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 25 | import {sharedStyles} from '../../../styles/shared-styles'; |
| 26 | import { |
| 27 | SubmittedTogetherInfo, |
| 28 | ChangeInfo, |
| 29 | RelatedChangeAndCommitInfo, |
| 30 | RelatedChangesInfo, |
| 31 | PatchSetNum, |
| 32 | CommitId, |
| 33 | } from '../../../types/common'; |
| 34 | import {appContext} from '../../../services/app-context'; |
| 35 | import {ParsedChangeInfo} from '../../../types/types'; |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 36 | import {GerritNav} from '../../core/gr-navigation/gr-navigation'; |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 37 | import {pluralize} from '../../../utils/string-util'; |
Milutin Kristofic | 41de817 | 2021-02-17 12:52:04 +0100 | [diff] [blame] | 38 | import { |
| 39 | changeIsOpen, |
| 40 | getRevisionKey, |
| 41 | isChangeInfo, |
| 42 | } from '../../../utils/change-util'; |
Milutin Kristofic | a7c24c1 | 2021-06-07 23:09:26 +0200 | [diff] [blame] | 43 | import {Interaction} from '../../../constants/reporting'; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 44 | |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 45 | /** What is the maximum number of shown changes in collapsed list? */ |
| 46 | const DEFALT_NUM_CHANGES_WHEN_COLLAPSED = 3; |
| 47 | |
| 48 | export interface ChangeMarkersInList { |
| 49 | showCurrentChangeArrow: boolean; |
| 50 | showWhenCollapsed: boolean; |
| 51 | showTopArrow: boolean; |
| 52 | showBottomArrow: boolean; |
| 53 | } |
| 54 | |
| 55 | export enum Section { |
| 56 | RELATED_CHANGES = 'related changes', |
| 57 | SUBMITTED_TOGETHER = 'submitted together', |
| 58 | SAME_TOPIC = 'same topic', |
| 59 | MERGE_CONFLICTS = 'merge conflicts', |
| 60 | CHERRY_PICKS = 'cherry picks', |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 61 | } |
| 62 | |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 63 | @customElement('gr-related-changes-list') |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 64 | export class GrRelatedChangesList extends GrLitElement { |
| 65 | @property() |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 66 | change?: ParsedChangeInfo; |
Dmitrii Filippov | 3fd2b10 | 2019-11-15 16:16:46 +0100 | [diff] [blame] | 67 | |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 68 | @property({type: String}) |
| 69 | patchNum?: PatchSetNum; |
| 70 | |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 71 | @property() |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 72 | mergeable?: boolean; |
| 73 | |
Frank Borden | f19f2b7 | 2021-05-12 11:21:34 +0200 | [diff] [blame] | 74 | @state() |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 75 | submittedTogether?: SubmittedTogetherInfo = { |
| 76 | changes: [], |
| 77 | non_visible_changes: 0, |
| 78 | }; |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 79 | |
Frank Borden | f19f2b7 | 2021-05-12 11:21:34 +0200 | [diff] [blame] | 80 | @state() |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 81 | relatedChanges: RelatedChangeAndCommitInfo[] = []; |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 82 | |
Frank Borden | f19f2b7 | 2021-05-12 11:21:34 +0200 | [diff] [blame] | 83 | @state() |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 84 | conflictingChanges: ChangeInfo[] = []; |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 85 | |
Frank Borden | f19f2b7 | 2021-05-12 11:21:34 +0200 | [diff] [blame] | 86 | @state() |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 87 | cherryPickChanges: ChangeInfo[] = []; |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 88 | |
Frank Borden | f19f2b7 | 2021-05-12 11:21:34 +0200 | [diff] [blame] | 89 | @state() |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 90 | sameTopicChanges: ChangeInfo[] = []; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 91 | |
Ben Rohlfs | 43935a4 | 2020-12-01 19:14:09 +0100 | [diff] [blame] | 92 | private readonly restApiService = appContext.restApiService; |
| 93 | |
Gerrit Code Review | 7903123 | 2021-08-19 14:32:41 +0000 | [diff] [blame] | 94 | static override get styles() { |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 95 | return [ |
| 96 | sharedStyles, |
| 97 | css` |
| 98 | .note { |
| 99 | color: var(--error-text-color); |
| 100 | margin-left: 1.2em; |
| 101 | } |
| 102 | section { |
| 103 | margin-bottom: var(--spacing-l); |
| 104 | } |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 105 | .relatedChangeLine { |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 106 | display: flex; |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 107 | visibility: visible; |
| 108 | height: auto; |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 109 | } |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 110 | .marker.arrow { |
| 111 | visibility: hidden; |
| 112 | min-width: 20px; |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 113 | } |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 114 | .marker.arrowToCurrentChange { |
| 115 | min-width: 20px; |
| 116 | text-align: center; |
| 117 | } |
| 118 | .marker.space { |
| 119 | height: 1px; |
| 120 | min-width: 20px; |
| 121 | } |
| 122 | gr-related-collapse[collapsed] .marker.arrow { |
| 123 | visibility: visible; |
| 124 | min-width: auto; |
| 125 | } |
| 126 | gr-related-collapse[collapsed] .relatedChangeLine.show-when-collapsed { |
| 127 | visibility: visible; |
| 128 | height: auto; |
| 129 | } |
| 130 | /* keep width, so width of section and position of show all button |
| 131 | * are set according to width of all (even hidden) elements |
| 132 | */ |
| 133 | gr-related-collapse[collapsed] .relatedChangeLine { |
| 134 | visibility: hidden; |
| 135 | height: 0px; |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 136 | } |
| 137 | `, |
| 138 | ]; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 139 | } |
| 140 | |
Gerrit Code Review | 7903123 | 2021-08-19 14:32:41 +0000 | [diff] [blame] | 141 | override render() { |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 142 | const sectionSize = this.sectionSizeFactory( |
| 143 | this.relatedChanges.length, |
| 144 | this.submittedTogether?.changes.length || 0, |
| 145 | this.sameTopicChanges.length, |
| 146 | this.conflictingChanges.length, |
| 147 | this.cherryPickChanges.length |
| 148 | ); |
| 149 | const relatedChangesMarkersPredicate = this.markersPredicateFactory( |
| 150 | this.relatedChanges.length, |
| 151 | this.relatedChanges.findIndex(relatedChange => |
| 152 | this._changesEqual(relatedChange, this.change) |
| 153 | ), |
| 154 | sectionSize(Section.RELATED_CHANGES) |
| 155 | ); |
| 156 | const connectedRevisions = this._computeConnectedRevisions( |
| 157 | this.change, |
| 158 | this.patchNum, |
| 159 | this.relatedChanges |
| 160 | ); |
| 161 | let firstNonEmptySectionFound = false; |
| 162 | let isFirstNonEmpty = |
| 163 | !firstNonEmptySectionFound && !!this.relatedChanges.length; |
| 164 | firstNonEmptySectionFound = firstNonEmptySectionFound || isFirstNonEmpty; |
| 165 | const relatedChangeSection = html` <section |
| 166 | id="relatedChanges" |
| 167 | ?hidden=${!this.relatedChanges.length} |
| 168 | > |
| 169 | <gr-related-collapse |
| 170 | title="Relation chain" |
| 171 | class="${classMap({first: isFirstNonEmpty})}" |
| 172 | .length=${this.relatedChanges.length} |
| 173 | .numChangesWhenCollapsed=${sectionSize(Section.RELATED_CHANGES)} |
| 174 | > |
| 175 | ${this.relatedChanges.map( |
| 176 | (change, index) => |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 177 | html`<div |
| 178 | class="${classMap({ |
| 179 | ['relatedChangeLine']: true, |
Chris Poucet | caeea1b | 2021-08-19 22:12:56 +0000 | [diff] [blame] | 180 | ['show-when-collapsed']: |
| 181 | relatedChangesMarkersPredicate(index).showWhenCollapsed, |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 182 | })}" |
| 183 | > |
| 184 | ${this.renderMarkers( |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 185 | relatedChangesMarkersPredicate(index) |
| 186 | )}<gr-related-change |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 187 | .change="${change}" |
| 188 | .connectedRevisions="${connectedRevisions}" |
| 189 | .href="${change?._change_number |
| 190 | ? GerritNav.getUrlForChangeById( |
| 191 | change._change_number, |
| 192 | change.project, |
| 193 | change._revision_number as PatchSetNum |
| 194 | ) |
| 195 | : ''}" |
| 196 | .showChangeStatus=${true} |
| 197 | >${change.commit.subject}</gr-related-change |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 198 | > |
| 199 | </div>` |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 200 | )} |
| 201 | </gr-related-collapse> |
| 202 | </section>`; |
| 203 | |
| 204 | const submittedTogetherChanges = this.submittedTogether?.changes ?? []; |
| 205 | const countNonVisibleChanges = |
| 206 | this.submittedTogether?.non_visible_changes ?? 0; |
| 207 | const submittedTogetherMarkersPredicate = this.markersPredicateFactory( |
| 208 | submittedTogetherChanges.length, |
| 209 | submittedTogetherChanges.findIndex(relatedChange => |
| 210 | this._changesEqual(relatedChange, this.change) |
| 211 | ), |
| 212 | sectionSize(Section.SUBMITTED_TOGETHER) |
| 213 | ); |
| 214 | isFirstNonEmpty = |
| 215 | !firstNonEmptySectionFound && |
| 216 | (!!submittedTogetherChanges?.length || |
| 217 | !!this.submittedTogether?.non_visible_changes); |
| 218 | firstNonEmptySectionFound = firstNonEmptySectionFound || isFirstNonEmpty; |
| 219 | const submittedTogetherSection = html`<section |
| 220 | id="submittedTogether" |
| 221 | ?hidden=${!submittedTogetherChanges?.length && |
| 222 | !this.submittedTogether?.non_visible_changes} |
| 223 | > |
| 224 | <gr-related-collapse |
| 225 | title="Submitted together" |
| 226 | class="${classMap({first: isFirstNonEmpty})}" |
| 227 | .length=${submittedTogetherChanges.length} |
| 228 | .numChangesWhenCollapsed=${sectionSize(Section.SUBMITTED_TOGETHER)} |
| 229 | > |
| 230 | ${submittedTogetherChanges.map( |
| 231 | (change, index) => |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 232 | html`<div |
| 233 | class="${classMap({ |
| 234 | ['relatedChangeLine']: true, |
Chris Poucet | caeea1b | 2021-08-19 22:12:56 +0000 | [diff] [blame] | 235 | ['show-when-collapsed']: |
| 236 | submittedTogetherMarkersPredicate(index).showWhenCollapsed, |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 237 | })}" |
| 238 | > |
| 239 | ${this.renderMarkers( |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 240 | submittedTogetherMarkersPredicate(index) |
| 241 | )}<gr-related-change |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 242 | .change="${change}" |
| 243 | .href="${GerritNav.getUrlForChangeById( |
| 244 | change._number, |
| 245 | change.project |
| 246 | )}" |
| 247 | .showSubmittableCheck=${true} |
| 248 | >${change.project}: ${change.branch}: |
| 249 | ${change.subject}</gr-related-change |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 250 | > |
| 251 | </div>` |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 252 | )} |
| 253 | </gr-related-collapse> |
| 254 | <div class="note" ?hidden=${!countNonVisibleChanges}> |
| 255 | (+ ${pluralize(countNonVisibleChanges, 'non-visible change')}) |
| 256 | </div> |
| 257 | </section>`; |
| 258 | |
| 259 | const sameTopicMarkersPredicate = this.markersPredicateFactory( |
| 260 | this.sameTopicChanges.length, |
| 261 | -1, |
| 262 | sectionSize(Section.SAME_TOPIC) |
| 263 | ); |
| 264 | isFirstNonEmpty = |
| 265 | !firstNonEmptySectionFound && !!this.sameTopicChanges?.length; |
| 266 | firstNonEmptySectionFound = firstNonEmptySectionFound || isFirstNonEmpty; |
| 267 | const sameTopicSection = html`<section |
| 268 | id="sameTopic" |
| 269 | ?hidden=${!this.sameTopicChanges?.length} |
| 270 | > |
| 271 | <gr-related-collapse |
| 272 | title="Same topic" |
| 273 | class="${classMap({first: isFirstNonEmpty})}" |
| 274 | .length=${this.sameTopicChanges.length} |
| 275 | .numChangesWhenCollapsed=${sectionSize(Section.SAME_TOPIC)} |
| 276 | > |
| 277 | ${this.sameTopicChanges.map( |
| 278 | (change, index) => |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 279 | html`<div |
| 280 | class="${classMap({ |
| 281 | ['relatedChangeLine']: true, |
Chris Poucet | caeea1b | 2021-08-19 22:12:56 +0000 | [diff] [blame] | 282 | ['show-when-collapsed']: |
| 283 | sameTopicMarkersPredicate(index).showWhenCollapsed, |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 284 | })}" |
| 285 | > |
| 286 | ${this.renderMarkers( |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 287 | sameTopicMarkersPredicate(index) |
| 288 | )}<gr-related-change |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 289 | .change="${change}" |
| 290 | .href="${GerritNav.getUrlForChangeById( |
| 291 | change._number, |
| 292 | change.project |
| 293 | )}" |
| 294 | >${change.project}: ${change.branch}: |
| 295 | ${change.subject}</gr-related-change |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 296 | > |
| 297 | </div>` |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 298 | )} |
| 299 | </gr-related-collapse> |
| 300 | </section>`; |
| 301 | |
| 302 | const mergeConflictsMarkersPredicate = this.markersPredicateFactory( |
| 303 | this.conflictingChanges.length, |
| 304 | -1, |
| 305 | sectionSize(Section.MERGE_CONFLICTS) |
| 306 | ); |
| 307 | isFirstNonEmpty = |
| 308 | !firstNonEmptySectionFound && !!this.conflictingChanges?.length; |
| 309 | firstNonEmptySectionFound = firstNonEmptySectionFound || isFirstNonEmpty; |
| 310 | const mergeConflictsSection = html`<section |
| 311 | id="mergeConflicts" |
| 312 | ?hidden=${!this.conflictingChanges?.length} |
| 313 | > |
| 314 | <gr-related-collapse |
| 315 | title="Merge conflicts" |
| 316 | class="${classMap({first: isFirstNonEmpty})}" |
| 317 | .length=${this.conflictingChanges.length} |
| 318 | .numChangesWhenCollapsed=${sectionSize(Section.MERGE_CONFLICTS)} |
| 319 | > |
| 320 | ${this.conflictingChanges.map( |
| 321 | (change, index) => |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 322 | html`<div |
| 323 | class="${classMap({ |
| 324 | ['relatedChangeLine']: true, |
Chris Poucet | caeea1b | 2021-08-19 22:12:56 +0000 | [diff] [blame] | 325 | ['show-when-collapsed']: |
| 326 | mergeConflictsMarkersPredicate(index).showWhenCollapsed, |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 327 | })}" |
| 328 | > |
| 329 | ${this.renderMarkers( |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 330 | mergeConflictsMarkersPredicate(index) |
| 331 | )}<gr-related-change |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 332 | .change="${change}" |
| 333 | .href="${GerritNav.getUrlForChangeById( |
| 334 | change._number, |
| 335 | change.project |
| 336 | )}" |
| 337 | >${change.subject}</gr-related-change |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 338 | > |
| 339 | </div>` |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 340 | )} |
| 341 | </gr-related-collapse> |
| 342 | </section>`; |
| 343 | |
| 344 | const cherryPicksMarkersPredicate = this.markersPredicateFactory( |
| 345 | this.cherryPickChanges.length, |
| 346 | -1, |
| 347 | sectionSize(Section.CHERRY_PICKS) |
| 348 | ); |
| 349 | isFirstNonEmpty = |
| 350 | !firstNonEmptySectionFound && !!this.cherryPickChanges?.length; |
| 351 | firstNonEmptySectionFound = firstNonEmptySectionFound || isFirstNonEmpty; |
| 352 | const cherryPicksSection = html`<section |
| 353 | id="cherryPicks" |
| 354 | ?hidden=${!this.cherryPickChanges?.length} |
| 355 | > |
| 356 | <gr-related-collapse |
| 357 | title="Cherry picks" |
| 358 | class="${classMap({first: isFirstNonEmpty})}" |
| 359 | .length=${this.cherryPickChanges.length} |
| 360 | .numChangesWhenCollapsed=${sectionSize(Section.CHERRY_PICKS)} |
| 361 | > |
| 362 | ${this.cherryPickChanges.map( |
| 363 | (change, index) => |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 364 | html`<div |
| 365 | class="${classMap({ |
| 366 | ['relatedChangeLine']: true, |
Chris Poucet | caeea1b | 2021-08-19 22:12:56 +0000 | [diff] [blame] | 367 | ['show-when-collapsed']: |
| 368 | cherryPicksMarkersPredicate(index).showWhenCollapsed, |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 369 | })}" |
| 370 | > |
| 371 | ${this.renderMarkers( |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 372 | cherryPicksMarkersPredicate(index) |
| 373 | )}<gr-related-change |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 374 | .change="${change}" |
| 375 | .href="${GerritNav.getUrlForChangeById( |
| 376 | change._number, |
| 377 | change.project |
| 378 | )}" |
| 379 | >${change.branch}: ${change.subject}</gr-related-change |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 380 | > |
| 381 | </div>` |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 382 | )} |
| 383 | </gr-related-collapse> |
| 384 | </section>`; |
| 385 | |
| 386 | return html`<gr-endpoint-decorator name="related-changes-section"> |
| 387 | <gr-endpoint-param |
| 388 | name="change" |
| 389 | .value=${this.change} |
| 390 | ></gr-endpoint-param> |
| 391 | <gr-endpoint-slot name="top"></gr-endpoint-slot> |
| 392 | ${relatedChangeSection} ${submittedTogetherSection} ${sameTopicSection} |
| 393 | ${mergeConflictsSection} ${cherryPicksSection} |
| 394 | <gr-endpoint-slot name="bottom"></gr-endpoint-slot> |
| 395 | </gr-endpoint-decorator>`; |
| 396 | } |
| 397 | |
| 398 | sectionSizeFactory( |
| 399 | relatedChangesLen: number, |
| 400 | submittedTogetherLen: number, |
| 401 | sameTopicLen: number, |
| 402 | mergeConflictsLen: number, |
| 403 | cherryPicksLen: number |
| 404 | ) { |
| 405 | const calcDefaultSize = (length: number) => |
| 406 | Math.min(length, DEFALT_NUM_CHANGES_WHEN_COLLAPSED); |
| 407 | |
| 408 | const sectionSizes = [ |
| 409 | { |
| 410 | section: Section.RELATED_CHANGES, |
| 411 | size: calcDefaultSize(relatedChangesLen), |
| 412 | len: relatedChangesLen, |
| 413 | }, |
| 414 | { |
| 415 | section: Section.SUBMITTED_TOGETHER, |
| 416 | size: calcDefaultSize(submittedTogetherLen), |
| 417 | len: submittedTogetherLen, |
| 418 | }, |
| 419 | { |
| 420 | section: Section.SAME_TOPIC, |
| 421 | size: calcDefaultSize(sameTopicLen), |
| 422 | len: sameTopicLen, |
| 423 | }, |
| 424 | { |
| 425 | section: Section.MERGE_CONFLICTS, |
| 426 | size: calcDefaultSize(mergeConflictsLen), |
| 427 | len: mergeConflictsLen, |
| 428 | }, |
| 429 | { |
| 430 | section: Section.CHERRY_PICKS, |
| 431 | size: calcDefaultSize(cherryPicksLen), |
| 432 | len: cherryPicksLen, |
| 433 | }, |
| 434 | ]; |
| 435 | |
| 436 | const FILLER = 1; // space for header |
| 437 | let totalSize = sectionSizes.reduce( |
| 438 | (acc, val) => acc + val.size + (val.size !== 0 ? FILLER : 0), |
| 439 | 0 |
| 440 | ); |
| 441 | |
| 442 | const MAX_SIZE = 16; |
| 443 | for (let i = 0; i < sectionSizes.length; i++) { |
| 444 | if (totalSize >= MAX_SIZE) break; |
| 445 | const sizeObj = sectionSizes[i]; |
| 446 | if (sizeObj.size === sizeObj.len) continue; |
| 447 | const newSize = Math.min( |
| 448 | MAX_SIZE - totalSize + sizeObj.size, |
| 449 | sizeObj.len |
| 450 | ); |
| 451 | totalSize += newSize - sizeObj.size; |
| 452 | sizeObj.size = newSize; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 453 | } |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 454 | |
| 455 | return (section: Section) => { |
| 456 | const sizeObj = sectionSizes.find(sizeObj => sizeObj.section === section); |
| 457 | if (sizeObj) return sizeObj.size; |
| 458 | return DEFALT_NUM_CHANGES_WHEN_COLLAPSED; |
| 459 | }; |
| 460 | } |
| 461 | |
| 462 | markersPredicateFactory( |
| 463 | length: number, |
| 464 | highlightIndex: number, |
| 465 | numChangesShownWhenCollapsed = DEFALT_NUM_CHANGES_WHEN_COLLAPSED |
| 466 | ): (index: number) => ChangeMarkersInList { |
| 467 | const showWhenCollapsedPredicate = (index: number) => { |
| 468 | if (highlightIndex === -1) return index < numChangesShownWhenCollapsed; |
| 469 | if (highlightIndex === 0) |
| 470 | return index <= numChangesShownWhenCollapsed - 1; |
| 471 | if (highlightIndex === length - 1) |
| 472 | return index >= length - numChangesShownWhenCollapsed; |
| 473 | let numBeforeHighlight = Math.floor(numChangesShownWhenCollapsed / 2); |
| 474 | let numAfterHighlight = |
| 475 | Math.floor(numChangesShownWhenCollapsed / 2) - |
| 476 | (numChangesShownWhenCollapsed % 2 ? 0 : 1); |
| 477 | numBeforeHighlight += Math.max( |
| 478 | highlightIndex + numAfterHighlight - length + 1, |
| 479 | 0 |
| 480 | ); |
| 481 | numAfterHighlight -= Math.min(0, highlightIndex - numBeforeHighlight); |
| 482 | return ( |
| 483 | highlightIndex - numBeforeHighlight <= index && |
| 484 | index <= highlightIndex + numAfterHighlight |
| 485 | ); |
| 486 | }; |
| 487 | return (index: number) => { |
| 488 | return { |
| 489 | showCurrentChangeArrow: |
| 490 | highlightIndex !== -1 && index === highlightIndex, |
| 491 | showWhenCollapsed: showWhenCollapsedPredicate(index), |
| 492 | showTopArrow: |
| 493 | index >= 1 && |
| 494 | index !== highlightIndex && |
| 495 | showWhenCollapsedPredicate(index) && |
| 496 | !showWhenCollapsedPredicate(index - 1), |
| 497 | showBottomArrow: |
| 498 | index <= length - 2 && |
| 499 | index !== highlightIndex && |
| 500 | showWhenCollapsedPredicate(index) && |
| 501 | !showWhenCollapsedPredicate(index + 1), |
| 502 | }; |
| 503 | }; |
| 504 | } |
| 505 | |
| 506 | renderMarkers(changeMarkers: ChangeMarkersInList) { |
| 507 | if (changeMarkers.showCurrentChangeArrow) { |
| 508 | return html`<span |
| 509 | role="img" |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 510 | class="marker arrowToCurrentChange" |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 511 | aria-label="Arrow marking current change" |
| 512 | >âž”</span |
| 513 | >`; |
| 514 | } |
| 515 | if (changeMarkers.showTopArrow) { |
| 516 | return html`<span |
| 517 | role="img" |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 518 | class="marker arrow" |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 519 | aria-label="Arrow marking change has collapsed ancestors" |
| 520 | ><iron-icon icon="gr-icons:arrowDropUp"></iron-icon |
| 521 | ></span> `; |
| 522 | } |
| 523 | if (changeMarkers.showBottomArrow) { |
| 524 | return html`<span |
| 525 | role="img" |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 526 | class="marker arrow" |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 527 | aria-label="Arrow marking change has collapsed descendants" |
| 528 | ><iron-icon icon="gr-icons:arrowDropDown"></iron-icon |
| 529 | ></span> `; |
| 530 | } |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 531 | return html`<span class="marker space"></span>`; |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | reload(getRelatedChanges?: Promise<RelatedChangesInfo | undefined>) { |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 535 | const change = this.change; |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 536 | if (!change) return Promise.reject(new Error('change missing')); |
| 537 | if (!this.patchNum) return Promise.reject(new Error('patchNum missing')); |
| 538 | if (!getRelatedChanges) { |
| 539 | getRelatedChanges = this.restApiService.getRelatedChanges( |
| 540 | change._number, |
| 541 | this.patchNum |
| 542 | ); |
| 543 | } |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 544 | const promises: Array<Promise<void>> = [ |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 545 | getRelatedChanges.then(response => { |
| 546 | if (!response) { |
| 547 | throw new Error('getRelatedChanges returned undefined response'); |
| 548 | } |
| 549 | this.relatedChanges = response?.changes ?? []; |
| 550 | }), |
Ben Rohlfs | 43935a4 | 2020-12-01 19:14:09 +0100 | [diff] [blame] | 551 | this.restApiService |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 552 | .getChangesSubmittedTogether(change._number) |
| 553 | .then(response => { |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 554 | this.submittedTogether = response; |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 555 | }), |
Ben Rohlfs | 43935a4 | 2020-12-01 19:14:09 +0100 | [diff] [blame] | 556 | this.restApiService |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 557 | .getChangeCherryPicks(change.project, change.change_id, change._number) |
| 558 | .then(response => { |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 559 | this.cherryPickChanges = response || []; |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 560 | }), |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 561 | ]; |
| 562 | |
| 563 | // Get conflicts if change is open and is mergeable. |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 564 | // Mergeable is output of restApiServict.getMergeable from gr-change-view |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 565 | if (changeIsOpen(change) && this.mergeable) { |
| 566 | promises.push( |
Ben Rohlfs | 43935a4 | 2020-12-01 19:14:09 +0100 | [diff] [blame] | 567 | this.restApiService |
| 568 | .getChangeConflicts(change._number) |
| 569 | .then(response => { |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 570 | this.conflictingChanges = response ?? []; |
Ben Rohlfs | 43935a4 | 2020-12-01 19:14:09 +0100 | [diff] [blame] | 571 | }) |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 572 | ); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 573 | } |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 574 | if (change.topic) { |
| 575 | const changeTopic = change.topic; |
| 576 | promises.push( |
| 577 | this.restApiService.getConfig().then(config => { |
| 578 | if (config && !config.change.submit_whole_topic) { |
Ben Rohlfs | 43935a4 | 2020-12-01 19:14:09 +0100 | [diff] [blame] | 579 | return this.restApiService |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 580 | .getChangesWithSameTopic(changeTopic, change._number) |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 581 | .then(response => { |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 582 | if (changeTopic === this.change?.topic) { |
| 583 | this.sameTopicChanges = response ?? []; |
| 584 | } |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 585 | }); |
| 586 | } |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 587 | this.sameTopicChanges = []; |
| 588 | return Promise.resolve(); |
| 589 | }) |
| 590 | ); |
| 591 | } |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 592 | |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 593 | return Promise.all(promises); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 594 | } |
| 595 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 596 | /** |
| 597 | * Do the given objects describe the same change? Compares the changes by |
| 598 | * their numbers. |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 599 | */ |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 600 | _changesEqual( |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 601 | a?: ChangeInfo | RelatedChangeAndCommitInfo, |
| 602 | b?: ChangeInfo | ParsedChangeInfo | RelatedChangeAndCommitInfo |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 603 | ) { |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 604 | const aNum = this._getChangeNumber(a); |
| 605 | const bNum = this._getChangeNumber(b); |
| 606 | return aNum === bNum; |
| 607 | } |
| 608 | |
| 609 | /** |
| 610 | * Get the change number from either a ChangeInfo (such as those included in |
| 611 | * SubmittedTogetherInfo responses) or get the change number from a |
| 612 | * RelatedChangeAndCommitInfo (such as those included in a |
| 613 | * RelatedChangesInfo response). |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 614 | */ |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 615 | _getChangeNumber( |
| 616 | change?: ChangeInfo | ParsedChangeInfo | RelatedChangeAndCommitInfo |
| 617 | ) { |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 618 | // Default to 0 if change property is not defined. |
| 619 | if (!change) return 0; |
| 620 | |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 621 | if (isChangeInfo(change)) { |
| 622 | return change._number; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 623 | } |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 624 | return change._change_number; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 625 | } |
| 626 | |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 627 | /* |
| 628 | * A list of commit ids connected to change to understand if other change |
| 629 | * is direct or indirect ancestor / descendant. |
| 630 | */ |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 631 | _computeConnectedRevisions( |
| 632 | change?: ParsedChangeInfo, |
| 633 | patchNum?: PatchSetNum, |
| 634 | relatedChanges?: RelatedChangeAndCommitInfo[] |
| 635 | ) { |
Milutin Kristofic | 02c5003 | 2021-02-10 08:49:33 +0100 | [diff] [blame] | 636 | if (!patchNum || !relatedChanges || !change) { |
| 637 | return []; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 638 | } |
| 639 | |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 640 | const connected: CommitId[] = []; |
Milutin Kristofic | 02c5003 | 2021-02-10 08:49:33 +0100 | [diff] [blame] | 641 | const changeRevision = getRevisionKey(change, patchNum); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 642 | const commits = relatedChanges.map(c => c.commit); |
| 643 | let pos = commits.length - 1; |
| 644 | |
| 645 | while (pos >= 0) { |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 646 | const commit: CommitId = commits[pos].commit; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 647 | connected.push(commit); |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 648 | // TODO(TS): Ensure that both (commit and changeRevision) are string and use === instead |
| 649 | // eslint-disable-next-line eqeqeq |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 650 | if (commit == changeRevision) { |
| 651 | break; |
| 652 | } |
| 653 | pos--; |
| 654 | } |
| 655 | while (pos >= 0) { |
| 656 | for (let i = 0; i < commits[pos].parents.length; i++) { |
| 657 | if (connected.includes(commits[pos].parents[i].commit)) { |
| 658 | connected.push(commits[pos].commit); |
| 659 | break; |
| 660 | } |
| 661 | } |
| 662 | --pos; |
| 663 | } |
| 664 | return connected; |
| 665 | } |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 666 | } |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 667 | |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 668 | @customElement('gr-related-collapse') |
| 669 | export class GrRelatedCollapse extends GrLitElement { |
| 670 | @property() |
Gerrit Code Review | 7903123 | 2021-08-19 14:32:41 +0000 | [diff] [blame] | 671 | override title = ''; |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 672 | |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 673 | @property({type: Boolean}) |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 674 | showAll = false; |
| 675 | |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 676 | @property({type: Boolean, reflect: true}) |
| 677 | collapsed = true; |
| 678 | |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 679 | @property() |
| 680 | length = 0; |
| 681 | |
| 682 | @property() |
| 683 | numChangesWhenCollapsed = DEFALT_NUM_CHANGES_WHEN_COLLAPSED; |
| 684 | |
| 685 | private readonly reporting = appContext.reportingService; |
| 686 | |
Gerrit Code Review | 7903123 | 2021-08-19 14:32:41 +0000 | [diff] [blame] | 687 | static override get styles() { |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 688 | return [ |
| 689 | sharedStyles, |
| 690 | css` |
| 691 | .title { |
| 692 | font-weight: var(--font-weight-bold); |
| 693 | color: var(--deemphasized-text-color); |
| 694 | padding-left: var(--metadata-horizontal-padding); |
| 695 | } |
| 696 | h4 { |
| 697 | display: flex; |
| 698 | align-self: flex-end; |
| 699 | } |
| 700 | gr-button { |
| 701 | display: flex; |
| 702 | } |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 703 | h4 { |
| 704 | margin-left: 20px; |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 705 | } |
| 706 | gr-button iron-icon { |
| 707 | color: inherit; |
| 708 | --iron-icon-height: 18px; |
| 709 | --iron-icon-width: 18px; |
| 710 | } |
| 711 | .container { |
| 712 | justify-content: space-between; |
| 713 | display: flex; |
| 714 | margin-bottom: var(--spacing-s); |
| 715 | } |
| 716 | :host(.first) .container { |
| 717 | margin-bottom: var(--spacing-m); |
| 718 | } |
| 719 | `, |
| 720 | ]; |
| 721 | } |
| 722 | |
Gerrit Code Review | 7903123 | 2021-08-19 14:32:41 +0000 | [diff] [blame] | 723 | override render() { |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 724 | const title = html`<h4 class="title">${this.title}</h4>`; |
| 725 | |
| 726 | const collapsible = this.length > this.numChangesWhenCollapsed; |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 727 | this.collapsed = !this.showAll && collapsible; |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 728 | |
| 729 | let button: TemplateResult | typeof nothing = nothing; |
| 730 | if (collapsible) { |
| 731 | let buttonText = 'Show less'; |
| 732 | let buttonIcon = 'expand-less'; |
| 733 | if (!this.showAll) { |
| 734 | buttonText = `Show all (${this.length})`; |
| 735 | buttonIcon = 'expand-more'; |
| 736 | } |
| 737 | button = html`<gr-button link="" @click="${this.toggle}" |
| 738 | >${buttonText}<iron-icon icon="gr-icons:${buttonIcon}"></iron-icon |
| 739 | ></gr-button>`; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 740 | } |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 741 | |
| 742 | return html`<div class="container">${title}${button}</div> |
Milutin Kristofic | 505f0ab | 2021-05-27 13:20:44 +0200 | [diff] [blame] | 743 | <div><slot></slot></div>`; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 744 | } |
| 745 | |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 746 | private toggle(e: MouseEvent) { |
| 747 | e.stopPropagation(); |
| 748 | this.showAll = !this.showAll; |
Milutin Kristofic | a7c24c1 | 2021-06-07 23:09:26 +0200 | [diff] [blame] | 749 | this.reporting.reportInteraction(Interaction.TOGGLE_SHOW_ALL_BUTTON, { |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 750 | sectionName: this.title, |
| 751 | toState: this.showAll ? 'Show all' : 'Show less', |
Milutin Kristofic | c866e60 | 2021-02-17 00:03:47 +0100 | [diff] [blame] | 752 | }); |
| 753 | } |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 754 | } |
| 755 | |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 756 | declare global { |
| 757 | interface HTMLElementTagNameMap { |
| 758 | 'gr-related-changes-list': GrRelatedChangesList; |
Milutin Kristofic | f819216 | 2021-04-21 22:12:59 +0200 | [diff] [blame] | 759 | 'gr-related-collapse': GrRelatedCollapse; |
Dmitrii Filippov | 1d60791 | 2020-09-21 13:21:14 +0200 | [diff] [blame] | 760 | } |
| 761 | } |