Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 1 | // 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 | |
| 5 | import {LitElement, html} from 'lit-element'; |
| 6 | |
| 7 | import 'elements/framework/links/mr-user-link/mr-user-link.js'; |
| 8 | import {fieldTypes, EMPTY_FIELD_VALUE} from 'shared/issue-fields.js'; |
| 9 | import {displayNameToUserRef} from 'shared/convertersV0.js'; |
| 10 | import {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 | */ |
| 19 | export 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}="${value}""> |
| 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 | |
| 58 | customElements.define('mr-field-values', MrFieldValues); |