Skip to content

Commit 1c76ff8

Browse files
committed
fix(tags): different object types on query.pages() fails to render
fix #59
1 parent 43916df commit 1c76ff8

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/ui/query-table.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ function query_table(
114114
},
115115
) {
116116
let fields = opts?.fields
117-
if (!rows || rows.length === 0 || (fields && fields.length === 0))
117+
if (fields && fields.length === 0)
118+
fields = undefined
119+
120+
if (!rows || rows.length === 0)
118121
return html`
119122
<div class="custom-query">
120123
<div class="text-sm mt-2 opacity-90">No matched result</div>
@@ -140,11 +143,13 @@ function query_table(
140143
fields = Array(first.length).fill('column ').map((x, i) => x + (i + 1))
141144
else if (first instanceof PageContext) {
142145
const propNames = Object.keys(first.props!)
146+
.filter(p => p !== 'title')
143147
fields = ['page', ...propNames]
144148
}
145149
else if (typeof first === 'object' && typeof first['original-name'] === 'string') {
146150
// assume this is PageEntity
147151
const propNames = Object.keys(first['properties-text-values']!)
152+
.filter(p => p !== 'title')
148153
fields = ['page', ...propNames]
149154
}
150155
else
@@ -186,6 +191,9 @@ function query_table(
186191
if (orderByNonField)
187192
extendedFields = extendedFields.concat(meta.order.by!)
188193

194+
// @ts-expect-error
195+
const listProps = context.config._settings['property/separated-by-commas'] ?? []
196+
189197
if (typeof first !== 'object')
190198
rows = rows.map(o => [o])
191199
else {
@@ -197,9 +205,12 @@ function query_table(
197205
if (f === 'page')
198206
return ref(p.name)
199207
if (propNames.includes(f)) {
200-
// @ts-expect-error
201-
if ((context.config._settings['property/separated-by-commas'] ?? []).includes(f))
202-
return p.propsRefs[f].map(r => ref(r)).join(', ')
208+
if (listProps.includes(f)) {
209+
const value = p.propsRefs[f]
210+
return value
211+
? value.map(r => ref(r)).join(', ')
212+
: value
213+
}
203214
return p.props[f]
204215
}
205216
return dev_get(context, f, p)
@@ -216,9 +227,12 @@ function query_table(
216227
if (f === 'page')
217228
return ref(p['original-name'])
218229
if (propNames.includes(f)) {
219-
// @ts-expect-error
220-
if ((context.config._settings['property/separated-by-commas'] ?? []).includes(f))
221-
return p['properties'][f].map(r => ref(r)).join(', ')
230+
if (listProps.includes(f)) {
231+
const value = p['properties'][f]
232+
return value
233+
? value.map(r => ref(r)).join(', ')
234+
: value
235+
}
222236
return p['properties-text-values'][f]
223237
}
224238
return dev_get(context, f, p)

0 commit comments

Comments
 (0)