blob: ac3dc1bcea71f925a634a3abd54c0fd76e015d1c [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001// Copyright 2020 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, 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);