From 0f7ddbb22a1b5a0a4575ee88c45d139d00f1fec9 Mon Sep 17 00:00:00 2001 From: Vyacheslav Tumanov Date: Mon, 6 Nov 2023 17:48:13 +0500 Subject: [PATCH 1/5] UBERF-4195: fix query after applying viewOptions Signed-off-by: Vyacheslav Tumanov --- plugins/view-resources/src/components/list/List.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/view-resources/src/components/list/List.svelte b/plugins/view-resources/src/components/list/List.svelte index aecf8464369..2089f708fb6 100644 --- a/plugins/view-resources/src/components/list/List.svelte +++ b/plugins/view-resources/src/components/list/List.svelte @@ -59,7 +59,7 @@ let resultQuery: DocumentQuery = query $: getResultQuery(query, viewOptionsConfig, viewOptions).then((p) => { - resultQuery = { ...query, ...p } + resultQuery = { ...p, ...query } }) $: queryNoLookup = noLookup(resultQuery) From d80ad60003cd023ded442d7bb7392445eac589e1 Mon Sep 17 00:00:00 2001 From: Vyacheslav Tumanov Date: Tue, 7 Nov 2023 21:47:19 +0500 Subject: [PATCH 2/5] UBERF-4195: function for merging queries Signed-off-by: Vyacheslav Tumanov --- packages/core/src/utils.ts | 37 ++++++++++++++++++- .../src/components/TypesView.svelte | 6 +-- .../src/components/kanban/KanbanView.svelte | 3 +- .../src/components/list/List.svelte | 13 ++++++- 4 files changed, 52 insertions(+), 7 deletions(-) diff --git a/packages/core/src/utils.ts b/packages/core/src/utils.ts index 6f6923327d1..b07de1bb8f2 100644 --- a/packages/core/src/utils.ts +++ b/packages/core/src/utils.ts @@ -16,7 +16,7 @@ import { Account, AnyAttribute, Class, Doc, DocData, DocIndexState, IndexKind, Obj, Ref, Space } from './classes' import core from './component' import { Hierarchy } from './hierarchy' -import { FindResult } from './storage' +import { DocumentQuery, FindResult } from './storage' function toHex (value: number, chars: number): string { const result = value.toString(16) @@ -331,3 +331,38 @@ export class RateLimitter { await await Promise.race(this.processingQueue.values()) } } + +export function mergeQueries (query1: DocumentQuery, query2: DocumentQuery): DocumentQuery { + const q = { ...query1 } + for (const k in query2) { + if ( + typeof query2[k] === 'object' && + typeof query1[k] === 'object' && + Object.keys(query2[k]).every((t) => t.startsWith('$')) && + Object.keys(query1[k]).every((t) => t.startsWith('$')) + ) { + for (const x in query2[k]) { + if (x === '$in') { + q[k][x] = + query1[k][x].length - query2[k][x].length < 0 + ? query2[k][x].filter((c: any) => query1[k][x].includes(c)) + : query1[k][x].filter((c: any) => query2[k][x].includes(c)) + continue + } + if (x === '$nin') { + q[k][x] = [...query1[k][x], ...query2[k][x]] + continue + } + if (x === '$lt') { + q[k][x] = query1[k][x] < query2[k][x] ? query1[k][x] : query2[k][x] + continue + } + if (x === '$gt') { + q[k][x] = query1[k][x] > query2[k][x] ? query1[k][x] : query2[k][x] + } + } + } + if (!Object.keys(query1).includes(k)) Object.assign(q[k], query2[k]) + } + return q +} diff --git a/plugins/task-resources/src/components/TypesView.svelte b/plugins/task-resources/src/components/TypesView.svelte index 13c337f4b6c..20caea131d5 100644 --- a/plugins/task-resources/src/components/TypesView.svelte +++ b/plugins/task-resources/src/components/TypesView.svelte @@ -13,7 +13,7 @@ // limitations under the License. -->