blob: 8754e8c0848e0d962f4b8303090f385ca5ad30bc [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001// Copyright 2019 The Chromium Authors
Copybara854996b2021-09-07 19:36:02 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import {LitElement, html} from 'lit-element';
6
7import {connectStore} from 'reducers/base.js';
8import * as issueV0 from 'reducers/issueV0.js';
9import './mr-phase.js';
10
11/**
12 * `<mr-launch-overview>`
13 *
14 * This is a shorthand view of the phases for a user to see a quick overview.
15 *
16 */
17export class MrLaunchOverview extends connectStore(LitElement) {
18 /** @override */
19 render() {
20 return html`
21 <link href="https://fonts.googleapis.com/icon?family=Material+Icons"
22 rel="stylesheet">
23 <style>
24 mr-launch-overview {
25 max-width: 100%;
26 display: flex;
27 flex-flow: column;
28 justify-content: flex-start;
29 align-items: stretch;
30 }
31 mr-launch-overview[hidden] {
32 display: none;
33 }
34 mr-phase {
35 margin-bottom: 0.75em;
36 }
37 </style>
38 ${this.phases.map((phase) => html`
39 <mr-phase
40 .phaseName=${phase.phaseRef.phaseName}
41 .approvals=${this._approvalsForPhase(this.approvals, phase.phaseRef.phaseName)}
42 ></mr-phase>
43 `)}
44 ${this._phaselessApprovals.length ? html`
45 <mr-phase .approvals=${this._phaselessApprovals}></mr-phase>
46 `: ''}
47 `;
48 }
49
50 /** @override */
51 static get properties() {
52 return {
53 approvals: {type: Array},
54 phases: {type: Array},
55 hidden: {
56 type: Boolean,
57 reflect: true,
58 },
59 };
60 }
61
62 /** @override */
63 createRenderRoot() {
64 return this;
65 }
66
67 /** @override */
68 constructor() {
69 super();
70 this.approvals = [];
71 this.phases = [];
72 this.hidden = true;
73 }
74
75 /** @override */
76 stateChanged(state) {
77 if (!issueV0.viewedIssue(state)) return;
78
79 this.approvals = issueV0.viewedIssue(state).approvalValues || [];
80 this.phases = issueV0.viewedIssue(state).phases || [];
81 }
82
83 /** @override */
84 update(changedProperties) {
85 if (changedProperties.has('phases') || changedProperties.has('approvals')) {
86 this.hidden = !this.phases.length && !this.approvals.length;
87 }
88 super.update(changedProperties);
89 }
90
91 get _phaselessApprovals() {
92 return this._approvalsForPhase(this.approvals);
93 }
94
95 _approvalsForPhase(approvals, phaseName) {
96 return (approvals || []).filter((a) => {
97 // We can assume phase names will be unique.
98 return a.phaseRef.phaseName == phaseName;
99 });
100 }
101}
102customElements.define('mr-launch-overview', MrLaunchOverview);