QFix: Show proper current employee (#8435)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev
2025-04-02 19:42:01 +07:00
committed by GitHub
parent b688e52f8a
commit 1f990867f5
3 changed files with 55 additions and 32 deletions
+23 -21
View File
@@ -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<Contact>): Promise<Resol
}
}
const currentEmployeeRefStore = writable<Ref<Employee> | undefined>()
void currentEmployeePromise.then((employee) => {
currentEmployeeRefStore.set(employee)
})
/**
* [Ref<Employee> => Employee] mapping
*/
export const employeeByIdStore = writable<IdMap<WithLookup<Employee>>>(new Map())
export const currentEmployeeRefStore = writable<Ref<Employee> | undefined>(getCurrentEmployee())
addEmployeeListenrer((ref) => {
currentEmployeeRefStore.set(ref)
})
export const myEmployeeStore = derived(
[currentEmployeeRefStore, employeeByIdStore],
([currentEmployeeRef, employeeById]) => {
+13 -11
View File
@@ -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<Employee>
let resolveEmployee: (employee: Ref<Employee>) => void
export const currentEmployeePromise = new Promise<Ref<Employee>>((resolve) => {
resolveEmployee = resolve
})
const employeeListeners: ((ref: Ref<Employee>) => void)[] = []
/**
* @public
* @returns
@@ -55,13 +51,19 @@ export function getCurrentEmployee (): Ref<Employee> {
return currentEmployee
}
export function addEmployeeListenrer (l: (ref: Ref<Employee>) => void): void {
employeeListeners.push(l)
}
/**
* @public
* @param employee -
*/
export function setCurrentEmployee (employee: Ref<Employee>): void {
currentEmployee = employee
resolveEmployee(employee)
for (const l of employeeListeners) {
l(employee)
}
}
/**
@@ -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,