diff --git a/plugins/view-resources/src/components/list/ListCategories.svelte b/plugins/view-resources/src/components/list/ListCategories.svelte index 27f5580f6a..117cd36b69 100644 --- a/plugins/view-resources/src/components/list/ListCategories.svelte +++ b/plugins/view-resources/src/components/list/ListCategories.svelte @@ -349,21 +349,28 @@ const listCategory: SvelteComponentTyped[] = [] const listListCategory: ListCategory[] = [] + function getGroupByKey ( + docKeys: Partial>>, + category: CategoryType, + resultQuery: DocumentQuery> + ): Partial> { + return { + ...docKeys, + [groupByKey]: + typeof category === 'object' + ? category.name !== undefined + ? { $in: category.values.flatMap((x) => x._id) } + : resultQuery[groupByKey]?.$in?.length !== 0 + ? undefined + : [] + : category + } + } {#each categories as category, i (typeof category === 'object' ? category.name : category)} {@const items = groupByKey === noCategory ? docs : getGroupByValues(groupByDocs, category)} - {@const categoryDocKeys = { - ...docKeys, - [groupByKey]: - typeof category === 'object' - ? category.name !== undefined - ? { $in: category.values.flatMap((x) => x._id) } - : resultQuery[groupByKey]?.$in?.length !== 0 - ? undefined - : [] - : category - }} + {@const categoryDocKeys = getGroupByKey(docKeys, category, resultQuery)} {#if items.length !== 0} { - // console.log('category Query', _class, { ...resultQuery, ...docKeys }) loading = docsQuery.query( _class, { ...resultQuery, ...docKeys }, (res) => { items = res loading = false - console.log({ docKeys }, res) const focusDoc = items.find((it) => it._id === $focusStore.focus?._id) if (focusDoc) { handleRowFocused(focusDoc)