Fix Filter section missing attribute (#2030)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2022-06-08 10:06:50 +07:00 committed by GitHub
parent 6c739dc935
commit 88597947f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,11 +31,22 @@
let current = 0
const client = getClient()
const hierarchy = client.getHierarchy()
const targetClass = (hierarchy.getAttribute(_class, filter.key.key).type as RefTo<Doc>).to
function getTargetClass (): Ref<Class<Doc>> | undefined {
try {
return (hierarchy.getAttribute(_class, filter.key.key).type as RefTo<Doc>).to
} catch (err: any) {
console.error(err)
}
}
const targetClass = getTargetClass()
$: isState = targetClass === task.class.State ?? false
const dispatch = createEventDispatcher()
async function getCountStates (ids: Ref<Doc>[]): Promise<number> {
if (targetClass === undefined) {
return 0
}
const selectStates = await client.findAll(targetClass, { _id: { $in: Array.from(ids) } }, {})
const unique = new Set(selectStates.map((s) => (s as State).title))
return unique.size