Skip to content

Commit 30b63ac

Browse files
committed
Updated displaying command logs entries in UI
1 parent d36a09b commit 30b63ac

File tree

1 file changed

+33
-14
lines changed
  • packages/app/src/components/workbench

1 file changed

+33
-14
lines changed

packages/app/src/components/workbench/list.ts

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class DevtoolsList extends Element {
1414
label = ''
1515

1616
@property({ type: Object })
17-
list: Record<string, any> | string[] = {}
17+
list: Record<string, unknown> | unknown[] = {}
1818

1919
static styles = [...Element.styles, css`
2020
:host {
@@ -85,34 +85,53 @@ export class DevtoolsList extends Element {
8585
}
8686

8787
render () {
88-
if (!this.list || Object.keys(this.list).length === 0) {
89-
return null
90-
}
88+
const isArrayList = Array.isArray(this.list)
89+
90+
if (this.list == null) return null
91+
if (isArrayList && (this.list as unknown[]).length === 0) return null
92+
if (!isArrayList && Object.keys(this.list as Record<string, unknown>).length === 0) return null
93+
94+
const entries: unknown[] | [string, unknown][] = isArrayList
95+
? (this.list as unknown[])
96+
: Object.entries(this.list as Record<string, unknown>)
9197

92-
const entries = Array.isArray(this.list)
93-
? this.list as string[]
94-
: Object.entries(this.list)
98+
const isKeyValueTuple = (val: unknown): val is [string, unknown] =>
99+
Array.isArray(val) && val.length === 2 && typeof val[0] === 'string'
95100

96101
return html`
97102
<section class="block">
98103
${this.#renderSectionHeader(this.label)}
99104
<dl class="flex flex-wrap ${this.isCollapsed ? '' : 'mt-2'}">
100-
${entries.map((entry, i) => {
101-
const isStringEntry = typeof entry === 'string'
102-
const key = isStringEntry ? undefined : (entry as [string, any])[0]
103-
const val = isStringEntry ? entry : (entry as [string, any])[1]
105+
${(entries as any[]).map((entry, i) => {
106+
let key: string | undefined
107+
let val: unknown
108+
109+
if (isArrayList) {
110+
if (isKeyValueTuple(entry)) {
111+
key = entry[0]
112+
val = entry[1]
113+
} else {
114+
val = entry
115+
}
116+
} else {
117+
key = (entry as [string, unknown])[0]
118+
val = (entry as [string, unknown])[1]
119+
}
104120
105-
const stringForMeasure = typeof val === 'object' && val !== null
121+
const stringForMeasure = (val && typeof val === 'object')
106122
? JSON.stringify(val, null, 2)
107123
: String(val)
108124
109-
const isMultiline = /\n/.test(stringForMeasure) || stringForMeasure.length > 40 || typeof val === 'object'
125+
const isMultiline = /\n/.test(stringForMeasure) ||
126+
stringForMeasure.length > 40 ||
127+
(val && typeof val === 'object')
128+
110129
const baseCls = 'row px-2 py-1 border-b-[1px] border-b-panelBorder'
111130
const colCls = isMultiline ? 'basis-full w-full' : 'basis-1/2'
112131
const lastBorderFix = i === entries.length - 1 ? '' : ''
113132
const collapsedCls = this.isCollapsed ? 'collapse' : 'max-h-[500px]'
114133
115-
if (isStringEntry) {
134+
if (key === undefined) {
116135
return html`
117136
<dd class="${baseCls} ${colCls} ${collapsedCls} ${lastBorderFix}">
118137
${this.#renderMetadataProp(val)}

0 commit comments

Comments
 (0)