Skip to content

Commit

Permalink
Merge pull request #49145 from bernhardoj/fix/48358-invoice-room-show…
Browse files Browse the repository at this point in the history
…s-default-ws-avatar

Fix default WS avatar is shown instead of the custom one
  • Loading branch information
rlinoz authored Sep 16, 2024
2 parents d0a51b8 + 837e413 commit 8c5141a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 24 deletions.
22 changes: 7 additions & 15 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1886,12 +1886,6 @@ function getDefaultWorkspaceAvatarTestID(workspaceName: string): string {
return !alphaNumeric ? defaultAvatarBuildingIconTestID : `SvgDefaultAvatar_${alphaNumeric[0]} Icon`;
}

function getWorkspaceAvatar(report: OnyxEntry<Report>): 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
*/
Expand Down Expand Up @@ -1959,20 +1953,19 @@ function getWorkspaceIcon(report: OnyxInputOrEntry<Report>, 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,
Expand Down Expand Up @@ -7968,7 +7961,6 @@ export {
getTransactionsWithReceipts,
getUserDetailTooltipText,
getWhisperDisplayNames,
getWorkspaceAvatar,
getWorkspaceChats,
getWorkspaceIcon,
goBackToDetailsPage,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ReportAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<AttachmentModal
Expand Down
1 change: 1 addition & 0 deletions src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,7 @@ export default withOnyx<ReportActionItemProps, ReportActionItemOnyxProps>({
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) &&
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportActionItemSingle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions tests/perf-test/ReportUtils.perf-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8c5141a

Please sign in to comment.