Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [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 |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 5 | */ |
Milutin Kristofic | be90017 | 2021-10-25 13:42:58 +0200 | [diff] [blame] | 6 | import '../../change/gr-submit-requirement-dashboard-hovercard/gr-submit-requirement-dashboard-hovercard'; |
Milutin Kristofic | facc3c5 | 2021-12-08 20:40:38 +0100 | [diff] [blame] | 7 | import '../../shared/gr-change-status/gr-change-status'; |
Chris Poucet | e690be0 | 2022-07-22 08:24:29 +0200 | [diff] [blame] | 8 | import '../../shared/gr-icon/gr-icon'; |
Milutin Kristofic | 52b1f58 | 2021-12-06 11:01:22 +0100 | [diff] [blame] | 9 | import {LitElement, css, html, TemplateResult} from 'lit'; |
Frank Borden | 42c1a45 | 2022-08-11 16:27:20 +0200 | [diff] [blame] | 10 | import {customElement, property} from 'lit/decorators.js'; |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 11 | import {ChangeInfo, SubmitRequirementStatus} from '../../../api/rest-api'; |
Milutin Kristofic | facc3c5 | 2021-12-08 20:40:38 +0100 | [diff] [blame] | 12 | import {changeStatuses} from '../../../utils/change-util'; |
Chris Poucet | af84f5a | 2022-07-18 10:48:30 +0200 | [diff] [blame] | 13 | import { |
| 14 | getRequirements, |
| 15 | iconForStatus, |
| 16 | SubmitRequirementsIcon, |
| 17 | } from '../../../utils/label-util'; |
Milutin Kristofic | b2237d6 | 2021-12-09 20:29:55 +0100 | [diff] [blame] | 18 | import {submitRequirementsStyles} from '../../../styles/gr-submit-requirements-styles'; |
Milutin Kristofic | c8b9408 | 2021-12-10 10:20:31 +0100 | [diff] [blame] | 19 | import {pluralize} from '../../../utils/string-util'; |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 20 | |
Milutin Kristofic | e5c80d8 | 2022-01-18 21:22:07 +0100 | [diff] [blame] | 21 | @customElement('gr-change-list-column-requirements-summary') |
| 22 | export class GrChangeListColumnRequirementsSummary extends LitElement { |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 23 | @property({type: Object}) |
| 24 | change?: ChangeInfo; |
| 25 | |
| 26 | static override get styles() { |
| 27 | return [ |
Milutin Kristofic | b2237d6 | 2021-12-09 20:29:55 +0100 | [diff] [blame] | 28 | submitRequirementsStyles, |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 29 | css` |
Ben Rohlfs | 74ca3ab | 2022-08-31 12:33:52 +0200 | [diff] [blame] | 30 | :host { |
| 31 | display: inline-block; |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 32 | } |
Ben Rohlfs | 74ca3ab | 2022-08-31 12:33:52 +0200 | [diff] [blame] | 33 | gr-change-status { |
| 34 | display: inline-block; |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 35 | } |
Chris Poucet | e690be0 | 2022-07-22 08:24:29 +0200 | [diff] [blame] | 36 | gr-icon.commentIcon { |
Kamil Musin | 3148450 | 2022-08-22 11:40:44 +0200 | [diff] [blame] | 37 | color: var(--warning-foreground); |
Milutin Kristofic | 0d287ef | 2021-12-08 15:52:51 +0100 | [diff] [blame] | 38 | } |
Milutin Kristofic | 0d287ef | 2021-12-08 15:52:51 +0100 | [diff] [blame] | 39 | .unsatisfied { |
| 40 | color: var(--primary-text-color); |
| 41 | } |
Milutin Kristofic | facc3c5 | 2021-12-08 20:40:38 +0100 | [diff] [blame] | 42 | /* Used to hide the leading separator comma for statuses. */ |
| 43 | .comma:first-of-type { |
| 44 | display: none; |
| 45 | } |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 46 | `, |
| 47 | ]; |
| 48 | } |
| 49 | |
| 50 | override render() { |
Milutin Kristofic | facc3c5 | 2021-12-08 20:40:38 +0100 | [diff] [blame] | 51 | const commentIcon = this.renderCommentIcon(); |
| 52 | return html`${this.renderChangeStatus()} ${commentIcon}`; |
| 53 | } |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 54 | |
Milutin Kristofic | facc3c5 | 2021-12-08 20:40:38 +0100 | [diff] [blame] | 55 | renderChangeStatus() { |
| 56 | if (!this.change) return; |
| 57 | const statuses = changeStatuses(this.change); |
| 58 | if (statuses.length > 0) { |
| 59 | return statuses.map( |
Ben Rohlfs | 74ca3ab | 2022-08-31 12:33:52 +0200 | [diff] [blame] | 60 | status => |
| 61 | html`<span class="comma">, </span |
| 62 | ><gr-change-status flat .status=${status}></gr-change-status>` |
Milutin Kristofic | facc3c5 | 2021-12-08 20:40:38 +0100 | [diff] [blame] | 63 | ); |
| 64 | } |
| 65 | return this.renderActiveStatus(); |
| 66 | } |
| 67 | |
| 68 | renderActiveStatus() { |
Milutin Kristofic | f611a5f | 2021-10-25 16:51:51 +0200 | [diff] [blame] | 69 | const submitRequirements = getRequirements(this.change); |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 70 | if (!submitRequirements.length) return html`n/a`; |
Milutin Kristofic | ee2aa9b | 2021-11-12 15:04:46 +0100 | [diff] [blame] | 71 | const numRequirements = submitRequirements.length; |
| 72 | const numSatisfied = submitRequirements.filter( |
Milutin Kristofic | 1839963 | 2021-11-02 12:24:38 +0100 | [diff] [blame] | 73 | req => |
| 74 | req.status === SubmitRequirementStatus.SATISFIED || |
| 75 | req.status === SubmitRequirementStatus.OVERRIDDEN |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 76 | ).length; |
| 77 | |
Milutin Kristofic | ee2aa9b | 2021-11-12 15:04:46 +0100 | [diff] [blame] | 78 | if (numSatisfied === numRequirements) { |
Milutin Kristofic | facc3c5 | 2021-12-08 20:40:38 +0100 | [diff] [blame] | 79 | return this.renderState( |
| 80 | iconForStatus(SubmitRequirementStatus.SATISFIED), |
| 81 | 'Ready' |
| 82 | ); |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 83 | } |
Milutin Kristofic | ee2aa9b | 2021-11-12 15:04:46 +0100 | [diff] [blame] | 84 | |
| 85 | const numUnsatisfied = submitRequirements.filter( |
| 86 | req => req.status === SubmitRequirementStatus.UNSATISFIED |
| 87 | ).length; |
Milutin Kristofic | 0a33f78 | 2021-12-06 13:33:51 +0100 | [diff] [blame] | 88 | |
Milutin Kristofic | facc3c5 | 2021-12-08 20:40:38 +0100 | [diff] [blame] | 89 | return this.renderState( |
Milutin Kristofic | ae44ca4 | 2021-12-03 14:29:05 +0100 | [diff] [blame] | 90 | iconForStatus(SubmitRequirementStatus.UNSATISFIED), |
Milutin Kristofic | 023fa47 | 2022-06-22 08:58:47 +0200 | [diff] [blame] | 91 | this.renderSummary(numUnsatisfied) |
Milutin Kristofic | 52b1f58 | 2021-12-06 11:01:22 +0100 | [diff] [blame] | 92 | ); |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 93 | } |
| 94 | |
Chris Poucet | af84f5a | 2022-07-18 10:48:30 +0200 | [diff] [blame] | 95 | renderState( |
| 96 | icon: SubmitRequirementsIcon, |
| 97 | aggregation: string | TemplateResult |
| 98 | ) { |
| 99 | return html`<span class=${icon.icon} role="button" tabindex="0"> |
Milutin Kristofic | 2e7966d | 2022-02-14 10:21:02 +0100 | [diff] [blame] | 100 | <gr-submit-requirement-dashboard-hovercard .change=${this.change}> |
Milutin Kristofic | be90017 | 2021-10-25 13:42:58 +0200 | [diff] [blame] | 101 | </gr-submit-requirement-dashboard-hovercard> |
Chris Poucet | e690be0 | 2022-07-22 08:24:29 +0200 | [diff] [blame] | 102 | <gr-icon |
| 103 | class=${icon.icon} |
| 104 | icon=${icon.icon} |
| 105 | ?filled=${icon.filled} |
Chris Poucet | af84f5a | 2022-07-18 10:48:30 +0200 | [diff] [blame] | 106 | role="img" |
Ben Rohlfs | 74ca3ab | 2022-08-31 12:33:52 +0200 | [diff] [blame] | 107 | ></gr-icon> |
| 108 | ${aggregation}</span |
Milutin Kristofic | 52b1f58 | 2021-12-06 11:01:22 +0100 | [diff] [blame] | 109 | >`; |
| 110 | } |
| 111 | |
Milutin Kristofic | 023fa47 | 2022-06-22 08:58:47 +0200 | [diff] [blame] | 112 | renderSummary(numUnsatisfied: number) { |
| 113 | return html`<span class="unsatisfied">${numUnsatisfied} missing</span>`; |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 114 | } |
Milutin Kristofic | 0a33f78 | 2021-12-06 13:33:51 +0100 | [diff] [blame] | 115 | |
| 116 | renderCommentIcon() { |
| 117 | if (!this.change?.unresolved_comment_count) return; |
Chris Poucet | e690be0 | 2022-07-22 08:24:29 +0200 | [diff] [blame] | 118 | return html`<gr-icon |
| 119 | class="commentIcon" |
Ben Rohlfs | 6c15a6e | 2022-08-31 10:03:59 +0200 | [diff] [blame] | 120 | icon="chat_bubble" |
Ben Rohlfs | 74ca3ab | 2022-08-31 12:33:52 +0200 | [diff] [blame] | 121 | small |
Chris Poucet | e690be0 | 2022-07-22 08:24:29 +0200 | [diff] [blame] | 122 | filled |
Ben Rohlfs | 8003bd3 | 2022-04-05 18:24:42 +0200 | [diff] [blame] | 123 | .title=${pluralize( |
Milutin Kristofic | c8b9408 | 2021-12-10 10:20:31 +0100 | [diff] [blame] | 124 | this.change?.unresolved_comment_count, |
| 125 | 'unresolved comment' |
Ben Rohlfs | 8003bd3 | 2022-04-05 18:24:42 +0200 | [diff] [blame] | 126 | )} |
Chris Poucet | e690be0 | 2022-07-22 08:24:29 +0200 | [diff] [blame] | 127 | ></gr-icon>`; |
Milutin Kristofic | 0a33f78 | 2021-12-06 13:33:51 +0100 | [diff] [blame] | 128 | } |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | declare global { |
| 132 | interface HTMLElementTagNameMap { |
Milutin Kristofic | e5c80d8 | 2022-01-18 21:22:07 +0100 | [diff] [blame] | 133 | 'gr-change-list-column-requirements-summary': GrChangeListColumnRequirementsSummary; |
Milutin Kristofic | 4deb19a | 2021-10-19 12:19:10 +0200 | [diff] [blame] | 134 | } |
| 135 | } |