blob: 5fe2e2ea7593052c214a6fe4afe958971761f2aa [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 'elements/framework/mr-comment-content/mr-comment-content.js';
7import 'elements/chops/chops-timestamp/chops-timestamp.js';
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01008import {generateProjectIssueURL} from 'shared/helpers.js';
Copybara854996b2021-09-07 19:36:02 +00009/**
10 * `<mr-comment-table>`
11 *
12 * The list of comments for a Monorail Polymer profile.
13 *
14 */
15export class MrCommentTable extends LitElement {
16 /** @override */
17 static get styles() {
18 return css`
19 .ellipsis {
20 max-width: 50%;
21 text-overflow: ellipsis;
22 overflow: hidden;
23 white-space: nowrap;
24 }
25 table {
26 word-wrap: break-word;
27 width: 100%;
28 }
29 tr {
30 font-size: var(--chops-main-font-size);
31 font-weight: normal;
32 text-align: left;
33 line-height: 180%;
34 }
35 td, th {
36 border-bottom: var(--chops-normal-border);
37 padding: 0.25em 16px;
38 }
39 td {
40 text-overflow: ellipsis;
41 }
42 th {
43 text-align: left;
44 }
45 .no-wrap {
46 white-space: nowrap;
47 }
48 `;
49 }
50
51 /** @override */
52 render() {
53 const comments = this._displayedComments(this.selectedDate, this.comments);
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010054 const params = {'id': comments.localId};
Copybara854996b2021-09-07 19:36:02 +000055 // TODO(zhangtiff): render deltas for comment changes.
56 return html`
57 <table cellspacing="0" cellpadding="0">
58 <tbody>
59 <tr id="heading-row">
60 <th>Date</th>
61 <th>Project</th>
62 <th>Comment</th>
63 <th>Issue Link</th>
64 </tr>
65
66 ${comments && comments.length ? comments.map((comment) => html`
67 <tr id="row">
68 <td class="no-wrap">
69 <chops-timestamp
70 .timestamp=${comment.timestamp}
71 short
72 ></chops-timestamp>
73 </td>
74 <td>${comment.projectName}</td>
75 <td class="ellipsis">
76 <mr-comment-content
77 .content=${this._truncateMessage(comment.content)}
78 ></mr-comment-content>
79 </td>
80 <td class="no-wrap">
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010081 <a href="${generateProjectIssueURL(comment.projectName, '/detail', params)}">
Copybara854996b2021-09-07 19:36:02 +000082 Issue ${comment.localId}
83 </a>
84 </td>
85 </tr>
86 `) : html`
87 <tr>
88 <td colspan="4"><i>No comments.</i></td>
89 </tr>
90 `}
91 </tbody>
92 </table>
93 `;
94 }
95
96 /** @override */
97 static get properties() {
98 return {
99 comments: {type: Array},
100 selectedDate: {type: Number},
101 };
102 }
103
104 /** @override */
105 constructor() {
106 super();
107 this.comments = [];
108 }
109
110 _truncateMessage(message) {
111 return message && message.substring(0, message.indexOf('\n'));
112 }
113
114 _displayedComments(selectedDate, comments) {
115 if (!selectedDate) {
116 return comments;
117 } else {
118 const computedComments = [];
119 if (!comments) return computedComments;
120
121 for (let i = 0; i < comments.length; i++) {
122 if (comments[i].timestamp <= selectedDate &&
123 comments[i].timestamp >= (selectedDate - 86400)) {
124 computedComments.push(comments[i]);
125 }
126 }
127 return computedComments;
128 }
129 }
130}
131customElements.define('mr-comment-table', MrCommentTable);