From d1e356e789673d09b09bb48385ce102331ca5814 Mon Sep 17 00:00:00 2001 From: Artyom Savchenko Date: Wed, 9 Jul 2025 16:13:05 +0700 Subject: [PATCH] UBERF-12299: Fix gmail integration selection (#9505) * UBERF-12299: Fix gmail integration selection Signed-off-by: Artem Savchenko * UBERF-12299: Use original social id Signed-off-by: Artem Savchenko --------- Signed-off-by: Artem Savchenko --- .../src/components/AccountBox.svelte | 24 ++++++++++++++++++- .../src/components/IntegrationSelector.svelte | 7 ++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/plugins/contact-resources/src/components/AccountBox.svelte b/plugins/contact-resources/src/components/AccountBox.svelte index 6af1b1d0b3..5125c16396 100644 --- a/plugins/contact-resources/src/components/AccountBox.svelte +++ b/plugins/contact-resources/src/components/AccountBox.svelte @@ -31,6 +31,7 @@ export let justify: 'left' | 'center' = 'center' export let width: string | undefined = undefined export let readonly = false + export let mapToPrimarySocialId = true $: docQuery = include.length === 0 @@ -41,6 +42,17 @@ } } $: selectedEmp = value != null ? $employeeByPersonIdStore.get(value)?._id : value + let employeeToPersonIdMap = new Map, PersonId>() + $: employeeToPersonIdMap = mapToPrimarySocialId + ? employeeToPersonIdMap + : new Map( + include + .map((personId) => { + const employee = $employeeByPersonIdStore.get(personId) + return employee !== undefined ? ([employee._id, personId] as const) : null + }) + .filter(notEmpty) + ) const dispatch = createEventDispatcher() @@ -48,7 +60,17 @@ if (e.detail === null) { dispatch('change', null) } else { - const socialString = $primarySocialIdByEmployeeRefStore.get(e.detail) + let socialString: PersonId | undefined + + if (mapToPrimarySocialId) { + socialString = $primarySocialIdByEmployeeRefStore.get(e.detail) + } else { + socialString = employeeToPersonIdMap.get(e.detail) + if (socialString === undefined) { + socialString = $primarySocialIdByEmployeeRefStore.get(e.detail) + console.warn('PersonId not found in provided social id list, falling back to primary social ID:', e.detail) + } + } if (socialString === undefined) { console.error('Social id not found for person', e.detail) return diff --git a/plugins/gmail-resources/src/components/IntegrationSelector.svelte b/plugins/gmail-resources/src/components/IntegrationSelector.svelte index a29ddb5c31..1c476834af 100644 --- a/plugins/gmail-resources/src/components/IntegrationSelector.svelte +++ b/plugins/gmail-resources/src/components/IntegrationSelector.svelte @@ -25,13 +25,16 @@ $: ids = Array.from(new Set(integrations.map((p) => p.createdBy))).filter(notEmpty) - function change (e: CustomEvent) { + function change (e: CustomEvent): void { if (e.detail === null) { selected = undefined } else { selected = integrations.find((p) => p.createdBy === e.detail) + if (selected === undefined) { + console.warn('Integration not found for selected person', e.detail) + } } } - +