diff --git a/plugins/view-resources/src/components/list/ListCategories.svelte b/plugins/view-resources/src/components/list/ListCategories.svelte index 1e316e003e..2ed26825eb 100644 --- a/plugins/view-resources/src/components/list/ListCategories.svelte +++ b/plugins/view-resources/src/components/list/ListCategories.svelte @@ -19,7 +19,15 @@ import { AnyComponent } from '@hcengineering/ui' import { AttributeModel, BuildModelKey, CategoryOption, ViewOptionModel, ViewOptions } from '@hcengineering/view' import { createEventDispatcher, onDestroy } from 'svelte' - import { buildModel, getAdditionalHeader, getCategories, getGroupByValues, getPresenter, groupBy } from '../../utils' + import { + buildModel, + concatCategories, + getAdditionalHeader, + getCategories, + getGroupByValues, + getPresenter, + groupBy + } from '../../utils' import { CategoryQuery, noCategory } from '../../viewOptions' import ListCategory from './ListCategory.svelte' @@ -85,7 +93,7 @@ const f = await getResource(categoryFunc.action) const res = hierarchy.clone(await f(_class, query, groupByKey, update, queryId, $statusStore)) if (res !== undefined) { - categories = Array.from(new Set([...categories, ...res])) + categories = concatCategories(res, categories) return } } diff --git a/plugins/view-resources/src/utils.ts b/plugins/view-resources/src/utils.ts index b96d3f5553..c841b1fec7 100644 --- a/plugins/view-resources/src/utils.ts +++ b/plugins/view-resources/src/utils.ts @@ -655,6 +655,33 @@ export async function getCategories ( ) } +export function concatCategories (arr1: CategoryType[], arr2: CategoryType[]): CategoryType[] { + const uniqueValues: Set = new Set() + const uniqueObjects: Map = new Map() + + for (const item of arr1) { + if (typeof item === 'object') { + const id = item.name + uniqueObjects.set(id, item) + } else { + uniqueValues.add(item) + } + } + + for (const item of arr2) { + if (typeof item === 'object') { + const id = item.name + if (!uniqueObjects.has(id)) { + uniqueObjects.set(id, item) + } + } else { + uniqueValues.add(item) + } + } + + return [...uniqueValues, ...uniqueObjects.values()] +} + /** * @public */ diff --git a/plugins/view-resources/src/viewOptions.ts b/plugins/view-resources/src/viewOptions.ts index b59d9df3fc..334733fb7d 100644 --- a/plugins/view-resources/src/viewOptions.ts +++ b/plugins/view-resources/src/viewOptions.ts @@ -131,16 +131,18 @@ export async function showEmptyGroups ( if (hierarchy.isDerived(attrClass, core.class.Status)) { // We do not need extensions for all status categories. - let statusList = mgr.statuses.filter((it) => { + let statusList = mgr.filter((it) => { return it.ofAttribute === attr._id }) if (query !== undefined) { - statusList = matchQuery( - statusList, - query as DocumentQuery, - _class, - hierarchy - ) as unknown as Array> + const { [key]: st, space } = query + const resQuery: DocumentQuery = { + space + } + if (st !== undefined) { + resQuery._id = st + } + statusList = matchQuery(statusList, resQuery, _class, hierarchy) as unknown as Array> } const statuses = statusList.map((it) => it._id) return await groupByCategory(client, _class, key, statuses, mgr, viewletDescriptorId)