blob: 5a3e42cf462ae0c0b0e64c707b2745dfe2effb99 [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001// Copyright 2020 The Chromium Authors. All rights reserved.
2// 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, css} from 'lit-element';
6
7import 'elements/chops/chops-timestamp/chops-timestamp.js';
8import {determineSloStatus} from './slo-rules.js';
9
10/** @typedef {import('./slo-rules.js').SloStatus} SloStatus */
11
12/**
13 * `<mr-issue-slo>`
14 *
15 * A widget for showing the given issue's SLO status.
16 */
17export class MrIssueSlo extends LitElement {
18 /** @override */
19 static get styles() {
20 return css``;
21 }
22
23 /** @override */
24 render() {
25 const sloStatus = this._determineSloStatus();
26 if (!sloStatus) {
27 return html`N/A`;
28 }
29 if (!sloStatus.target) {
30 return html`Done`;
31 }
32 return html`
33 <chops-timestamp .timestamp=${sloStatus.target} short></chops-timestamp>`;
34 }
35
36 /**
37 * Wrapper around slo-rules.js determineSloStatus to allow tests to override
38 * the return value.
39 * @private
40 * @return {SloStatus}
41 */
42 _determineSloStatus() {
43 return this.issue ? determineSloStatus(this.issue) : null;
44 }
45
46 /** @override */
47 static get properties() {
48 return {
49 issue: {type: Object},
50 };
51 }
52 /** @override */
53 constructor() {
54 super();
55 /** @type {Issue} */
56 this.issue;
57 }
58}
59customElements.define('mr-issue-slo', MrIssueSlo);