From fecff25fd65454cf1baf18a9dcb54c419baf9d3d Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Sat, 15 Apr 2023 01:12:13 +0700 Subject: [PATCH] TSK-1194: Fix filter (#2990) Signed-off-by: Andrey Sobolev --- packages/presentation/src/status.ts | 2 +- .../ui/src/components/DropdownLabels.svelte | 4 +- .../src/components/filter/ObjectFilter.svelte | 11 ++- .../src/components/SpecialView.svelte | 86 +++++++++---------- 4 files changed, 50 insertions(+), 53 deletions(-) diff --git a/packages/presentation/src/status.ts b/packages/presentation/src/status.ts index bfdb337ca7..10c4681d59 100644 --- a/packages/presentation/src/status.ts +++ b/packages/presentation/src/status.ts @@ -231,7 +231,7 @@ export class StatusMiddleware extends BasePresentationMiddleware implements Pres statusFields.push(attr) const v = (query as any)[attr.name] - if (v !== undefined) { + if (v != null) { // Only add filter if we have filer inside. if (typeof v === 'string') { target.push(v as Ref) diff --git a/packages/ui/src/components/DropdownLabels.svelte b/packages/ui/src/components/DropdownLabels.svelte index 1e16582d05..5fe21f9829 100644 --- a/packages/ui/src/components/DropdownLabels.svelte +++ b/packages/ui/src/components/DropdownLabels.svelte @@ -70,7 +70,7 @@ { placeholder, items, multiselect, selected }, container, (result) => { - if (result) { + if (result != null) { if (allowDeselect && selected === result) { selected = undefined dispatch('selected', undefined) @@ -83,7 +83,7 @@ mgr?.setFocusPos(focusIndex) }, (result) => { - if (result) { + if (result != null) { selected = result dispatch('selected', result) } diff --git a/plugins/view-resources/src/components/filter/ObjectFilter.svelte b/plugins/view-resources/src/components/filter/ObjectFilter.svelte index 322053b86f..02be8c150a 100644 --- a/plugins/view-resources/src/components/filter/ObjectFilter.svelte +++ b/plugins/view-resources/src/components/filter/ObjectFilter.svelte @@ -57,11 +57,11 @@ const statuses = val const result: (Doc | undefined)[] = [] statusesCount = [] - const unique = [...new Set(val.map((v) => v?.name))] + const unique = [...new Set(val.map((v) => v?.name?.trim()?.toLocaleLowerCase()))] unique.forEach((label, i) => { let count = 0 statuses.forEach((state) => { - if (state?.name === label) { + if (state?.name?.trim()?.toLocaleLowerCase() === label?.trim()?.toLowerCase()) { if (!count) result[i] = state count += targets.get(state?._id) ?? 0 } @@ -76,7 +76,12 @@ await objectsPromise } targets.clear() - const baseObjects = await client.findAll(filter.key._class, space ? { space } : {}, { + + const spaces = ( + await client.findAll(core.class.Space, { archived: true }, { projection: { _id: 1, archived: 1, _class: 1 } }) + ).map((it) => it._id) + + const baseObjects = await client.findAll(filter.key._class, space ? { space } : { space: { $nin: spaces } }, { projection: { [filter.key.key]: 1, space: 1 } }) for (const object of baseObjects) { diff --git a/plugins/workbench-resources/src/components/SpecialView.svelte b/plugins/workbench-resources/src/components/SpecialView.svelte index d762d67e68..f87fb4db95 100644 --- a/plugins/workbench-resources/src/components/SpecialView.svelte +++ b/plugins/workbench-resources/src/components/SpecialView.svelte @@ -15,7 +15,7 @@