Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @license |
| 3 | * Copyright (C) 2015 The Android Open Source Project |
| 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 | */ |
| 17 | |
Milutin Kristofic | be90017 | 2021-10-25 13:42:58 +0200 | [diff] [blame] | 18 | import '../../change/gr-submit-requirement-dashboard-hovercard/gr-submit-requirement-dashboard-hovercard'; |
Milutin Kristofic | facc3c5 | 2021-12-08 20:40:38 +0100 | [diff] [blame] | 19 | import '../../shared/gr-change-status/gr-change-status'; |
Milutin Kristofic | 52b1f58 | 2021-12-06 11:01:22 +0100 | [diff] [blame] | 20 | import {LitElement, css, html, TemplateResult} from 'lit'; |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 21 | import {customElement, property} from 'lit/decorators'; |
| 22 | import {ChangeInfo, SubmitRequirementStatus} from '../../../api/rest-api'; |
Milutin Kristofic | facc3c5 | 2021-12-08 20:40:38 +0100 | [diff] [blame] | 23 | import {changeStatuses} from '../../../utils/change-util'; |
Milutin Kristofic | ae44ca4 | 2021-12-03 14:29:05 +0100 | [diff] [blame] | 24 | import {getRequirements, iconForStatus} from '../../../utils/label-util'; |
Milutin Kristofic | b2237d6 | 2021-12-09 20:29:55 +0100 | [diff] [blame] | 25 | import {submitRequirementsStyles} from '../../../styles/gr-submit-requirements-styles'; |
Milutin Kristofic | c8b9408 | 2021-12-10 10:20:31 +0100 | [diff] [blame] | 26 | import {pluralize} from '../../../utils/string-util'; |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 27 | |
Milutin Kristofic | e5c80d8 | 2022-01-18 21:22:07 +0100 | [diff] [blame] | 28 | @customElement('gr-change-list-column-requirements-summary') |
| 29 | export class GrChangeListColumnRequirementsSummary extends LitElement { |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 30 | @property({type: Object}) |
| 31 | change?: ChangeInfo; |
| 32 | |
| 33 | static override get styles() { |
| 34 | return [ |
Milutin Kristofic | b2237d6 | 2021-12-09 20:29:55 +0100 | [diff] [blame] | 35 | submitRequirementsStyles, |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 36 | css` |
| 37 | iron-icon { |
| 38 | width: var(--line-height-normal, 20px); |
| 39 | height: var(--line-height-normal, 20px); |
| 40 | vertical-align: top; |
| 41 | } |
Milutin Kristofic | 0d287ef | 2021-12-08 15:52:51 +0100 | [diff] [blame] | 42 | iron-icon.block, |
| 43 | iron-icon.check-circle-filled { |
| 44 | margin-right: var(--spacing-xs); |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 45 | } |
Milutin Kristofic | 0d287ef | 2021-12-08 15:52:51 +0100 | [diff] [blame] | 46 | iron-icon.commentIcon { |
Milutin Kristofic | 0a33f78 | 2021-12-06 13:33:51 +0100 | [diff] [blame] | 47 | color: var(--deemphasized-text-color); |
| 48 | margin-left: var(--spacing-s); |
| 49 | } |
Milutin Kristofic | 0d287ef | 2021-12-08 15:52:51 +0100 | [diff] [blame] | 50 | span { |
| 51 | line-height: var(--line-height-normal); |
| 52 | } |
| 53 | span.check-circle-filled { |
| 54 | color: var(--success-foreground); |
| 55 | } |
| 56 | .unsatisfied { |
| 57 | color: var(--primary-text-color); |
| 58 | } |
| 59 | .total { |
| 60 | margin-left: var(--spacing-xs); |
| 61 | color: var(--deemphasized-text-color); |
| 62 | } |
Milutin Kristofic | facc3c5 | 2021-12-08 20:40:38 +0100 | [diff] [blame] | 63 | :host { |
| 64 | align-items: center; |
| 65 | display: inline-flex; |
| 66 | } |
| 67 | .comma { |
| 68 | padding-right: var(--spacing-xs); |
| 69 | } |
| 70 | /* Used to hide the leading separator comma for statuses. */ |
| 71 | .comma:first-of-type { |
| 72 | display: none; |
| 73 | } |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 74 | `, |
| 75 | ]; |
| 76 | } |
| 77 | |
| 78 | override render() { |
Milutin Kristofic | facc3c5 | 2021-12-08 20:40:38 +0100 | [diff] [blame] | 79 | const commentIcon = this.renderCommentIcon(); |
| 80 | return html`${this.renderChangeStatus()} ${commentIcon}`; |
| 81 | } |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 82 | |
Milutin Kristofic | facc3c5 | 2021-12-08 20:40:38 +0100 | [diff] [blame] | 83 | renderChangeStatus() { |
| 84 | if (!this.change) return; |
| 85 | const statuses = changeStatuses(this.change); |
| 86 | if (statuses.length > 0) { |
| 87 | return statuses.map( |
| 88 | status => html` |
| 89 | <div class="comma">,</div> |
| 90 | <gr-change-status flat .status=${status}></gr-change-status> |
| 91 | ` |
| 92 | ); |
| 93 | } |
| 94 | return this.renderActiveStatus(); |
| 95 | } |
| 96 | |
| 97 | renderActiveStatus() { |
Milutin Kristofic | f611a5f | 2021-10-25 16:51:51 +0200 | [diff] [blame] | 98 | const submitRequirements = getRequirements(this.change); |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 99 | if (!submitRequirements.length) return html`n/a`; |
Milutin Kristofic | ee2aa9b | 2021-11-12 15:04:46 +0100 | [diff] [blame] | 100 | const numRequirements = submitRequirements.length; |
| 101 | const numSatisfied = submitRequirements.filter( |
Milutin Kristofic | 1839963 | 2021-11-02 12:24:38 +0100 | [diff] [blame] | 102 | req => |
| 103 | req.status === SubmitRequirementStatus.SATISFIED || |
| 104 | req.status === SubmitRequirementStatus.OVERRIDDEN |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 105 | ).length; |
| 106 | |
Milutin Kristofic | ee2aa9b | 2021-11-12 15:04:46 +0100 | [diff] [blame] | 107 | if (numSatisfied === numRequirements) { |
Milutin Kristofic | facc3c5 | 2021-12-08 20:40:38 +0100 | [diff] [blame] | 108 | return this.renderState( |
| 109 | iconForStatus(SubmitRequirementStatus.SATISFIED), |
| 110 | 'Ready' |
| 111 | ); |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 112 | } |
Milutin Kristofic | ee2aa9b | 2021-11-12 15:04:46 +0100 | [diff] [blame] | 113 | |
| 114 | const numUnsatisfied = submitRequirements.filter( |
| 115 | req => req.status === SubmitRequirementStatus.UNSATISFIED |
| 116 | ).length; |
Milutin Kristofic | 0a33f78 | 2021-12-06 13:33:51 +0100 | [diff] [blame] | 117 | |
Milutin Kristofic | facc3c5 | 2021-12-08 20:40:38 +0100 | [diff] [blame] | 118 | return this.renderState( |
Milutin Kristofic | ae44ca4 | 2021-12-03 14:29:05 +0100 | [diff] [blame] | 119 | iconForStatus(SubmitRequirementStatus.UNSATISFIED), |
Milutin Kristofic | 52b1f58 | 2021-12-06 11:01:22 +0100 | [diff] [blame] | 120 | this.renderSummary(numUnsatisfied, numRequirements) |
| 121 | ); |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 122 | } |
| 123 | |
Milutin Kristofic | 52b1f58 | 2021-12-06 11:01:22 +0100 | [diff] [blame] | 124 | renderState(icon: string, aggregation: string | TemplateResult) { |
Milutin Kristofic | 2e7966d | 2022-02-14 10:21:02 +0100 | [diff] [blame] | 125 | return html`<span class="${icon}" role="button" tabindex="0"> |
| 126 | <gr-submit-requirement-dashboard-hovercard .change=${this.change}> |
Milutin Kristofic | be90017 | 2021-10-25 13:42:58 +0200 | [diff] [blame] | 127 | </gr-submit-requirement-dashboard-hovercard> |
| 128 | <iron-icon class="${icon}" icon="gr-icons:${icon}" role="img"></iron-icon |
Milutin Kristofic | 52b1f58 | 2021-12-06 11:01:22 +0100 | [diff] [blame] | 129 | >${aggregation}</span |
| 130 | >`; |
| 131 | } |
| 132 | |
| 133 | renderSummary(numUnsatisfied: number, numRequirements: number) { |
| 134 | return html`<span |
| 135 | ><span class="unsatisfied">${numUnsatisfied}</span |
| 136 | ><span class="total">(of ${numRequirements})</span></span |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 137 | >`; |
| 138 | } |
Milutin Kristofic | 0a33f78 | 2021-12-06 13:33:51 +0100 | [diff] [blame] | 139 | |
| 140 | renderCommentIcon() { |
| 141 | if (!this.change?.unresolved_comment_count) return; |
| 142 | return html`<iron-icon |
| 143 | icon="gr-icons:comment" |
| 144 | class="commentIcon" |
Milutin Kristofic | c8b9408 | 2021-12-10 10:20:31 +0100 | [diff] [blame] | 145 | .title="${pluralize( |
| 146 | this.change?.unresolved_comment_count, |
| 147 | 'unresolved comment' |
| 148 | )}" |
Milutin Kristofic | 0a33f78 | 2021-12-06 13:33:51 +0100 | [diff] [blame] | 149 | ></iron-icon>`; |
| 150 | } |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | declare global { |
| 154 | interface HTMLElementTagNameMap { |
Milutin Kristofic | e5c80d8 | 2022-01-18 21:22:07 +0100 | [diff] [blame] | 155 | 'gr-change-list-column-requirements-summary': GrChangeListColumnRequirementsSummary; |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 156 | } |
| 157 | } |