diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index f35ab637aea1..dcecdf3c1eb9 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1886,12 +1886,6 @@ function getDefaultWorkspaceAvatarTestID(workspaceName: string): string { return !alphaNumeric ? defaultAvatarBuildingIconTestID : `SvgDefaultAvatar_${alphaNumeric[0]} Icon`; } -function getWorkspaceAvatar(report: OnyxEntry): AvatarSource { - const workspaceName = getPolicyName(report, false, allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]); - const avatar = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]?.avatarURL ?? ''; - return !isEmpty(avatar) ? avatar : getDefaultWorkspaceAvatar(workspaceName); -} - /** * Helper method to return the default avatar associated with the given reportID */ @@ -1959,20 +1953,19 @@ function getWorkspaceIcon(report: OnyxInputOrEntry, policy?: OnyxInputOr const workspaceName = getPolicyName(report, false, policy); const cacheKey = report?.policyID ?? workspaceName; const iconFromCache = workSpaceIconsCache.get(cacheKey); - const avatarURL = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]?.avatarURL; - - const isSameAvatarURL = iconFromCache?.icon?.source === avatarURL; - const isDefaultWorkspaceAvatar = !avatarURL && typeof iconFromCache?.icon?.source !== 'string'; - const hasWorkSpaceNameChanged = iconFromCache?.name !== workspaceName; - if (iconFromCache && (isSameAvatarURL || isDefaultWorkspaceAvatar) && !hasWorkSpaceNameChanged) { - return iconFromCache.icon; - } // disabling to protect against empty strings // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const policyAvatarURL = report?.policyAvatar || allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]?.avatarURL; // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const policyExpenseChatAvatarSource = policyAvatarURL || getDefaultWorkspaceAvatar(workspaceName); + const isSameAvatarURL = iconFromCache?.icon?.source === policyExpenseChatAvatarSource; + const hasWorkSpaceNameChanged = iconFromCache?.name !== workspaceName; + + if (iconFromCache && (isSameAvatarURL || report?.policyAvatar === undefined) && !hasWorkSpaceNameChanged) { + return iconFromCache.icon; + } + const workspaceIcon: Icon = { source: policyExpenseChatAvatarSource ?? '', type: CONST.ICON_TYPE_WORKSPACE, @@ -7968,7 +7961,6 @@ export { getTransactionsWithReceipts, getUserDetailTooltipText, getWhisperDisplayNames, - getWorkspaceAvatar, getWorkspaceChats, getWorkspaceIcon, goBackToDetailsPage, diff --git a/src/pages/ReportAvatar.tsx b/src/pages/ReportAvatar.tsx index eeb6829e7fc0..eb921032979b 100644 --- a/src/pages/ReportAvatar.tsx +++ b/src/pages/ReportAvatar.tsx @@ -24,7 +24,7 @@ function ReportAvatar({report = {} as Report, route, policies, isLoadingApp = tr const policyID = route.params.policyID ?? '-1'; const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]; const policyName = ReportUtils.getPolicyName(report, false, policy); - const avatarURL = ReportUtils.getWorkspaceAvatar(report); + const avatarURL = ReportUtils.getWorkspaceIcon(report).source; return ( ({ prevProps.shouldHideThreadDividerLine === nextProps.shouldHideThreadDividerLine && prevProps.report?.total === nextProps.report?.total && prevProps.report?.nonReimbursableTotal === nextProps.report?.nonReimbursableTotal && + prevProps.report?.policyAvatar === nextProps.report?.policyAvatar && prevProps.linkedReportActionID === nextProps.linkedReportActionID && lodashIsEqual(prevProps.report.fieldList, nextProps.report.fieldList) && lodashIsEqual(prevProps.transactionThreadReport, nextProps.transactionThreadReport) && diff --git a/src/pages/home/report/ReportActionItemSingle.tsx b/src/pages/home/report/ReportActionItemSingle.tsx index 95a7332f0606..0e58296d39f2 100644 --- a/src/pages/home/report/ReportActionItemSingle.tsx +++ b/src/pages/home/report/ReportActionItemSingle.tsx @@ -100,7 +100,7 @@ function ReportActionItemSingle({ if (isWorkspaceActor) { displayName = ReportUtils.getPolicyName(report); actorHint = displayName; - avatarSource = ReportUtils.getWorkspaceAvatar(report); + avatarSource = ReportUtils.getWorkspaceIcon(report).source; avatarId = report.policyID; } else if (action?.delegateAccountID && personalDetails[action?.delegateAccountID]) { // We replace the actor's email, name, and avatar with the Copilot manually for now. And only if we have their diff --git a/tests/perf-test/ReportUtils.perf-test.ts b/tests/perf-test/ReportUtils.perf-test.ts index 11c6d3772799..8cd531db8628 100644 --- a/tests/perf-test/ReportUtils.perf-test.ts +++ b/tests/perf-test/ReportUtils.perf-test.ts @@ -169,13 +169,6 @@ describe('ReportUtils', () => { await measureFunction(() => ReportUtils.temporary_getMoneyRequestOptions(report, policy, reportParticipants)); }); - test('[ReportUtils] getWorkspaceAvatar on 1k policies', async () => { - const report = createRandomReport(1); - - await waitForBatchedUpdates(); - await measureFunction(() => ReportUtils.getWorkspaceAvatar(report)); - }); - test('[ReportUtils] getWorkspaceChat on 1k policies', async () => { const policyID = '1'; const accountsID = Array.from({length: 20}, (v, i) => i + 1);