Skip to content

Commit

Permalink
TSK-1189: Fix showing all available categories (#2987)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
  • Loading branch information
haiodo authored Apr 14, 2023
1 parent db4d240 commit 4f36208
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
ActionContext,
focusStore,
getCategories,
getCategorySpaces,
getGroupByValues,
getPresenter,
groupBy,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
ActionContext,
focusStore,
getCategories,
getCategorySpaces,
getGroupByValues,
getPresenter,
groupBy,
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions plugins/view-resources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 0 additions & 8 deletions plugins/view-resources/src/viewOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4f36208

Please sign in to comment.