From 270e1343590da86326ba6ee7503961573679ce39 Mon Sep 17 00:00:00 2001 From: sua yoo Date: Tue, 15 Aug 2023 21:14:08 -0700 Subject: [PATCH] Show details in crawl error log (#1079) Shows crawl error log details in a dialog. Since the detail object does not always follow a specific format, this iteration uses the detail key in uppercase as the label. --- frontend/src/components/crawl-logs.ts | 89 +++++++++++++++++++++--- frontend/src/components/numbered-list.ts | 20 +++++- 2 files changed, 100 insertions(+), 9 deletions(-) diff --git a/frontend/src/components/crawl-logs.ts b/frontend/src/components/crawl-logs.ts index 93045a4f..81e20a29 100644 --- a/frontend/src/components/crawl-logs.ts +++ b/frontend/src/components/crawl-logs.ts @@ -25,9 +25,8 @@ export class CrawlLogs extends LitElement { .row { display: grid; - grid-template-columns: 9rem 4rem 14rem 1fr; + grid-template-columns: 9rem 4rem 15rem 1fr; line-height: 1.3; - max-width: 800px; } .cell { @@ -61,12 +60,37 @@ export class CrawlLogs extends LitElement { overflow: hidden; white-space: nowrap; } + + a { + color: inherit; + } + + a:hover { + text-decoration: none; + } + + pre { + white-space: pre-wrap; + font-family: var(--sl-font-mono); + font-size: var(--sl-font-size-x-small); + margin: 0; + padding: var(--sl-spacing-small); + border: 1px solid var(--sl-panel-border-color); + border-radius: var(--sl-border-radius-medium); + } `, ]; @property({ type: Object }) logs?: APIPaginatedList; + @state() + private selectedLog: + | (CrawlLog & { + index: number; + }) + | null = null; + render() { if (!this.logs) return; return html` @@ -78,9 +102,21 @@ export class CrawlLogs extends LitElement {
${msg("Page URL")}
- ${this.logs.items.map( - (log: CrawlLog, idx) => html` - + ${this.logs.items.map((log: CrawlLog, idx) => { + const selected = this.selectedLog?.index === idx; + return html` + { + this.selectedLog = { + index: idx, + ...log, + }; + }} + > +
${idx + 1}.
- ` - )} + `; + })}
-
`; + + (this.selectedLog = null)} + >${this.renderLogDetails()} `; + } + + private renderLogDetails() { + if (!this.selectedLog) return; + const { details } = this.selectedLog; + return html` + + + ${this.selectedLog.timestamp} + + ${Object.entries(details).map( + ([key, value]) => html` + + ${key === "stack" || + (typeof value !== "string" && typeof value !== "number") + ? this.renderPre(value) + : value ?? "--"} + + ` + )} + + `; + } + + private renderPre(value: any) { + let str = value; + if (typeof value !== "string") { + str = JSON.stringify(value, null, 2); + } + return html`
${str}
`; } } diff --git a/frontend/src/components/numbered-list.ts b/frontend/src/components/numbered-list.ts index 92ab93c6..7cf158f2 100644 --- a/frontend/src/components/numbered-list.ts +++ b/frontend/src/components/numbered-list.ts @@ -24,6 +24,12 @@ export class NumberedListItem extends LitElement { @property({ type: Boolean }) isEven: boolean = false; + @property({ type: Boolean }) + selected: boolean = false; + + @property({ type: Boolean }) + hoverable: boolean = false; + static styles = css` :host, .item { @@ -65,7 +71,17 @@ export class NumberedListItem extends LitElement { } .item.even .content { - background-color: var(--sl-color-neutral-50); */ + background-color: var(--sl-color-neutral-50); + } + + .item.hoverable { + cursor: pointer; + } + + .item.selected .content, + .item.hoverable:hover .content { + background-color: var(--sl-color-blue-500); + color: var(--sl-color-neutral-0); } `; @@ -77,6 +93,8 @@ export class NumberedListItem extends LitElement { first: this.isFirst, last: this.isLast, even: this.isEven, + selected: this.selected, + hoverable: this.hoverable, })} >