Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 1 | // 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 | |
| 5 | import {LitElement, html, css} from 'lit-element'; |
| 6 | |
| 7 | import 'elements/chops/chops-timestamp/chops-timestamp.js'; |
| 8 | import {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 | */ |
| 17 | export 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 | } |
| 59 | customElements.define('mr-issue-slo', MrIssueSlo); |