blob: 029de6ce7b180ff43f95edba3e39dbb40a12cbd8 [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001// Copyright 2019 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';
6import {ifDefined} from 'lit-html/directives/if-defined';
7import {issueRefToString, issueRefToUrl} from 'shared/convertersV0.js';
8import {SHARED_STYLES} from 'shared/shared-styles.js';
9import '../../mr-dropdown/mr-dropdown.js';
10import '../../../help/mr-cue/mr-fed-ref-cue.js';
11
12/**
13 * `<mr-issue-link>`
14 *
15 * Displays a link to an issue.
16 *
17 */
18export class MrIssueLink extends LitElement {
19 /** @override */
20 static get styles() {
21 return [
22 SHARED_STYLES,
23 css`
24 a[is-closed] {
25 text-decoration: line-through;
26 }
27 mr-dropdown {
28 width: var(--chops-main-font-size);
29 --mr-dropdown-icon-font-size: var(--chops-main-font-size);
30 --mr-dropdown-menu-min-width: 100px;
31 }
32 `,
33 ];
34 }
35
36 /** @override */
37 render() {
38 let fedRefInfo;
39 if (this.issue && this.issue.extIdentifier) {
40 fedRefInfo = html`
41 <!-- TODO(jeffcarp): Figure out CSS to enable menuAlignment=left -->
42 <mr-dropdown
43 label="Federated Reference Info"
44 icon="info_outline"
45 menuAlignment="right"
46 >
47 <mr-fed-ref-cue
48 cuePrefName="federated_reference"
49 fedRefShortlink=${this.issue.extIdentifier}
50 nondismissible>
51 </mr-fed-ref-cue>
52 </mr-dropdown>
53 `;
54 }
55 return html`
56 <a
57 id="bugLink"
58 href=${this.href}
59 title=${ifDefined(this.issue && this.issue.summary)}
60 ?is-closed=${this.isClosed}
61 >${this._linkText}</a>${fedRefInfo}`;
62 }
63
64 /** @override */
65 static get properties() {
66 return {
67 // The issue being viewed. Falls back gracefully if this is only a ref.
68 issue: {type: Object},
69 text: {type: String},
70 // The global current project name. NOT the issue's project name.
71 projectName: {type: String},
72 queryParams: {type: Object},
73 short: {type: Boolean},
74 };
75 }
76
77 /** @override */
78 constructor() {
79 super();
80
81 this.issue = {};
82 this.queryParams = {};
83 this.short = false;
84 }
85
86 click() {
87 const link = this.shadowRoot.querySelector('a');
88 if (!link) return;
89 link.click();
90 }
91
92 /**
93 * @return {string} Where this issue links to.
94 */
95 get href() {
96 return issueRefToUrl(this.issue, this.queryParams);
97 }
98
99 get isClosed() {
100 if (!this.issue || !this.issue.statusRef) return false;
101
102 return this.issue.statusRef.meansOpen === false;
103 }
104
105 get _linkText() {
106 const {projectName, issue, text, short} = this;
107 if (text) return text;
108
109 if (issue && issue.extIdentifier) {
110 return issue.extIdentifier;
111 }
112
113 const prefix = short ? '' : 'Issue ';
114
115 return prefix + issueRefToString(issue, projectName);
116 }
117}
118
119customElements.define('mr-issue-link', MrIssueLink);