-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[CP Staging][Avatars] Display subscript for single expenses & invoices in Workspace #67993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ import type {ValueOf} from 'type-fest'; | |
| import {FallbackAvatar} from '@components/Icon/Expensicons'; | ||
| import useOnyx from '@hooks/useOnyx'; | ||
| import useReportIsArchived from '@hooks/useReportIsArchived'; | ||
| import {getReportAction} from '@libs/ReportActionsUtils'; | ||
| import {getOriginalMessage, getReportAction, isMoneyRequestAction} from '@libs/ReportActionsUtils'; | ||
| import { | ||
| getDisplayNameForParticipant, | ||
| getIcons, | ||
|
|
@@ -37,7 +37,6 @@ function useReportActionAvatars({ | |
| policyID?: string; | ||
| }) { | ||
| /* Get avatar type */ | ||
|
|
||
| const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, { | ||
| canBeMissing: true, | ||
| }); | ||
|
|
@@ -50,7 +49,15 @@ function useReportActionAvatars({ | |
| const chatReport = isReportAChatReport ? report : reportChatReport; | ||
| const iouReport = isReportAChatReport ? undefined : report; | ||
|
|
||
| const action = passedAction ?? (iouReport?.parentReportActionID ? getReportAction(chatReport?.reportID ?? iouReport?.chatReportID, iouReport?.parentReportActionID) : undefined); | ||
| let action; | ||
|
|
||
| if (passedAction) { | ||
| action = passedAction; | ||
| } else if (iouReport?.parentReportActionID) { | ||
| action = getReportAction(chatReport?.reportID ?? iouReport?.chatReportID, iouReport?.parentReportActionID); | ||
| } else if (!!reportChatReport && !!chatReport?.parentReportActionID && !iouReport) { | ||
| action = getReportAction(reportChatReport?.reportID, chatReport.parentReportActionID); | ||
| } | ||
|
|
||
| const isReportArchived = useReportIsArchived(iouReport?.reportID); | ||
|
|
||
|
|
@@ -87,8 +94,9 @@ function useReportActionAvatars({ | |
| }; | ||
| } | ||
|
|
||
| const isWorkspacePolicy = !!policy && policy.type !== CONST.POLICY.TYPE.PERSONAL; | ||
| const isATripRoom = isTripRoom(chatReport); | ||
| const isWorkspaceWithoutChatReportProp = !chatReport && policy?.type !== CONST.POLICY.TYPE.PERSONAL; | ||
| const isWorkspaceWithoutChatReportProp = !chatReport && isWorkspacePolicy; | ||
| const isAWorkspaceChat = isPolicyExpenseChat(chatReport) || isWorkspaceWithoutChatReportProp; | ||
| const isATripPreview = action?.actionName === CONST.REPORT.ACTIONS.TYPE.TRIP_PREVIEW; | ||
| const isAReportPreviewAction = action?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW; | ||
|
|
@@ -101,13 +109,15 @@ function useReportActionAvatars({ | |
| const shouldUseAccountIDs = accountIDs.length > 0; | ||
| const shouldShowAllActors = displayAllActors && !reportPreviewSenderID; | ||
| const isChatThreadOutsideTripRoom = isChatThread(chatReport) && !isATripRoom; | ||
| const shouldShowSubscriptAvatar = shouldReportShowSubscript(iouReport ?? chatReport, isReportArchived) && policy?.type !== CONST.POLICY.TYPE.PERSONAL; | ||
| const shouldShowSubscriptAvatar = shouldReportShowSubscript(iouReport ?? chatReport, isReportArchived) && isWorkspacePolicy; | ||
| const shouldShowConvertedSubscriptAvatar = (shouldStackHorizontally || shouldUseAccountIDs) && shouldShowSubscriptAvatar && !reportPreviewSenderID; | ||
| const isExpense = isMoneyRequestAction(action) && getOriginalMessage(action)?.type === CONST.IOU.ACTION.CREATE; | ||
| const isWorkspaceExpense = isWorkspacePolicy && isExpense; | ||
|
|
||
| const shouldUseSubscriptAvatar = | ||
| (((shouldShowSubscriptAvatar && isReportPreviewOrNoAction) || isReportPreviewInTripRoom || isATripPreview) && | ||
| (((shouldShowSubscriptAvatar && isReportPreviewOrNoAction) || isReportPreviewInTripRoom || isATripPreview || isWorkspaceExpense) && | ||
| !shouldStackHorizontally && | ||
| !isChatThreadOutsideTripRoom && | ||
| !(isChatThreadOutsideTripRoom && !isWorkspaceExpense) && | ||
| !shouldShowConvertedSubscriptAvatar) || | ||
| shouldUseCardFeed; | ||
|
|
||
|
|
@@ -134,6 +144,8 @@ function useReportActionAvatars({ | |
|
|
||
| const defaultDisplayName = getDisplayNameForParticipant({accountID, personalDetailsData: personalDetails}) ?? ''; | ||
| const isAInvoiceReport = isInvoiceReport(iouReport ?? null); | ||
| const invoiceReport = [iouReport, chatReport, reportChatReport].find(isInvoiceReport); | ||
| const isNestedInInvoiceReport = !!invoiceReport; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coming from #69343, we should add the check for the chat thread as well |
||
| const isWorkspaceActor = isAInvoiceReport || (isAWorkspaceChat && (!actorAccountID || displayAllActors)); | ||
| const isChatReportOnlyProp = !iouReport && chatReport; | ||
| const isWorkspaceChatWithoutChatReport = !chatReport && isAWorkspaceChat; | ||
|
|
@@ -206,9 +218,18 @@ function useReportActionAvatars({ | |
|
|
||
| const shouldUseMappedAccountIDs = avatarsForAccountIDs.length > 0 && (avatarType === CONST.REPORT_ACTION_AVATARS.TYPE.MULTIPLE || shouldUseActorAccountID); | ||
| const shouldUsePrimaryAvatarID = isWorkspaceActor && !!primaryAvatar.id; | ||
| const shouldUseInvoiceExpenseIcons = isWorkspaceExpense && isNestedInInvoiceReport && !!accountID; | ||
|
|
||
| let avatars = [primaryAvatar, secondaryAvatar]; | ||
|
|
||
| if (shouldUseInvoiceExpenseIcons) { | ||
| avatars = getIconsWithDefaults(invoiceReport); | ||
| } else if (shouldUseMappedAccountIDs) { | ||
| avatars = avatarsForAccountIDs; | ||
|
Comment on lines
+225
to
+228
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the centralized place where these checks are made?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this hook is used inside a component that is used for every report or report action avatar in the app. |
||
| } | ||
|
|
||
| return { | ||
| avatars: shouldUseMappedAccountIDs ? avatarsForAccountIDs : [primaryAvatar, secondaryAvatar], | ||
| avatars, | ||
| avatarType, | ||
| details: { | ||
| ...(personalDetails?.[accountID] ?? {}), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of add the case outside of it, could we update this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it's not that easy. It's more a matter of which report to pass and which report to pass to the icons function. For example, the invoice single expense view has no IOU report, and the invoice report is actually a parent of its chat report. The whole logic revolves around that. The function itself performs checks such as
isExpenseRequestso it is correct.But I agree that there are sooo many checks that it needs a refractor and some utils functions and I am willing to do such as well as the optimization but I think we should focus to cover everything and do refractor as a last PR, same as we did with Better Expense Report View and it worked well.
What do you think?