Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UBERF-4195: fix query after applying viewOptions #3942

Merged
merged 5 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -331,3 +331,38 @@ export class RateLimitter {
await await Promise.race(this.processingQueue.values())
}
}

export function mergeQueries<T extends Doc> (query1: DocumentQuery<T>, query2: DocumentQuery<T>): DocumentQuery<T> {
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('$')) &&
ThetaDR marked this conversation as resolved.
Show resolved Hide resolved
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
}
6 changes: 3 additions & 3 deletions plugins/task-resources/src/components/TypesView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
-->
<script lang="ts">
import { Class, Doc, DocumentQuery, Ref, Space, WithLookup } from '@hcengineering/core'
import { Class, Doc, DocumentQuery, mergeQueries, Ref, Space, WithLookup } from '@hcengineering/core'
import { IntlString, getEmbeddedLabel } from '@hcengineering/platform'
import { createQuery } from '@hcengineering/presentation'
import { Project, ProjectType, ProjectTypeCategory } from '@hcengineering/task'
Expand Down Expand Up @@ -65,7 +65,7 @@
$: spacesQ.query(task.class.Project, { type: mode as Ref<ProjectType> }, (result) => {
spaces = result
})

let resultQuery: DocumentQuery<Doc>
$: query = { ...(baseQuery ?? {}), ...(viewlet?.baseQuery ?? {}), space: { $in: spaces.map((it) => it._id) } }
$: searchQuery = search === '' ? query : { ...query, $search: search }
$: resultQuery = searchQuery
Expand Down Expand Up @@ -154,7 +154,7 @@
query={searchQuery}
{viewOptions}
on:change={(e) => {
resultQuery = { ...query, ...e.detail }
resultQuery = mergeQueries(query, e.detail)
}}
/>
<Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
DocumentUpdate,
FindOptions,
generateId,
mergeQueries,
Ref
} from '@hcengineering/core'
import { Item, Kanban as KanbanUI } from '@hcengineering/kanban'
Expand Down Expand Up @@ -87,7 +88,7 @@
}

let resultQuery: DocumentQuery<any> = { ...query }
$: getResultQuery(query, viewOptionsConfig, viewOptions).then((p) => (resultQuery = { ...p, ...query }))
$: getResultQuery(query, viewOptionsConfig, viewOptions).then((p) => (resultQuery = mergeQueries(p, query)))
ThetaDR marked this conversation as resolved.
Show resolved Hide resolved

const client = getClient()
const hierarchy = client.getHierarchy()
Expand Down
13 changes: 11 additions & 2 deletions plugins/view-resources/src/components/list/List.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@
// limitations under the License.
-->
<script lang="ts">
import core, { Class, Doc, DocumentQuery, FindOptions, Ref, Space, RateLimitter } from '@hcengineering/core'
import core, {
Class,
Doc,
DocumentQuery,
FindOptions,
Ref,
Space,
RateLimitter,
mergeQueries
} from '@hcengineering/core'
import { IntlString, getResource } from '@hcengineering/platform'
import { createQuery, getClient } from '@hcengineering/presentation'
import { AnyComponent, AnySvelteComponent } from '@hcengineering/ui'
Expand Down Expand Up @@ -59,7 +68,7 @@

let resultQuery: DocumentQuery<Doc> = query
$: getResultQuery(query, viewOptionsConfig, viewOptions).then((p) => {
resultQuery = { ...query, ...p }
resultQuery = mergeQueries(p, query) as DocumentQuery<Doc>
ThetaDR marked this conversation as resolved.
Show resolved Hide resolved
})

$: queryNoLookup = noLookup(resultQuery)
Expand Down