Skip to content

Commit 51be4aa

Browse files
committed
Add last modified date to exceptions tables.
- Uses dayjs for relative time labels - For top resources we use the most recent modified timestamp of all entries for the given top level site.
1 parent 51d1eb2 commit 51be4aa

File tree

5 files changed

+46
-2
lines changed

5 files changed

+46
-2
lines changed

package-lock.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
},
2323
"dependencies": {
2424
"addons-moz-compare": "^1.3.0",
25+
"dayjs": "^1.11.13",
2526
"lit": "^3.3.0",
2627
"mozjexl": "^1.1.6"
2728
}

src/components/exceptions-table/exceptions-table.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import "../bug-label";
1010
import "./exception-dialog";
1111
import { ExceptionDialog } from "./exception-dialog";
1212
import tableStyles from "./table-styles.css.ts";
13-
import { capitalizeFirstChar, renderUrlPattern } from "./utils.ts";
13+
import { capitalizeFirstChar, renderLastModified, renderUrlPattern } from "./utils.ts";
1414

1515
/**
1616
* A table component for displaying exception list entries.
@@ -123,6 +123,7 @@ export class ExceptionsTable extends LitElement {
123123
<th>Resource</th>
124124
<th>Classifier Features</th>
125125
<th>Filters</th>
126+
<th>Last Modified</th>
126127
<th>Detail</th>
127128
</tr>
128129
</thead>
@@ -151,6 +152,7 @@ export class ExceptionsTable extends LitElement {
151152
</span>
152153
</td>
153154
<td> ${this.renderFilters(entry)} </td>
155+
<td> ${renderLastModified(entry.last_modified)} </td>
154156
<td>
155157
<button @click=${() => this.onDetailClick(entry)}>{ }</button>
156158
</td>

src/components/exceptions-table/top-exceptions-table.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import "../bug-label";
1010
import "./exception-dialog";
1111
import { ExceptionDialog } from "./exception-dialog";
1212
import tableStyles from "./table-styles.css.ts";
13-
import { getHostFromUrlPattern } from "./utils.ts";
13+
import { getHostFromUrlPattern, renderLastModified } from "./utils.ts";
1414

1515
interface TopResource {
1616
host: string;
@@ -93,6 +93,15 @@ export class TopExceptionsTable extends LitElement {
9393
.sort((a, b) => b.topLevelSites.size - a.topLevelSites.size);
9494
}
9595

96+
/**
97+
* Get the most recent last modified timestamp from a list of entries.
98+
* @param entries The entries to get the most recent last modified timestamp from.
99+
* @returns The most recent last modified timestamp.
100+
*/
101+
private getMostRecentLastModified(entries: ExceptionListEntry[]): number {
102+
return Math.max(...entries.map((entry) => entry.last_modified));
103+
}
104+
96105
private renderTable() {
97106
return html`
98107
<div class="table-container">
@@ -102,6 +111,7 @@ export class TopExceptionsTable extends LitElement {
102111
<th class="compact-col">Bugs</th>
103112
<th class="compact-col"># Sites</th>
104113
<th>Resource</th>
114+
<th>Last Modified</th>
105115
<th>Detail</th>
106116
</tr>
107117
</thead>
@@ -118,6 +128,11 @@ export class TopExceptionsTable extends LitElement {
118128
</td>
119129
<td class="compact-col">${topResource.topLevelSites.size}</td>
120130
<td>${topResource.host}</td>
131+
<td
132+
>${renderLastModified(
133+
this.getMostRecentLastModified(Array.from(topResource.entries)),
134+
)}</td
135+
>
121136
<td>
122137
<button
123138
@click=${() => this.onDetailClick(Array.from(topResource.entries.values()))}

src/components/exceptions-table/utils.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
import { html } from "lit";
6+
import dayjs from "dayjs";
7+
import relativeTime from "dayjs/plugin/relativeTime";
8+
9+
// Extend dayjs with relative time plugin. This is used for the last modified
10+
// column in the exceptions tables.
11+
dayjs.extend(relativeTime);
612

713
// Common utilities for the exceptions table elements.
814

@@ -51,3 +57,16 @@ export function renderUrlPattern(urlPattern?: string) {
5157

5258
return html`<span title=${urlPattern}>${host}</span>`;
5359
}
60+
61+
/**
62+
* Renders the last modified date for an entry. Shows a relative time label
63+
* and the absolute date on hover.
64+
* @param lastModified The last modified timestamp to render. Epoch time in
65+
* milliseconds.
66+
* @returns The rendered last modified date.
67+
*/
68+
export function renderLastModified(lastModified: number) {
69+
const dateObj = dayjs(lastModified);
70+
const absoluteDate = dateObj.toDate().toLocaleString();
71+
return html`<span title="${absoluteDate}">${dateObj.fromNow()}</span>`;
72+
}

0 commit comments

Comments
 (0)