From ad6eb3a84baf7de7c681a74065dda228498ddebe Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Wed, 22 Mar 2023 15:06:57 +0600 Subject: [PATCH] Fix filters (#2804) Signed-off-by: Denis Bykhov --- packages/query/src/index.ts | 21 +++++++++++++++++++ .../src/components/filter/ObjectFilter.svelte | 2 +- .../src/components/filter/ValueFilter.svelte | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/query/src/index.ts b/packages/query/src/index.ts index 797c9c4ca6..ee8fdf202d 100644 --- a/packages/query/src/index.ts +++ b/packages/query/src/index.ts @@ -130,6 +130,13 @@ export class LiveQuery extends TxProcessor implements Client { if (this.client.getHierarchy().getDomain(_class) === DOMAIN_MODEL) { return await this.client.findAll(_class, query, options) } + if (options?.projection !== undefined) { + options.projection = { + ...options.projection, + _class: 1, + modifiedOn: 1 + } + } const q = this.findQuery(_class, query, options) ?? this.createDumpQuery(_class, query, options) if (q.result instanceof Promise) { q.result = await q.result @@ -148,6 +155,13 @@ export class LiveQuery extends TxProcessor implements Client { if (this.client.getHierarchy().getDomain(_class) === DOMAIN_MODEL) { return await this.client.findOne(_class, query, options) } + if (options?.projection !== undefined) { + options.projection = { + ...options.projection, + _class: 1, + modifiedOn: 1 + } + } const q = this.findQuery(_class, query, options) ?? this.createDumpQuery(_class, query, options) if (q.result instanceof Promise) { q.result = await q.result @@ -255,6 +269,13 @@ export class LiveQuery extends TxProcessor implements Client { callback: (result: FindResult) => void, options?: FindOptions ): () => void { + if (options?.projection !== undefined) { + options.projection = { + ...options.projection, + _class: 1, + modifiedOn: 1 + } + } const q = this.getQuery(_class, query, callback as (result: Doc[]) => void, options) ?? this.createQuery(_class, query, callback, options) diff --git a/plugins/view-resources/src/components/filter/ObjectFilter.svelte b/plugins/view-resources/src/components/filter/ObjectFilter.svelte index 64e932ee1a..d8edb9f171 100644 --- a/plugins/view-resources/src/components/filter/ObjectFilter.svelte +++ b/plugins/view-resources/src/components/filter/ObjectFilter.svelte @@ -70,7 +70,7 @@ } targets.clear() const baseObjects = await client.findAll(filter.key._class, space ? { space } : {}, { - projection: { [filter.key.key]: 1 } + projection: { [filter.key.key]: 1, space: 1 } }) for (const object of baseObjects) { const value = getObjectValue(filter.key.key, object) ?? undefined diff --git a/plugins/view-resources/src/components/filter/ValueFilter.svelte b/plugins/view-resources/src/components/filter/ValueFilter.svelte index 26ef8c029a..ef79514d54 100644 --- a/plugins/view-resources/src/components/filter/ValueFilter.svelte +++ b/plugins/view-resources/src/components/filter/ValueFilter.svelte @@ -64,7 +64,7 @@ { ...resultQuery, ...(space ? { space } : {}) }, { sort: { [filter.key.key]: SortingOrder.Ascending }, - projection: { [prefix + filter.key.key]: 1 } + projection: { [prefix + filter.key.key]: 1, space: 1 } } ) const res = await objectsPromise