Skip to content

Commit

Permalink
fix(tags): query.table corner cases
Browse files Browse the repository at this point in the history
  • Loading branch information
stdword committed Jul 22, 2024
1 parent 1a37e4c commit e9544c4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,22 +663,22 @@ export function dev_get(context: C, path: string, obj?: any): string {

if (attr === '@') {
if (!parts.length) {
obj = obj['props']
obj = obj['props'] ?? obj['properties-text-values']
continue
}

let token = parts.at(0) // @token1
const refs = obj['propsRefs'][token as string]
const refs = (obj['propsRefs'] ?? obj['properties'])[token as string]

if (refs === undefined || refs.length === 0) {
obj = obj['props']
obj = obj['props'] ?? obj['properties-text-values']
continue
}

token = parts.at(1) // @token1.token2
if (token === undefined) {
// fallback to props text values
obj = obj['props']
obj = obj['props'] ?? obj['properties-text-values']
continue
}

Expand Down
18 changes: 15 additions & 3 deletions src/ui/query-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,23 @@ function query_table(
</div>
`

if (!Array.isArray(rows)) {
if (typeof rows !== 'string' && rows[Symbol.iterator]) {
const result: any[] = []
for (const row of rows as Iterable<any>)
result.push(row)
rows = result
}
else
rows = [rows]
}

const first = rows[0]

// auto fill fields names
if (!fields) {
if (Array.isArray(first))
fields = Array(first.length).fill('field ').map((x, i) => x + (i + 1))
fields = Array(first.length).fill('column ').map((x, i) => x + (i + 1))
else if (first instanceof PageContext) {
const propNames = Object.keys(first.props!)
fields = ['page', ...propNames]
Expand All @@ -137,8 +148,9 @@ function query_table(
fields = ['page', ...propNames]
}
else
fields = []
fields = ['column']
}
fields = fields.filter(f => !!f)

let orderBy: string | undefined
if (saveState) {
Expand Down Expand Up @@ -279,7 +291,7 @@ function query_table(
function wrapRow(row) {
const index = row.at(-1)
const htmlRow = row.slice(0, -1).map(
d => `<td class="whitespace-nowrap">${dev_toHTML(context, d.toString())}</td>`
d => `<td class="whitespace-nowrap">${dev_toHTML(context, (d ?? '').toString())}</td>`
).join('\n')

return `<tr data-index="${index}">${htmlRow}</tr>`
Expand Down

0 comments on commit e9544c4

Please sign in to comment.