From bc53f95568acc32824fb973c6b1493f7a0325a88 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Fri, 13 Sep 2024 11:49:47 +0700 Subject: [PATCH 1/2] fix default ws avatar is shown instead of the custom one --- src/libs/ReportUtils.ts | 22 ++++++------------- src/pages/ReportAvatar.tsx | 2 +- .../home/report/ReportActionItemSingle.tsx | 2 +- tests/perf-test/ReportUtils.perf-test.ts | 7 ------ 4 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 7001dedea2f1..86f46fe65f75 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1866,12 +1866,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 */ @@ -1939,20 +1933,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, @@ -7945,7 +7938,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 ( { 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); From 837e4132ae8b1357c11fce240b6956648cde0f6a Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Fri, 13 Sep 2024 11:49:57 +0700 Subject: [PATCH 2/2] fix ws avatar isn't dynamically updated --- src/pages/home/report/ReportActionItem.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/home/report/ReportActionItem.tsx b/src/pages/home/report/ReportActionItem.tsx index 3d69f029b8bd..8ea9a3c6aa40 100644 --- a/src/pages/home/report/ReportActionItem.tsx +++ b/src/pages/home/report/ReportActionItem.tsx @@ -1045,6 +1045,7 @@ export default withOnyx({ 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) &&