Skip to content

Commit c66e37a

Browse files
committed
Simplify url pattern display.
1 parent 8259c23 commit c66e37a

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

src/exceptions-table.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,43 @@ export class ExceptionsTable extends LitElement {
159159
}
160160
}
161161

162+
/**
163+
* Get the host from a URL pattern using regex.
164+
* @param urlPattern The URL pattern to get the host from.
165+
* @returns The host from the URL pattern.
166+
*/
167+
private getHostFromUrlPattern(urlPattern: string): string | null {
168+
const match = urlPattern.match(/:\/\/(?:\*\.)?([^/*]+)/);
169+
170+
if (match?.length && match.length >= 2) {
171+
return match[1];
172+
}
173+
174+
console.warn("Failed to parse host from URL pattern", urlPattern);
175+
return null;
176+
}
177+
178+
/**
179+
* Renders the URL pattern for an entry.
180+
* For simplicity we show only the host part.
181+
* The full pattern is shown on hover.
182+
* @param urlPattern The URL pattern to render.
183+
* @returns The rendered URL pattern.
184+
*/
185+
private renderUrlPattern(urlPattern?: string) {
186+
if (!urlPattern) {
187+
return html`-`;
188+
}
189+
let host = this.getHostFromUrlPattern(urlPattern);
190+
191+
// If we can't parse the host, return the original URL pattern.
192+
if (host == null) {
193+
return urlPattern;
194+
}
195+
196+
return html`<span title=${urlPattern}>${host}</span>`;
197+
}
198+
162199
private renderTable() {
163200
return html`
164201
<div class="table-container">
@@ -193,9 +230,9 @@ export class ExceptionsTable extends LitElement {
193230
: ""}
194231
</td>
195232
<td class="${this.hasGlobalRules ? "" : "hidden-col"}">
196-
${entry.topLevelUrlPattern ?? ""}
233+
${this.renderUrlPattern(entry.topLevelUrlPattern)}
197234
</td>
198-
<td>${entry.urlPattern ?? ""}</td>
235+
<td>${this.renderUrlPattern(entry.urlPattern)}</td>
199236
<td>
200237
<span class="badges">
201238
${Array.isArray(entry.classifierFeatures)

0 commit comments

Comments
 (0)