Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 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 | import {ifDefined} from 'lit-html/directives/if-defined'; |
| 7 | import {issueRefToString, issueRefToUrl} from 'shared/convertersV0.js'; |
| 8 | import {SHARED_STYLES} from 'shared/shared-styles.js'; |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 9 | |
| 10 | /** |
| 11 | * `<mr-issue-link>` |
| 12 | * |
| 13 | * Displays a link to an issue. |
| 14 | * |
| 15 | */ |
| 16 | export class MrIssueLink extends LitElement { |
| 17 | /** @override */ |
| 18 | static get styles() { |
| 19 | return [ |
| 20 | SHARED_STYLES, |
| 21 | css` |
| 22 | a[is-closed] { |
| 23 | text-decoration: line-through; |
| 24 | } |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 25 | `, |
| 26 | ]; |
| 27 | } |
| 28 | |
| 29 | /** @override */ |
| 30 | render() { |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 31 | return html` |
| 32 | <a |
| 33 | id="bugLink" |
| 34 | href=${this.href} |
| 35 | title=${ifDefined(this.issue && this.issue.summary)} |
| 36 | ?is-closed=${this.isClosed} |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 37 | >${this._linkText}</a>`; |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | /** @override */ |
| 41 | static get properties() { |
| 42 | return { |
| 43 | // The issue being viewed. Falls back gracefully if this is only a ref. |
| 44 | issue: {type: Object}, |
| 45 | text: {type: String}, |
| 46 | // The global current project name. NOT the issue's project name. |
| 47 | projectName: {type: String}, |
| 48 | queryParams: {type: Object}, |
| 49 | short: {type: Boolean}, |
| 50 | }; |
| 51 | } |
| 52 | |
| 53 | /** @override */ |
| 54 | constructor() { |
| 55 | super(); |
| 56 | |
| 57 | this.issue = {}; |
| 58 | this.queryParams = {}; |
| 59 | this.short = false; |
| 60 | } |
| 61 | |
| 62 | click() { |
| 63 | const link = this.shadowRoot.querySelector('a'); |
| 64 | if (!link) return; |
| 65 | link.click(); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @return {string} Where this issue links to. |
| 70 | */ |
| 71 | get href() { |
| 72 | return issueRefToUrl(this.issue, this.queryParams); |
| 73 | } |
| 74 | |
| 75 | get isClosed() { |
| 76 | if (!this.issue || !this.issue.statusRef) return false; |
| 77 | |
| 78 | return this.issue.statusRef.meansOpen === false; |
| 79 | } |
| 80 | |
| 81 | get _linkText() { |
| 82 | const {projectName, issue, text, short} = this; |
| 83 | if (text) return text; |
| 84 | |
| 85 | if (issue && issue.extIdentifier) { |
| 86 | return issue.extIdentifier; |
| 87 | } |
| 88 | |
| 89 | const prefix = short ? '' : 'Issue '; |
| 90 | |
| 91 | return prefix + issueRefToString(issue, projectName); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | customElements.define('mr-issue-link', MrIssueLink); |