From 1f990867f575e2464985c36283f110ebd39c286d Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Wed, 2 Apr 2025 19:42:01 +0700 Subject: [PATCH] QFix: Show proper current employee (#8435) Signed-off-by: Andrey Sobolev --- plugins/contact-resources/src/utils.ts | 44 ++++++++++--------- plugins/contact/src/utils.ts | 24 +++++----- .../src/components/AccountPopup.svelte | 19 ++++++++ 3 files changed, 55 insertions(+), 32 deletions(-) diff --git a/plugins/contact-resources/src/utils.ts b/plugins/contact-resources/src/utils.ts index d8858bdb8c..95fa224403 100644 --- a/plugins/contact-resources/src/utils.ts +++ b/plugins/contact-resources/src/utils.ts @@ -14,7 +14,9 @@ // limitations under the License. // +import { type AccountClient, getClient as getAccountClientRaw } from '@hcengineering/account-client' import { + addEmployeeListenrer, AvatarType, type Channel, type ChannelProvider, @@ -22,27 +24,31 @@ import { contactId, type Employee, formatName, + getCurrentEmployee, getFirstName, getLastName, getName, - getCurrentEmployee, - currentEmployeePromise, - type Person, - type SocialIdentity, - type PermissionsStore, type PermissionsBySpace, - type PersonsByPermission + type PermissionsStore, + type Person, + type PersonsByPermission, + type SocialIdentity } from '@hcengineering/contact' import core, { + type AccountUuid, type AggregateValue, type Class, type Client, type Doc, type DocumentQuery, + getCurrentAccount, type Hierarchy, type IdMap, + notEmpty, type ObjQueryType, type Permission, + type PersonId, + pickPrimarySocialId, type Ref, SocialIdType, type Space, @@ -51,18 +57,13 @@ import core, { type TxOperations, type TypedSpace, type UserStatus, - type WithLookup, - type AccountUuid, - notEmpty, - getCurrentAccount, - pickPrimarySocialId, - type PersonId + type WithLookup } from '@hcengineering/core' +import login from '@hcengineering/login' import notification, { type DocNotifyContext, type InboxNotification } from '@hcengineering/notification' -import { type IntlString, getEmbeddedLabel, getMetadata, getResource, translate } from '@hcengineering/platform' +import { getEmbeddedLabel, getMetadata, getResource, type IntlString, translate } from '@hcengineering/platform' import presentation, { createQuery, getClient, onClient } from '@hcengineering/presentation' import { type TemplateDataProvider } from '@hcengineering/templates' -import login from '@hcengineering/login' import { getCurrentResolvedLocation, getPanelURI, @@ -73,9 +74,8 @@ import { } from '@hcengineering/ui' import view, { type Filter, type GrouppingManager } from '@hcengineering/view' import { accessDeniedStore, FilterQuery } from '@hcengineering/view-resources' -import { derived, get, type Readable, writable } from 'svelte/store' import { type LocationData } from '@hcengineering/workbench' -import { type AccountClient, getClient as getAccountClientRaw } from '@hcengineering/account-client' +import { derived, get, type Readable, writable } from 'svelte/store' import contact from './plugin' @@ -311,15 +311,17 @@ async function generateLocation (loc: Location, id: Ref): Promise | undefined>() -void currentEmployeePromise.then((employee) => { - currentEmployeeRefStore.set(employee) -}) - /** * [Ref => Employee] mapping */ export const employeeByIdStore = writable>>(new Map()) + +export const currentEmployeeRefStore = writable | undefined>(getCurrentEmployee()) + +addEmployeeListenrer((ref) => { + currentEmployeeRefStore.set(ref) +}) + export const myEmployeeStore = derived( [currentEmployeeRefStore, employeeByIdStore], ([currentEmployeeRef, employeeById]) => { diff --git a/plugins/contact/src/utils.ts b/plugins/contact/src/utils.ts index f5d29c41cf..3ab66b19b4 100644 --- a/plugins/contact/src/utils.ts +++ b/plugins/contact/src/utils.ts @@ -16,6 +16,7 @@ import { Account, AccountRole, + AccountUuid, AttachedData, buildSocialIdString, Class, @@ -23,16 +24,15 @@ import { Doc, FindResult, generateId, + Person as GlobalPerson, Hierarchy, MeasureContext, + notEmpty, PersonId, Ref, SocialId, - TxFactory, - Person as GlobalPerson, - AccountUuid, - notEmpty, - toIdMap + toIdMap, + TxFactory } from '@hcengineering/core' import { getMetadata } from '@hcengineering/platform' import { ColorDefinition } from '@hcengineering/ui' @@ -42,11 +42,7 @@ import { AVATAR_COLORS, GravatarPlaceholderType } from './types' let currentEmployee: Ref -let resolveEmployee: (employee: Ref) => void -export const currentEmployeePromise = new Promise>((resolve) => { - resolveEmployee = resolve -}) - +const employeeListeners: ((ref: Ref) => void)[] = [] /** * @public * @returns @@ -55,13 +51,19 @@ export function getCurrentEmployee (): Ref { return currentEmployee } +export function addEmployeeListenrer (l: (ref: Ref) => void): void { + employeeListeners.push(l) +} + /** * @public * @param employee - */ export function setCurrentEmployee (employee: Ref): void { currentEmployee = employee - resolveEmployee(employee) + for (const l of employeeListeners) { + l(employee) + } } /** diff --git a/plugins/workbench-resources/src/components/AccountPopup.svelte b/plugins/workbench-resources/src/components/AccountPopup.svelte index 29b90dc81f..fca743106e 100644 --- a/plugins/workbench-resources/src/components/AccountPopup.svelte +++ b/plugins/workbench-resources/src/components/AccountPopup.svelte @@ -130,6 +130,25 @@ group: 'end' }) } + + if (hasAccountRole(account, AccountRole.User)) { + actions.push({ + icon: setting.icon.Signout, + label: setting.string.SelectWorkspace, + action: async () => { + closePopup() + const loc = getCurrentResolvedLocation() + loc.fragment = undefined + loc.query = undefined + loc.path[0] = loginId + loc.path[1] = 'selectWorkspace' + loc.path.length = 2 + navigate(loc) + }, + group: 'end' + }) + } + actions.push( { icon: setting.icon.Support,