Skip to content

Commit b215aa8

Browse files
authored
Merge pull request #49172 from Expensify/georgia-fixIOUpreview
[ReportPreview / Avatars] Fix avatar styles and headline for Ecards, invoices, and group expense reports
2 parents bc106fa + b704277 commit b215aa8

File tree

5 files changed

+215
-86
lines changed

5 files changed

+215
-86
lines changed

Diff for: src/CONST.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ const CONST = {
171171
},
172172

173173
// Note: Group and Self-DM excluded as these are not tied to a Workspace
174-
WORKSPACE_ROOM_TYPES: [chatTypes.POLICY_ADMINS, chatTypes.POLICY_ANNOUNCE, chatTypes.DOMAIN_ALL, chatTypes.POLICY_ROOM, chatTypes.POLICY_EXPENSE_CHAT],
174+
WORKSPACE_ROOM_TYPES: [chatTypes.POLICY_ADMINS, chatTypes.POLICY_ANNOUNCE, chatTypes.DOMAIN_ALL, chatTypes.POLICY_ROOM, chatTypes.POLICY_EXPENSE_CHAT, chatTypes.INVOICE],
175175
ANDROID_PACKAGE_NAME,
176176
WORKSPACE_ENABLE_FEATURE_REDIRECT_DELAY: 100,
177177
ANIMATED_HIGHLIGHT_ENTRY_DELAY: 50,

Diff for: src/libs/ReportActionsUtils.ts

+39-8
Original file line numberDiff line numberDiff line change
@@ -994,20 +994,20 @@ const iouRequestTypes = new Set<ValueOf<typeof CONST.IOU.REPORT_ACTION_TYPE>>([
994994
CONST.IOU.REPORT_ACTION_TYPE.TRACK,
995995
]);
996996

997-
/**
998-
* Gets the reportID for the transaction thread associated with a report by iterating over the reportActions and identifying the IOU report actions.
999-
* Returns a reportID if there is exactly one transaction thread for the report, and null otherwise.
1000-
*/
1001-
function getOneTransactionThreadReportID(reportID: string, reportActions: OnyxEntry<ReportActions> | ReportAction[], isOffline: boolean | undefined = undefined): string | undefined {
1002-
// If the report is not an IOU, Expense report, or Invoice, it shouldn't be treated as one-transaction report.
997+
function getMoneyRequestActions(
998+
reportID: string,
999+
reportActions: OnyxEntry<ReportActions> | ReportAction[],
1000+
isOffline: boolean | undefined = undefined,
1001+
): Array<ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.IOU>> {
1002+
// If the report is not an IOU, Expense report, or Invoice, it shouldn't have money request actions.
10031003
const report = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
10041004
if (report?.type !== CONST.REPORT.TYPE.IOU && report?.type !== CONST.REPORT.TYPE.EXPENSE && report?.type !== CONST.REPORT.TYPE.INVOICE) {
1005-
return;
1005+
return [];
10061006
}
10071007

10081008
const reportActionsArray = Array.isArray(reportActions) ? reportActions : Object.values(reportActions ?? {});
10091009
if (!reportActionsArray.length) {
1010-
return;
1010+
return [];
10111011
}
10121012

10131013
const iouRequestActions = [];
@@ -1035,6 +1035,15 @@ function getOneTransactionThreadReportID(reportID: string, reportActions: OnyxEn
10351035
iouRequestActions.push(action);
10361036
}
10371037
}
1038+
return iouRequestActions;
1039+
}
1040+
1041+
/**
1042+
* Gets the reportID for the transaction thread associated with a report by iterating over the reportActions and identifying the IOU report actions.
1043+
* Returns a reportID if there is exactly one transaction thread for the report, and null otherwise.
1044+
*/
1045+
function getOneTransactionThreadReportID(reportID: string, reportActions: OnyxEntry<ReportActions> | ReportAction[], isOffline: boolean | undefined = undefined): string | undefined {
1046+
const iouRequestActions = getMoneyRequestActions(reportID, reportActions, isOffline);
10381047

10391048
// If we don't have any IOU request actions, or we have more than one IOU request actions, this isn't a oneTransaction report
10401049
if (!iouRequestActions.length || iouRequestActions.length > 1) {
@@ -1054,6 +1063,27 @@ function getOneTransactionThreadReportID(reportID: string, reportActions: OnyxEn
10541063
return singleAction.childReportID;
10551064
}
10561065

1066+
/**
1067+
* Returns true if all transactions on the report have the same ownerID
1068+
*/
1069+
function hasSameActorForAllTransactions(reportID: string, reportActions: OnyxEntry<ReportActions> | ReportAction[], isOffline: boolean | undefined = undefined): boolean {
1070+
const iouRequestActions = getMoneyRequestActions(reportID, reportActions, isOffline);
1071+
if (!iouRequestActions.length) {
1072+
return true;
1073+
}
1074+
1075+
let actorID: number | undefined;
1076+
1077+
for (const action of iouRequestActions) {
1078+
if (actorID !== undefined && actorID !== action?.actorAccountID) {
1079+
return false;
1080+
}
1081+
actorID = action?.actorAccountID;
1082+
}
1083+
1084+
return true;
1085+
}
1086+
10571087
/**
10581088
* When we delete certain reports, we want to check whether there are any visible actions left to display.
10591089
* If there are no visible actions left (including system messages), we can hide the report from view entirely
@@ -1834,6 +1864,7 @@ export {
18341864
getRenamedAction,
18351865
isCardIssuedAction,
18361866
getCardIssuedMessage,
1867+
hasSameActorForAllTransactions,
18371868
};
18381869

18391870
export type {LastVisibleMessage};

Diff for: src/libs/ReportUtils.ts

+18-9
Original file line numberDiff line numberDiff line change
@@ -1580,12 +1580,20 @@ function hasOnlyNonReimbursableTransactions(iouReportID: string | undefined): bo
15801580
return transactions.every((transaction) => !TransactionUtils.getReimbursable(transaction));
15811581
}
15821582

1583+
/**
1584+
* Checks if a report has only transactions with same ownerID
1585+
*/
1586+
function isSingleActorMoneyReport(reportID: string): boolean {
1587+
const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] ?? ([] as ReportAction[]);
1588+
return !!ReportActionsUtils.hasSameActorForAllTransactions(reportID, reportActions);
1589+
}
1590+
15831591
/**
15841592
* Checks if a report has only one transaction associated with it
15851593
*/
15861594
function isOneTransactionReport(reportID: string): boolean {
15871595
const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] ?? ([] as ReportAction[]);
1588-
return ReportActionsUtils.getOneTransactionThreadReportID(reportID, reportActions) !== null;
1596+
return !!ReportActionsUtils.getOneTransactionThreadReportID(reportID, reportActions);
15891597
}
15901598

15911599
/*
@@ -2217,7 +2225,7 @@ function getIcons(
22172225
if (isChatThread(report)) {
22182226
const parentReportAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID];
22192227

2220-
const actorAccountID = getReportActionActorAccountID(parentReportAction, report);
2228+
const actorAccountID = getReportActionActorAccountID(parentReportAction);
22212229
const actorDisplayName = PersonalDetailsUtils.getDisplayNameOrDefault(allPersonalDetails?.[actorAccountID ?? -1], '', false);
22222230
const actorIcon = {
22232231
id: actorAccountID,
@@ -2312,7 +2320,7 @@ function getIcons(
23122320
const isManager = currentUserAccountID === report?.managerID;
23132321

23142322
// For one transaction IOUs, display a simplified report icon
2315-
if (isOneTransactionReport(report?.reportID ?? '-1')) {
2323+
if (isOneTransactionReport(report?.reportID ?? '-1') || isSingleActorMoneyReport(report?.reportID ?? '-1')) {
23162324
return [ownerIcon];
23172325
}
23182326

@@ -4826,9 +4834,9 @@ function buildOptimisticReportPreview(
48264834
},
48274835
],
48284836
created,
4829-
accountID: iouReport?.managerID ?? -1,
4837+
accountID: iouReport?.ownerAccountID ?? -1,
48304838
// The preview is initially whispered if created with a receipt, so the actor is the current user as well
4831-
actorAccountID: hasReceipt ? currentUserAccountID : iouReport?.managerID ?? -1,
4839+
actorAccountID: hasReceipt ? currentUserAccountID : iouReport?.ownerAccountID ?? -1,
48324840
childReportID: childReportID ?? iouReport?.reportID,
48334841
childMoneyRequestCount: 1,
48344842
childLastMoneyRequestComment: comment,
@@ -6649,7 +6657,7 @@ function shouldReportShowSubscript(report: OnyxEntry<Report>): boolean {
66496657
return true;
66506658
}
66516659

6652-
if (isExpenseReport(report) && isOneTransactionReport(report?.reportID ?? '-1')) {
6660+
if (isExpenseReport(report)) {
66536661
return true;
66546662
}
66556663

@@ -6661,7 +6669,7 @@ function shouldReportShowSubscript(report: OnyxEntry<Report>): boolean {
66616669
return true;
66626670
}
66636671

6664-
if (isInvoiceRoom(report)) {
6672+
if (isInvoiceRoom(report) || isInvoiceReport(report)) {
66656673
return true;
66666674
}
66676675

@@ -7543,10 +7551,10 @@ function canLeaveChat(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>): boo
75437551
return (isChatThread(report) && !!getReportNotificationPreference(report)) || isUserCreatedPolicyRoom(report) || isNonAdminOrOwnerOfPolicyExpenseChat(report, policy);
75447552
}
75457553

7546-
function getReportActionActorAccountID(reportAction: OnyxInputOrEntry<ReportAction>, iouReport: OnyxInputOrEntry<Report> | undefined): number | undefined {
7554+
function getReportActionActorAccountID(reportAction: OnyxInputOrEntry<ReportAction>): number | undefined {
75477555
switch (reportAction?.actionName) {
75487556
case CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW:
7549-
return !isEmptyObject(iouReport) ? iouReport.managerID : reportAction?.childManagerAccountID;
7557+
return reportAction?.childOwnerAccountID ?? reportAction?.actorAccountID;
75507558

75517559
case CONST.REPORT.ACTIONS.TYPE.SUBMITTED:
75527560
return reportAction?.adminAccountID ?? reportAction?.actorAccountID;
@@ -8127,6 +8135,7 @@ export {
81278135
isIndividualInvoiceRoom,
81288136
isAuditor,
81298137
hasMissingInvoiceBankAccount,
8138+
isSingleActorMoneyReport,
81308139
};
81318140

81328141
export type {

0 commit comments

Comments
 (0)