Skip to content

Commit c5df224

Browse files
committed
Fix Search Workspace Avatars
1 parent 3c1d3c5 commit c5df224

4 files changed

Lines changed: 43 additions & 4 deletions

File tree

src/components/ReportActionAvatars/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ import useReportActionAvatars from './useReportActionAvatars';
1313
type ReportActionAvatarsProps = {
1414
horizontalStacking?: HorizontalStacking | boolean;
1515

16-
/** IOU Report ID for single avatar */
16+
/** Report ID for the report action avatars */
1717
reportID?: string;
1818

19-
/** IOU Report ID for single avatar */
19+
/** Action for the report action avatars */
2020
action?: OnyxEntry<ReportAction>;
2121

22+
/** Policy ID for the workspace avatar */
23+
policyID?: string;
24+
2225
/** Single avatar container styles */
2326
singleAvatarContainerStyle?: ViewStyle[];
2427

@@ -53,6 +56,7 @@ type ReportActionAvatarsProps = {
5356
/**
5457
* The component that renders proper user avatars based on either:
5558
*
59+
* - policyID - this can be passed if we have no other option, and we want to display workspace avatar, it makes component ignore the props below
5660
* - accountIDs - if this is passed, it is prioritized and render even if report or action has different avatars attached, useful for option items, menu items etc.
5761
* - action - this is useful when we want to display avatars of chat threads, messages, report/trip previews etc.
5862
* - reportID - this can be passed without above props, when we want to display chat report avatars, DM chat avatars etc.
@@ -62,6 +66,7 @@ function ReportActionAvatars({
6266
reportID: potentialReportID,
6367
action,
6468
accountIDs: passedAccountIDs = [],
69+
policyID,
6570
size = CONST.AVATAR_SIZE.DEFAULT,
6671
shouldShowTooltip = true,
6772
horizontalStacking,
@@ -96,6 +101,7 @@ function ReportActionAvatars({
96101
shouldStackHorizontally,
97102
shouldUseCardFeed: !!subscriptCardFeed,
98103
accountIDs,
104+
policyID,
99105
});
100106

101107
let avatarType: ValueOf<typeof CONST.REPORT_ACTION_AVATARS.TYPE> = notPreciseAvatarType;

src/components/ReportActionAvatars/useReportActionAvatars.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
getDisplayNameForParticipant,
99
getIcons,
1010
getReportActionActorAccountID,
11+
getWorkspaceIcon,
1112
isChatThread,
1213
isInvoiceReport,
1314
isPolicyExpenseChat,
@@ -26,12 +27,14 @@ function useReportActionAvatars({
2627
shouldStackHorizontally = false,
2728
shouldUseCardFeed = false,
2829
accountIDs = [],
30+
policyID: passedPolicyID,
2931
}: {
3032
report: OnyxEntry<Report>;
3133
action: OnyxEntry<ReportAction>;
3234
shouldStackHorizontally?: boolean;
3335
shouldUseCardFeed?: boolean;
3436
accountIDs?: number[];
37+
policyID?: string;
3538
}) {
3639
/* Get avatar type */
3740

@@ -57,9 +60,33 @@ function useReportActionAvatars({
5760
chatReport,
5861
});
5962

60-
const policyID = chatReport?.policyID === CONST.POLICY.ID_FAKE || !chatReport?.policyID ? (iouReport?.policyID ?? chatReport?.policyID) : chatReport?.policyID;
63+
const policyID = passedPolicyID ?? (chatReport?.policyID === CONST.POLICY.ID_FAKE || !chatReport?.policyID ? (iouReport?.policyID ?? chatReport?.policyID) : chatReport?.policyID);
6164
const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`];
6265

66+
const {chatReportIDAdmins, chatReportIDAnnounce, workspaceAccountID} = policy ?? {};
67+
const [policyChatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${chatReportIDAnnounce ?? chatReportIDAdmins}`, {canBeMissing: true});
68+
69+
if (passedPolicyID) {
70+
const policyChatReportAvatar = {...getWorkspaceIcon(policyChatReport, policy), id: policyID, name: policy?.name};
71+
72+
return {
73+
avatars: [policyChatReportAvatar],
74+
avatarType: CONST.REPORT_ACTION_AVATARS.TYPE.SINGLE,
75+
details: {
76+
...(personalDetails?.[workspaceAccountID ?? CONST.DEFAULT_NUMBER_ID] ?? {}),
77+
shouldDisplayAllActors: false,
78+
isWorkspaceActor: false,
79+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
80+
actorHint: String(policyID).replace(CONST.REGEX.MERGED_ACCOUNT_PREFIX, ''),
81+
accountID: workspaceAccountID,
82+
delegateAccountID: undefined,
83+
},
84+
source: {
85+
policyChatReport,
86+
},
87+
};
88+
}
89+
6390
const isATripRoom = isTripRoom(chatReport);
6491
const isWorkspaceWithoutChatReportProp = !chatReport && policy?.type !== CONST.POLICY.TYPE.PERSONAL;
6592
const isAWorkspaceChat = isPolicyExpenseChat(chatReport) || isWorkspaceWithoutChatReportProp;

src/components/SelectionList/UserListItem.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function UserListItem<TItem extends ListItem>({
9999
</View>
100100
</PressableWithFeedback>
101101
)}
102-
{!!item.icons && (
102+
{(!!item.reportID || !!item.accountID || !!item.policyID) && (
103103
<ReportActionAvatars
104104
subscriptAvatarBorderColor={hovered && !isFocused ? hoveredBackgroundColor : subscriptAvatarBorderColor}
105105
shouldShowTooltip={showTooltip}
@@ -110,6 +110,7 @@ function UserListItem<TItem extends ListItem>({
110110
]}
111111
reportID={item.reportID}
112112
accountIDs={[Number(item.accountID)]}
113+
policyID={!item.reportID && !item.accountID ? item.policyID : undefined}
113114
singleAvatarContainerStyle={[styles.actionAvatar, styles.mr3]}
114115
/>
115116
)}

tests/ui/ReportActionAvatarsTest.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,5 +442,10 @@ describe('ReportActionAvatars', () => {
442442
const retrievedData = await retrieveDataFromAvatarView({reportID: iouDMSingleExpenseReport.reportID});
443443
isSingleAvatarRendered(retrievedData);
444444
});
445+
446+
it('renders workspace avatar if policyID is passed as a prop', async () => {
447+
const retrievedData = await retrieveDataFromAvatarView({policyID: policy.id});
448+
isSingleAvatarRendered({...retrievedData, userAvatar: getDefaultWorkspaceAvatar().name});
449+
});
445450
});
446451
});

0 commit comments

Comments
 (0)