blob: dbde06138d3a00c5062490102f92e358c63fbb06 [file] [log] [blame]
Milutin Kristofic4deb19a2021-10-19 12:19:10 +02001/**
2 * @license
Ben Rohlfs94fcbbc2022-05-27 10:45:03 +02003 * Copyright 2015 Google LLC
4 * SPDX-License-Identifier: Apache-2.0
Milutin Kristofic4deb19a2021-10-19 12:19:10 +02005 */
Milutin Kristoficbe900172021-10-25 13:42:58 +02006import '../../change/gr-submit-requirement-dashboard-hovercard/gr-submit-requirement-dashboard-hovercard';
Milutin Kristoficfacc3c52021-12-08 20:40:38 +01007import '../../shared/gr-change-status/gr-change-status';
Chris Poucete690be02022-07-22 08:24:29 +02008import '../../shared/gr-icon/gr-icon';
Milutin Kristofic52b1f582021-12-06 11:01:22 +01009import {LitElement, css, html, TemplateResult} from 'lit';
Frank Borden42c1a452022-08-11 16:27:20 +020010import {customElement, property} from 'lit/decorators.js';
Milutin Kristofic4deb19a2021-10-19 12:19:10 +020011import {ChangeInfo, SubmitRequirementStatus} from '../../../api/rest-api';
Milutin Kristoficfacc3c52021-12-08 20:40:38 +010012import {changeStatuses} from '../../../utils/change-util';
Chris Poucetaf84f5a2022-07-18 10:48:30 +020013import {
14 getRequirements,
15 iconForStatus,
16 SubmitRequirementsIcon,
17} from '../../../utils/label-util';
Milutin Kristoficb2237d62021-12-09 20:29:55 +010018import {submitRequirementsStyles} from '../../../styles/gr-submit-requirements-styles';
Milutin Kristoficc8b94082021-12-10 10:20:31 +010019import {pluralize} from '../../../utils/string-util';
Milutin Kristofic4deb19a2021-10-19 12:19:10 +020020
Milutin Kristofice5c80d82022-01-18 21:22:07 +010021@customElement('gr-change-list-column-requirements-summary')
22export class GrChangeListColumnRequirementsSummary extends LitElement {
Milutin Kristofic4deb19a2021-10-19 12:19:10 +020023 @property({type: Object})
24 change?: ChangeInfo;
25
26 static override get styles() {
27 return [
Milutin Kristoficb2237d62021-12-09 20:29:55 +010028 submitRequirementsStyles,
Milutin Kristofic4deb19a2021-10-19 12:19:10 +020029 css`
Ben Rohlfs74ca3ab2022-08-31 12:33:52 +020030 :host {
31 display: inline-block;
Milutin Kristofic4deb19a2021-10-19 12:19:10 +020032 }
Ben Rohlfs74ca3ab2022-08-31 12:33:52 +020033 gr-change-status {
34 display: inline-block;
Milutin Kristofic4deb19a2021-10-19 12:19:10 +020035 }
Chris Poucete690be02022-07-22 08:24:29 +020036 gr-icon.commentIcon {
Kamil Musin31484502022-08-22 11:40:44 +020037 color: var(--warning-foreground);
Milutin Kristofic0d287ef2021-12-08 15:52:51 +010038 }
Milutin Kristofic0d287ef2021-12-08 15:52:51 +010039 .unsatisfied {
40 color: var(--primary-text-color);
41 }
Milutin Kristoficfacc3c52021-12-08 20:40:38 +010042 /* Used to hide the leading separator comma for statuses. */
43 .comma:first-of-type {
44 display: none;
45 }
Milutin Kristofic4deb19a2021-10-19 12:19:10 +020046 `,
47 ];
48 }
49
50 override render() {
Milutin Kristoficfacc3c52021-12-08 20:40:38 +010051 const commentIcon = this.renderCommentIcon();
52 return html`${this.renderChangeStatus()} ${commentIcon}`;
53 }
Milutin Kristofic4deb19a2021-10-19 12:19:10 +020054
Milutin Kristoficfacc3c52021-12-08 20:40:38 +010055 renderChangeStatus() {
56 if (!this.change) return;
57 const statuses = changeStatuses(this.change);
58 if (statuses.length > 0) {
59 return statuses.map(
Ben Rohlfs74ca3ab2022-08-31 12:33:52 +020060 status =>
61 html`<span class="comma">, </span
62 ><gr-change-status flat .status=${status}></gr-change-status>`
Milutin Kristoficfacc3c52021-12-08 20:40:38 +010063 );
64 }
65 return this.renderActiveStatus();
66 }
67
68 renderActiveStatus() {
Milutin Kristoficf611a5f2021-10-25 16:51:51 +020069 const submitRequirements = getRequirements(this.change);
Milutin Kristofic4deb19a2021-10-19 12:19:10 +020070 if (!submitRequirements.length) return html`n/a`;
Milutin Kristoficee2aa9b2021-11-12 15:04:46 +010071 const numRequirements = submitRequirements.length;
72 const numSatisfied = submitRequirements.filter(
Milutin Kristofic18399632021-11-02 12:24:38 +010073 req =>
74 req.status === SubmitRequirementStatus.SATISFIED ||
75 req.status === SubmitRequirementStatus.OVERRIDDEN
Milutin Kristofic4deb19a2021-10-19 12:19:10 +020076 ).length;
77
Milutin Kristoficee2aa9b2021-11-12 15:04:46 +010078 if (numSatisfied === numRequirements) {
Milutin Kristoficfacc3c52021-12-08 20:40:38 +010079 return this.renderState(
80 iconForStatus(SubmitRequirementStatus.SATISFIED),
81 'Ready'
82 );
Milutin Kristofic4deb19a2021-10-19 12:19:10 +020083 }
Milutin Kristoficee2aa9b2021-11-12 15:04:46 +010084
85 const numUnsatisfied = submitRequirements.filter(
86 req => req.status === SubmitRequirementStatus.UNSATISFIED
87 ).length;
Milutin Kristofic0a33f782021-12-06 13:33:51 +010088
Milutin Kristoficfacc3c52021-12-08 20:40:38 +010089 return this.renderState(
Milutin Kristoficae44ca42021-12-03 14:29:05 +010090 iconForStatus(SubmitRequirementStatus.UNSATISFIED),
Milutin Kristofic023fa472022-06-22 08:58:47 +020091 this.renderSummary(numUnsatisfied)
Milutin Kristofic52b1f582021-12-06 11:01:22 +010092 );
Milutin Kristofic4deb19a2021-10-19 12:19:10 +020093 }
94
Chris Poucetaf84f5a2022-07-18 10:48:30 +020095 renderState(
96 icon: SubmitRequirementsIcon,
97 aggregation: string | TemplateResult
98 ) {
99 return html`<span class=${icon.icon} role="button" tabindex="0">
Milutin Kristofic2e7966d2022-02-14 10:21:02 +0100100 <gr-submit-requirement-dashboard-hovercard .change=${this.change}>
Milutin Kristoficbe900172021-10-25 13:42:58 +0200101 </gr-submit-requirement-dashboard-hovercard>
Chris Poucete690be02022-07-22 08:24:29 +0200102 <gr-icon
103 class=${icon.icon}
104 icon=${icon.icon}
105 ?filled=${icon.filled}
Chris Poucetaf84f5a2022-07-18 10:48:30 +0200106 role="img"
Ben Rohlfs74ca3ab2022-08-31 12:33:52 +0200107 ></gr-icon>
108 ${aggregation}</span
Milutin Kristofic52b1f582021-12-06 11:01:22 +0100109 >`;
110 }
111
Milutin Kristofic023fa472022-06-22 08:58:47 +0200112 renderSummary(numUnsatisfied: number) {
113 return html`<span class="unsatisfied">${numUnsatisfied} missing</span>`;
Milutin Kristofic4deb19a2021-10-19 12:19:10 +0200114 }
Milutin Kristofic0a33f782021-12-06 13:33:51 +0100115
116 renderCommentIcon() {
117 if (!this.change?.unresolved_comment_count) return;
Chris Poucete690be02022-07-22 08:24:29 +0200118 return html`<gr-icon
119 class="commentIcon"
Ben Rohlfs6c15a6e2022-08-31 10:03:59 +0200120 icon="chat_bubble"
Ben Rohlfs74ca3ab2022-08-31 12:33:52 +0200121 small
Chris Poucete690be02022-07-22 08:24:29 +0200122 filled
Ben Rohlfs8003bd32022-04-05 18:24:42 +0200123 .title=${pluralize(
Milutin Kristoficc8b94082021-12-10 10:20:31 +0100124 this.change?.unresolved_comment_count,
125 'unresolved comment'
Ben Rohlfs8003bd32022-04-05 18:24:42 +0200126 )}
Chris Poucete690be02022-07-22 08:24:29 +0200127 ></gr-icon>`;
Milutin Kristofic0a33f782021-12-06 13:33:51 +0100128 }
Milutin Kristofic4deb19a2021-10-19 12:19:10 +0200129}
130
131declare global {
132 interface HTMLElementTagNameMap {
Milutin Kristofice5c80d82022-01-18 21:22:07 +0100133 'gr-change-list-column-requirements-summary': GrChangeListColumnRequirementsSummary;
Milutin Kristofic4deb19a2021-10-19 12:19:10 +0200134 }
135}