blob: 0aaa998dd25a4be83b2e09197786d6d429fdc82c [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, css} from 'lit-element';
6import {ifDefined} from 'lit-html/directives/if-defined';
7import {issueRefToString, issueRefToUrl} from 'shared/convertersV0.js';
8import {SHARED_STYLES} from 'shared/shared-styles.js';
Copybara854996b2021-09-07 19:36:02 +00009
10/**
11 * `<mr-issue-link>`
12 *
13 * Displays a link to an issue.
14 *
15 */
16export 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 }
Copybara854996b2021-09-07 19:36:02 +000025 `,
26 ];
27 }
28
29 /** @override */
30 render() {
Copybara854996b2021-09-07 19:36:02 +000031 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ínezf19ea432024-01-23 20:20:52 +010037 >${this._linkText}</a>`;
Copybara854996b2021-09-07 19:36:02 +000038 }
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
95customElements.define('mr-issue-link', MrIssueLink);