TSK-1189: Fix showing all available categories (#2987)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2023-04-14 21:34:03 +07:00 committed by GitHub
parent db4d240f0a
commit 4f36208880
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 10 deletions

View File

@ -42,6 +42,7 @@
ActionContext,
focusStore,
getCategories,
getCategorySpaces,
getGroupByValues,
getPresenter,
groupBy,
@ -167,9 +168,15 @@
const categoryFunc = viewOption as CategoryOption
if (viewOptions[viewOption.key] ?? viewOption.defaultValue) {
const categoryAction = await getResource(categoryFunc.action)
const spaces = getCategorySpaces(categories)
if (space !== undefined) {
spaces.push(space)
}
const res = await categoryAction(
_class,
space ? { space } : {},
spaces.length > 0 ? { space: { $in: Array.from(spaces.values()) } } : {},
groupByKey,
update,
queryId,

View File

@ -55,6 +55,7 @@
ActionContext,
focusStore,
getCategories,
getCategorySpaces,
getGroupByValues,
getPresenter,
groupBy,
@ -193,9 +194,14 @@
const categoryFunc = viewOption as CategoryOption
if (viewOptions[viewOption.key] ?? viewOption.defaultValue) {
const categoryAction = await getResource(categoryFunc.action)
const spaces = getCategorySpaces(categories)
if (space !== undefined) {
spaces.push(space)
}
const res = await categoryAction(
_class,
space !== undefined ? { space } : {},
spaces.length > 0 ? { space: { $in: Array.from(spaces.values()) } } : {},
groupByKey,
update,
queryId,

View File

@ -647,6 +647,18 @@ export async function getCategories (
)
}
/**
* @public
*/
export function getCategorySpaces (categories: CategoryType[]): Array<Ref<Space>> {
return Array.from(
(categories.filter((it) => typeof it === 'object') as StatusValue[]).reduce<Set<Ref<Space>>>((arr, val) => {
val.values.forEach((it) => arr.add(it.space))
return arr
}, new Set())
)
}
export function concatCategories (arr1: CategoryType[], arr2: CategoryType[]): CategoryType[] {
const uniqueValues: Set<string | number | undefined> = new Set()
const uniqueObjects: Map<string | number, StatusValue> = new Map()

View File

@ -139,14 +139,6 @@ export async function showEmptyGroups (
const resQuery: DocumentQuery<Status> = {}
if (space !== undefined) {
resQuery.space = space
} else {
const spaceRefs = Array.from(new Set(statusList.map((p) => p.space)))
const spaces = await client.findAll(
core.class.Space,
{ _id: { $in: spaceRefs }, archived: false },
{ projection: { _id: 1 } }
)
resQuery.space = { $in: spaces.map((p) => p._id) }
}
if (st !== undefined) {
resQuery._id = st