diff --git a/plugins/contact-resources/src/index.ts b/plugins/contact-resources/src/index.ts index da155de58c..ec630c01d5 100644 --- a/plugins/contact-resources/src/index.ts +++ b/plugins/contact-resources/src/index.ts @@ -147,7 +147,7 @@ import { } from './utils' export * from './utils' -export { employeeByIdStore, employeesStore } from './utils' +export { employeeByIdStore } from './utils' export * from './assignee' export { AccountArrayEditor, diff --git a/plugins/contact-resources/src/utils.ts b/plugins/contact-resources/src/utils.ts index 512b5d4345..160b0c22ba 100644 --- a/plugins/contact-resources/src/utils.ts +++ b/plugins/contact-resources/src/utils.ts @@ -317,7 +317,6 @@ void currentEmployeePromise.then((employee) => { * [Ref => Employee] mapping */ export const employeeByIdStore = writable>>(new Map()) -export const employeesStore = writable>>([]) export const myEmployeeStore = derived( [currentEmployeeRefStore, employeeByIdStore], ([currentEmployeeRef, employeeById]) => { @@ -326,9 +325,10 @@ export const myEmployeeStore = derived( ) /** * [Ref => Person] mapping + * Does not contain ALL persons. + * Only employees for now. Later need to be extended to possibly include guests and GitHub persons. */ export const personByIdStore = writable>>(new Map()) -export const personsStore = writable>>([]) export const socialIdsStore = writable>>([]) // NOTE @@ -345,11 +345,16 @@ export const mySocialStringsStore = derived(mySocialIdsStore, (mySocialIds) => { /** * [Ref => SocialIdentity[]] mapping */ -export const socialIdsByPersonRefStore = derived([personByIdStore, socialIdsStore], ([personById, socialIds]) => { - const mapped = Array.from(personById.entries()).map( - ([_id, person]) => [_id, socialIds.filter((si) => si.attachedTo === person._id)] as const - ) - return new Map(mapped) +export const socialIdsByPersonRefStore = derived([socialIdsStore], ([socialIds]) => { + const sidsByPersonRef: Record, SocialIdentity[]> = socialIds.reduce< + Record, SocialIdentity[]> + >((acc, si) => { + acc[si.attachedTo] = acc[si.attachedTo] ?? [] + acc[si.attachedTo].push(si) + return acc + }, {}) + + return new Map(Object.entries(sidsByPersonRef)) }) /** * [Ref => PersonId (primary)] mapping @@ -412,7 +417,6 @@ export const channelProviders = writable([]) export const statusByUserStore = writable>(new Map()) const providerQuery = createQuery(true) -const personsQuery = createQuery(true) const employeesQuery = createQuery(true) const siQuery = createQuery(true) @@ -421,19 +425,11 @@ onClient(() => { channelProviders.set(res) }) - personsQuery.query( - contact.class.Person, - {}, - (res) => { - personsStore.set(res) - personByIdStore.set(toIdMap(res)) - }, - { limit: 500 } - ) - employeesQuery.query(contact.mixin.Employee, { active: { $in: [true, false] } }, (res) => { - employeesStore.set(res) employeeByIdStore.set(toIdMap(res)) + + // We may need to extend this later with guests and github users + personByIdStore.set(toIdMap(res)) }) siQuery.query(contact.class.SocialIdentity, {}, (res) => {