Skip to content

Commit

Permalink
fix(tags): different object types on query.pages() fails to render
Browse files Browse the repository at this point in the history
fix #59
  • Loading branch information
stdword committed Jan 2, 2025
1 parent 43916df commit 1c76ff8
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/ui/query-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ function query_table(
},
) {
let fields = opts?.fields
if (!rows || rows.length === 0 || (fields && fields.length === 0))
if (fields && fields.length === 0)
fields = undefined

if (!rows || rows.length === 0)
return html`
<div class="custom-query">
<div class="text-sm mt-2 opacity-90">No matched result</div>
Expand All @@ -140,11 +143,13 @@ function query_table(
fields = Array(first.length).fill('column ').map((x, i) => x + (i + 1))
else if (first instanceof PageContext) {
const propNames = Object.keys(first.props!)
.filter(p => p !== 'title')
fields = ['page', ...propNames]
}
else if (typeof first === 'object' && typeof first['original-name'] === 'string') {
// assume this is PageEntity
const propNames = Object.keys(first['properties-text-values']!)
.filter(p => p !== 'title')
fields = ['page', ...propNames]
}
else
Expand Down Expand Up @@ -186,6 +191,9 @@ function query_table(
if (orderByNonField)
extendedFields = extendedFields.concat(meta.order.by!)

// @ts-expect-error
const listProps = context.config._settings['property/separated-by-commas'] ?? []

if (typeof first !== 'object')
rows = rows.map(o => [o])
else {
Expand All @@ -197,9 +205,12 @@ function query_table(
if (f === 'page')
return ref(p.name)
if (propNames.includes(f)) {
// @ts-expect-error
if ((context.config._settings['property/separated-by-commas'] ?? []).includes(f))
return p.propsRefs[f].map(r => ref(r)).join(', ')
if (listProps.includes(f)) {
const value = p.propsRefs[f]
return value
? value.map(r => ref(r)).join(', ')
: value
}
return p.props[f]
}
return dev_get(context, f, p)
Expand All @@ -216,9 +227,12 @@ function query_table(
if (f === 'page')
return ref(p['original-name'])
if (propNames.includes(f)) {
// @ts-expect-error
if ((context.config._settings['property/separated-by-commas'] ?? []).includes(f))
return p['properties'][f].map(r => ref(r)).join(', ')
if (listProps.includes(f)) {
const value = p['properties'][f]
return value
? value.map(r => ref(r)).join(', ')
: value
}
return p['properties-text-values'][f]
}
return dev_get(context, f, p)
Expand Down

0 comments on commit 1c76ff8

Please sign in to comment.