Skip to content

Commit 4bf8176

Browse files
authored
UBERF-11415: Optimise contact UI stores (#9185)
1 parent f1c76f6 commit 4bf8176

File tree

115 files changed

+1837
-942
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+1837
-942
lines changed

desktop/src/ui/notifications.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getPersonBySocialId, formatName } from '@hcengineering/contact'
1+
import { getPersonByPersonId, formatName } from '@hcengineering/contact'
22
import { Ref, TxOperations } from '@hcengineering/core'
33
import notification, { DocNotifyContext, CommonInboxNotification, ActivityInboxNotification, InboxNotification } from '@hcengineering/notification'
44
import { IntlString, addEventListener, translate } from '@hcengineering/platform'
@@ -67,7 +67,7 @@ async function hydrateNotificationAsYouCan (lastNotification: InboxNotification)
6767
body: ''
6868
}
6969

70-
const person = await getPersonBySocialId(client, lastNotification.modifiedBy)
70+
const person = await getPersonByPersonId(client, lastNotification.modifiedBy)
7171
if (person == null) {
7272
return noPersonData
7373
}

desktop/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"skipLibCheck": true,
1212
"moduleResolution": "node",
1313
"allowSyntheticDefaultImports": true,
14-
"lib": ["es2016", "dom", "ES2021.String", "ESNext.Array"]
14+
"lib": ["es2023", "dom", "ES2021.String", "ESNext.Array"]
1515
},
1616
"include": ["src/**/*", "declarations.d.ts"],
1717
"exclude": ["node_modules", "lib", "dist", "types", "bundle"]

dev/prod/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"verbatimModuleSyntax": true,
1414
"allowSyntheticDefaultImports": true,
1515
"lib": [
16-
"es2016",
16+
"es2023",
1717
"dom",
1818
"ES2021.String",
1919
"ESNext.Array"

models/contact/src/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -826,10 +826,6 @@ export function createModel (builder: Builder): void {
826826
presenter: contact.component.PersonPresenter
827827
})
828828

829-
builder.mixin(core.class.TypePersonId, core.class.Class, view.mixin.ArrayEditor, {
830-
inlineEditor: contact.component.PersonIdArrayEditor
831-
})
832-
833829
builder.mixin(core.class.TypeAccountUuid, core.class.Class, view.mixin.ArrayEditor, {
834830
inlineEditor: contact.component.AccountArrayEditor
835831
})

packages/core/src/common.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ export function groupByArray<T, K> (array: T[], keyProvider: (item: T) => K): Ma
1414
return result
1515
}
1616

17+
export async function groupByArrayAsync<T, K> (array: T[], keyProvider: (item: T) => Promise<K>): Promise<Map<K, T[]>> {
18+
const result = new Map<K, T[]>()
19+
20+
for (const item of array) {
21+
const key = await keyProvider(item)
22+
23+
if (!result.has(key)) {
24+
result.set(key, [item])
25+
} else {
26+
result.get(key)?.push(item)
27+
}
28+
}
29+
30+
return result
31+
}
32+
1733
export function flipSet<T> (set: Set<T>, item: T): Set<T> {
1834
if (set.has(item)) {
1935
set.delete(item)

packages/core/src/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,14 @@ export function notEmpty<T> (id: T | undefined | null): id is T {
944944
return id !== undefined && id !== null && id !== ''
945945
}
946946

947+
export function unique<T> (arr: T[]): T[] {
948+
return Array.from(new Set(arr))
949+
}
950+
951+
export function uniqueNotEmpty<T extends NonNullable<unknown>> (arr: Array<T | undefined | null>): T[] {
952+
return unique(arr).filter(notEmpty)
953+
}
954+
947955
/**
948956
* Return a current performance timestamp
949957
*/

plugins/activity-resources/src/activityMessagesUtils.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import core, {
1919
type Client,
2020
type Collection,
2121
type Doc,
22-
groupByArray,
22+
groupByArrayAsync,
2323
type Hierarchy,
2424
type Mixin,
2525
type Ref,
@@ -37,8 +37,7 @@ import {
3737
import contact, { type Person } from '@hcengineering/contact'
3838
import { type IntlString } from '@hcengineering/platform'
3939
import { type AnyComponent } from '@hcengineering/ui'
40-
import { get } from 'svelte/store'
41-
import { personRefByPersonIdStore } from '@hcengineering/contact-resources'
40+
import { getPersonRefByPersonId } from '@hcengineering/contact-resources'
4241
import activity, {
4342
type ActivityMessage,
4443
type DisplayActivityMessage,
@@ -257,7 +256,10 @@ export async function combineActivityMessages (
257256

258257
const result: Array<DisplayActivityMessage | undefined> = [...uncombined]
259258

260-
const groupedByType: Map<string, DocUpdateMessage[]> = groupByArray(docUpdateMessages, getDocUpdateMessageKey)
259+
const groupedByType: Map<string, DocUpdateMessage[]> = await groupByArrayAsync(
260+
docUpdateMessages,
261+
getDocUpdateMessageKey
262+
)
261263

262264
for (const [, groupedMessages] of groupedByType) {
263265
const cantMerge = groupedMessages.filter(
@@ -365,8 +367,8 @@ function groupByTime<T extends ActivityMessage> (messages: T[]): T[][] {
365367
return result
366368
}
367369

368-
function getDocUpdateMessageKey (message: DocUpdateMessage): string {
369-
const personRef = get(personRefByPersonIdStore).get(message.createdBy as any)
370+
async function getDocUpdateMessageKey (message: DocUpdateMessage): Promise<string> {
371+
const personRef = await getPersonRefByPersonId(message.createdBy as any)
370372

371373
if (message.action === 'update') {
372374
return [message._class, message.attachedTo, message.action, personRef, getAttributeUpdatesKey(message)].join('_')

plugins/activity-resources/src/components/BasePreview.svelte

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
<script lang="ts">
1717
import { ComponentExtensions, getClient, LiteMessageViewer } from '@hcengineering/presentation'
1818
import { Person } from '@hcengineering/contact'
19-
import { Avatar, personByPersonIdStore, SystemAvatar } from '@hcengineering/contact-resources'
20-
import core, { PersonId, Doc, Ref, Timestamp, type WithLookup } from '@hcengineering/core'
19+
import { Avatar, getPersonByPersonIdCb, SystemAvatar } from '@hcengineering/contact-resources'
20+
import core, { PersonId, Doc, Timestamp } from '@hcengineering/core'
2121
import { Icon, Label, resizeObserver, TimeSince, tooltip } from '@hcengineering/ui'
2222
import { Asset, getEmbeddedLabel, IntlString } from '@hcengineering/platform'
2323
import activity, { ActivityMessage, ActivityMessagePreviewType } from '@hcengineering/activity'
@@ -42,12 +42,18 @@
4242
const tooltipLimit = 512
4343
4444
let isActionsOpened = false
45-
let person: WithLookup<Person> | undefined = undefined
45+
let person: Person | undefined = undefined
4646
4747
let width: number
4848
4949
$: isCompact = width < limit
50-
$: person = account !== undefined ? $personByPersonIdStore.get(account) : undefined
50+
$: if (account !== undefined) {
51+
getPersonByPersonIdCb(account, (p) => {
52+
person = p ?? undefined
53+
})
54+
} else {
55+
person = undefined
56+
}
5157
5258
export function onActionsOpened (): void {
5359
isActionsOpened = true

plugins/activity-resources/src/components/Replies.svelte

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
-->
1515
<script lang="ts">
1616
import { Person } from '@hcengineering/contact'
17-
import { personByIdStore, Avatar } from '@hcengineering/contact-resources'
18-
import { Doc, IdMap, Ref, WithLookup } from '@hcengineering/core'
17+
import { Avatar, getPersonByPersonRefStore } from '@hcengineering/contact-resources'
18+
import { Doc, IdMap, notEmpty, Ref, WithLookup } from '@hcengineering/core'
1919
import { Label, TimeSince } from '@hcengineering/ui'
2020
import activity, { ActivityMessage } from '@hcengineering/activity'
2121
import notification, {
@@ -49,7 +49,8 @@
4949
$: notificationsByContextStore = inboxClient?.inboxNotificationsByContext
5050
5151
$: hasNew = hasNewReplies(object, $contextByDocStore, $notificationsByContextStore)
52-
$: updateQuery(persons, $personByIdStore)
52+
$: personByRefStore = getPersonByPersonRefStore(Array.from(persons))
53+
$: updateQuery(persons, $personByRefStore)
5354
5455
function hasNewReplies (
5556
message: ActivityMessage,
@@ -73,7 +74,7 @@
7374
function updateQuery (personIds: Set<Ref<Person>>, personById: IdMap<Person>): void {
7475
displayPersons = Array.from(personIds)
7576
.map((id) => personById.get(id))
76-
.filter((person): person is Person => person !== undefined)
77+
.filter(notEmpty)
7778
.slice(0, maxDisplayPersons - 1)
7879
}
7980

plugins/activity-resources/src/components/activity-info-message/ActivityInfoMessagePresenter.svelte

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
-->
1515
<script lang="ts">
1616
import { ActivityInfoMessage } from '@hcengineering/activity'
17-
import { Avatar, SystemAvatar, personByPersonIdStore } from '@hcengineering/contact-resources'
17+
import { Avatar, SystemAvatar, getPersonByPersonIdCb } from '@hcengineering/contact-resources'
1818
import { translateCB } from '@hcengineering/platform'
1919
import { HTMLViewer } from '@hcengineering/presentation'
2020
import { Action, themeStore } from '@hcengineering/ui'
2121
2222
import ActivityMessageHeader from '../activity-message/ActivityMessageHeader.svelte'
2323
import ActivityMessageTemplate from '../activity-message/ActivityMessageTemplate.svelte'
24+
import { Person } from '@hcengineering/contact'
2425
2526
export let value: ActivityInfoMessage
2627
export let showNotify: boolean = false
@@ -36,7 +37,10 @@
3637
export let readonly: boolean = false
3738
export let onClick: (() => void) | undefined = undefined
3839
39-
$: person = $personByPersonIdStore.get(value.createdBy ?? value.modifiedBy)
40+
let person: Person | undefined
41+
$: getPersonByPersonIdCb(value.createdBy ?? value.modifiedBy, (p) => {
42+
person = p ?? undefined
43+
})
4044
4145
let content = ''
4246

0 commit comments

Comments
 (0)