Skip to content

Commit

Permalink
UBERF-9568: Fix person space filter (#8183)
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Savchenko <[email protected]>
  • Loading branch information
ArtyomSavchenko authored Mar 10, 2025
1 parent b2e15df commit 4407b36
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 122 deletions.
9 changes: 2 additions & 7 deletions models/my-space/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export function createModel (builder: Builder): void {
alias: mySpaceId,
accessLevel: AccountRole.User,
hidden: false,
locationResolver: mySpace.resolver.Location,
navigatorModel: {
spaces: [],
specials: [
Expand All @@ -48,13 +47,9 @@ export function createModel (builder: Builder): void {
componentProps: {
_class: mail.class.MailThread,
icon: mySpace.icon.Mail,
label: mySpace.string.Mail,
createLabel: mail.string.CreateMail,
createComponent: mail.component.CreateMail
label: mySpace.string.Mail
},
queryOptions: {
filterBySpace: true
}
queryBuilder: mySpace.functions.BuildQuery
}
]
}
Expand Down
6 changes: 3 additions & 3 deletions plugins/my-space-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
//

import { type Resources } from '@hcengineering/platform'
import { resolveLocation } from './navigation'

import { buildPersonSpaceQuery } from './utils'
export { default as plugin } from './plugin'

export default async (): Promise<Resources> => ({
component: {},
resolver: {
Location: resolveLocation
functions: {
BuildQuery: buildPersonSpaceQuery
}
})
87 changes: 0 additions & 87 deletions plugins/my-space-resources/src/navigation.ts

This file was deleted.

28 changes: 28 additions & 0 deletions plugins/my-space-resources/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Copyright © 2025 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//

import type { Doc, DocumentQuery } from '@hcengineering/core'
import { getClient } from '@hcengineering/presentation'
import contact, { getCurrentEmployee } from '@hcengineering/contact'

export async function buildPersonSpaceQuery (): Promise<DocumentQuery<Doc>> {
const client = getClient()
const employee = getCurrentEmployee()
if (employee === undefined) {
return { space: undefined }
}
const space = await client.findOne(contact.class.PersonSpace, { person: employee }, { projection: { _id: 1 } })
return space?._id !== undefined ? { space: space._id } : {}
}
3 changes: 1 addition & 2 deletions plugins/my-space/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
},
"dependencies": {
"@hcengineering/core": "^0.6.32",
"@hcengineering/platform": "^0.6.11",
"@hcengineering/ui": "^0.6.15"
"@hcengineering/platform": "^0.6.11"
},
"repository": "https://github.com/hcengineering/platform",
"publishConfig": {
Expand Down
7 changes: 3 additions & 4 deletions plugins/my-space/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
// limitations under the License.
//

import { type Doc, type Ref, type SpaceTypeDescriptor } from '@hcengineering/core'
import { DocumentQuery, type Doc, type Ref, type SpaceTypeDescriptor } from '@hcengineering/core'
import type { Asset, IntlString, Plugin, Resource } from '@hcengineering/platform'
import { type Location, type ResolvedLocation } from '@hcengineering/ui'

import { plugin } from '@hcengineering/platform'

Expand All @@ -41,8 +40,8 @@ export const mySpacePlugin = plugin(mySpaceId, {
ConfigDescription: '' as IntlString,
Mail: '' as IntlString
},
resolver: {
Location: '' as Resource<(loc: Location) => Promise<ResolvedLocation | undefined>>
functions: {
BuildQuery: '' as Resource<() => Promise<DocumentQuery<Doc>>>
}
})

Expand Down
34 changes: 24 additions & 10 deletions plugins/workbench-resources/src/components/SpecialView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
-->
<script lang="ts">
import { Class, Doc, DocumentQuery, FindOptions, Ref, Space, WithLookup, mergeQueries } from '@hcengineering/core'
import { Asset, IntlString } from '@hcengineering/platform'
import { Asset, getResource, IntlString, Resource } from '@hcengineering/platform'
import { getClient } from '@hcengineering/presentation'
import {
AnyComponent,
Expand All @@ -38,7 +38,7 @@
ViewletSelector,
ViewletSettingButton
} from '@hcengineering/view-resources'
import { QueryOptions, ParentsNavigationModel } from '@hcengineering/workbench'
import { ParentsNavigationModel } from '@hcengineering/workbench'
import ComponentNavigator from './ComponentNavigator.svelte'
Expand All @@ -56,7 +56,7 @@
export let baseQuery: DocumentQuery<Doc> | undefined = undefined
export let modes: IModeSelector<any> | undefined = undefined
export let navigationModel: ParentsNavigationModel | undefined = undefined
export let queryOptions: QueryOptions | undefined = undefined
export let queryBuilder: Resource<() => Promise<DocumentQuery<Doc>>> | undefined = undefined
const client = getClient()
const hierarchy = client.getHierarchy()
Expand All @@ -69,15 +69,16 @@
let viewlets: Array<WithLookup<Viewlet>> = []
let viewOptions: ViewOptions | undefined
$: spaceQuery = queryOptions?.filterBySpace === true && space !== undefined ? { space } : {}
$: _baseQuery = mergeQueries(mergeQueries(baseQuery ?? {}, viewlet?.baseQuery ?? {}), spaceQuery)
let isQueryLoaded = queryBuilder === undefined
$: _baseQuery = mergeQueries(baseQuery ?? {}, viewlet?.baseQuery ?? {})
$: query = { ..._baseQuery }
$: searchQuery = search === '' ? query : { ...query, $search: search }
$: resultQuery = searchQuery
$: resultQuery = isQueryLoaded ? searchQuery : undefined
let options = viewlet?.options
$: void updateQuery(_baseQuery, viewOptions, viewlet)
$: void updateQuery(_baseQuery, viewOptions, viewlet, queryBuilder)
$: void updateOptions(viewlet?.options, viewOptions, viewlet)
async function updateOptions (
Expand All @@ -91,12 +92,25 @@
async function updateQuery (
initialQuery: DocumentQuery<Doc>,
viewOptions: ViewOptions | undefined,
viewlet: Viewlet | undefined
viewlet: Viewlet | undefined,
builder: Resource<() => Promise<DocumentQuery<Doc>>> | undefined
): Promise<void> {
const updatedQuery = builder === undefined ? initialQuery : updateInitialQuery(initialQuery, builder)
query =
viewOptions !== undefined && viewlet !== undefined
? await getResultQuery(hierarchy, initialQuery, viewlet.viewOptions?.other, viewOptions)
: initialQuery
? await getResultQuery(hierarchy, updatedQuery, viewlet.viewOptions?.other, viewOptions)
: updatedQuery
isQueryLoaded = true
}
async function updateInitialQuery (
initialQuery: DocumentQuery<Doc>,
builder: Resource<() => Promise<DocumentQuery<Doc>>> | undefined
): Promise<DocumentQuery<Doc>> {
if (builder === undefined) return initialQuery
const fn = await getResource(builder)
const q = (await fn()) ?? {}
return mergeQueries(initialQuery ?? {}, q ?? {})
}
function showCreateDialog (): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@
space: currentSpace,
navigationModel: specialComponent?.navigationModel,
workbenchWidth,
queryOptions: specialComponent?.queryOptions
queryBuilder: specialComponent?.queryBuilder
}}
on:action={(e) => {
if (e?.detail) {
Expand Down
10 changes: 2 additions & 8 deletions plugins/workbench/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// limitations under the License.
//

import type { AccountRole, Class, Doc, Obj, PersonId, Ref, Space, Tx } from '@hcengineering/core'
import type { AccountRole, Class, Doc, DocumentQuery, Obj, PersonId, Ref, Space, Tx } from '@hcengineering/core'
import { DocNotifyContext, InboxNotification } from '@hcengineering/notification'
import type { Asset, IntlString, Resource } from '@hcengineering/platform'
import type { Preference } from '@hcengineering/preference'
Expand Down Expand Up @@ -173,7 +173,7 @@ export interface SpecialNavModel {
(inboxNotificationsByContext: Map<Ref<DocNotifyContext>, InboxNotification[]>) => number
>
navigationModel?: ParentsNavigationModel
queryOptions?: QueryOptions
queryBuilder?: Resource<() => Promise<DocumentQuery<Doc>>>
}

/** @public */
Expand All @@ -190,12 +190,6 @@ export interface ParentsNavigationModel {
createButton?: AnyComponent
}

/** @public */
export interface QueryOptions {
// If specified should display only documents from the current space
filterBySpace?: boolean
}

/** @public */
export interface ViewConfiguration {
class: Ref<Class<Doc>> // show object of this class
Expand Down

0 comments on commit 4407b36

Please sign in to comment.