blob: ba68c39fc925dbeb407a7e0673d60d32f70817e2 [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} from 'lit-element';
6
7import 'elements/framework/links/mr-user-link/mr-user-link.js';
8import {fieldTypes, EMPTY_FIELD_VALUE} from 'shared/issue-fields.js';
9import {displayNameToUserRef} from 'shared/convertersV0.js';
10import {SHARED_STYLES} from 'shared/shared-styles.js';
11
12/**
13 * `<mr-field-values>`
14 *
15 * Takes in a list of field values and a single fieldDef and displays them
16 * according to their type.
17 *
18 */
19export class MrFieldValues extends LitElement {
20 /** @override */
21 static get styles() {
22 return SHARED_STYLES;
23 }
24
25 /** @override */
26 render() {
27 if (!this.values || !this.values.length) {
28 return html`${EMPTY_FIELD_VALUE}`;
29 }
30 switch (this.type) {
31 case fieldTypes.URL_TYPE:
32 return html`${this.values.map((value) => html`
33 <a href=${value} target="_blank" rel="nofollow">${value}</a>
34 `)}`;
35 case fieldTypes.USER_TYPE:
36 return html`${this.values.map((value) => html`
37 <mr-user-link .userRef=${displayNameToUserRef(value)}></mr-user-link>
38 `)}`;
39 default:
40 return html`${this.values.map((value, i) => html`
41 <a href="/p/${this.projectName}/issues/list?q=${this.name}=&quot;${value}&quot;">
42 ${value}</a>${this.values.length - 1 > i ? ', ' : ''}
43 `)}`;
44 }
45 }
46
47 /** @override */
48 static get properties() {
49 return {
50 name: {type: String},
51 type: {type: Object},
52 projectName: {type: String},
53 values: {type: Array},
54 };
55 }
56}
57
58customElements.define('mr-field-values', MrFieldValues);