Skip to content

Commit ce886f9

Browse files
authored
Merge pull request Expensify#62024 from Expensify/revert-60292-VickyStash/feature/58828-stop-creating-optimistic-transaction-RequestMoney
[CP Staging] Revert "Stop creating the transaction thread reports optimistically for RequestMoney"
2 parents a4f66c7 + 6b6c84d commit ce886f9

File tree

16 files changed

+190
-320
lines changed

16 files changed

+190
-320
lines changed

src/CONST.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,6 @@ const CONST = {
10411041
EMPTY_ARRAY,
10421042
EMPTY_OBJECT,
10431043
DEFAULT_NUMBER_ID,
1044-
FAKE_REPORT_ID: 'FAKE_REPORT_ID',
10451044
USE_EXPENSIFY_URL,
10461045
EXPENSIFY_URL,
10471046
GOOGLE_MEET_URL_ANDROID: 'https://meet.google.com',

src/ROUTES.ts

+5-29
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,12 @@ const ROUTES = {
8383
backTo,
8484
moneyRequestReportActionID,
8585
transactionID,
86-
iouReportID,
8786
}: {
8887
reportID: string | undefined;
8988
reportActionID?: string;
9089
backTo?: string;
9190
moneyRequestReportActionID?: string;
9291
transactionID?: string;
93-
iouReportID?: string;
9492
}) => {
9593
if (!reportID) {
9694
Log.warn('Invalid reportID is used to build the SEARCH_REPORT route');
@@ -107,10 +105,6 @@ const ROUTES = {
107105
queryParams.push(`moneyRequestReportActionID=${moneyRequestReportActionID}`);
108106
}
109107

110-
if (iouReportID) {
111-
queryParams.push(`iouReportID=${iouReportID}`);
112-
}
113-
114108
const queryString = queryParams.length > 0 ? (`${baseRoute}?${queryParams.join('&')}` as const) : baseRoute;
115109
return getUrlWithBackToParam(queryString, backTo);
116110
},
@@ -382,19 +376,10 @@ const ROUTES = {
382376
REPORT: 'r',
383377
REPORT_WITH_ID: {
384378
route: 'r/:reportID?/:reportActionID?',
385-
getRoute: (
386-
reportID: string | undefined,
387-
reportActionID?: string,
388-
referrer?: string,
389-
moneyRequestReportActionID?: string,
390-
transactionID?: string,
391-
backTo?: string,
392-
iouReportID?: string,
393-
) => {
379+
getRoute: (reportID: string | undefined, reportActionID?: string, referrer?: string, moneyRequestReportActionID?: string, transactionID?: string, backTo?: string) => {
394380
if (!reportID) {
395381
Log.warn('Invalid reportID is used to build the REPORT_WITH_ID route');
396382
}
397-
398383
const baseRoute = reportActionID ? (`r/${reportID}/${reportActionID}` as const) : (`r/${reportID}` as const);
399384

400385
const queryParams: string[] = [];
@@ -408,10 +393,6 @@ const ROUTES = {
408393
queryParams.push(`transactionID=${transactionID}`);
409394
}
410395

411-
if (iouReportID) {
412-
queryParams.push(`iouReportID=${iouReportID}`);
413-
}
414-
415396
const queryString = queryParams.length > 0 ? `?${queryParams.join('&')}` : '';
416397

417398
return getUrlWithBackToParam(`${baseRoute}${queryString}` as const, backTo);
@@ -593,15 +574,10 @@ const ROUTES = {
593574
},
594575
MONEY_REQUEST_HOLD_REASON: {
595576
route: ':type/edit/reason/:transactionID?/:searchHash?',
596-
getRoute: (type: ValueOf<typeof CONST.POLICY.TYPE>, transactionID: string, reportID: string | undefined, backTo: string, searchHash?: number) => {
597-
let route = searchHash
598-
? (`${type as string}/edit/reason/${transactionID}/${searchHash}/?backTo=${backTo}` as const)
599-
: (`${type as string}/edit/reason/${transactionID}/?backTo=${backTo}` as const);
600-
601-
if (reportID) {
602-
route = `${route}&reportID=${reportID}` as const;
603-
}
604-
577+
getRoute: (type: ValueOf<typeof CONST.POLICY.TYPE>, transactionID: string, reportID: string, backTo: string, searchHash?: number) => {
578+
const route = searchHash
579+
? (`${type as string}/edit/reason/${transactionID}/${searchHash}/?backTo=${backTo}&reportID=${reportID}` as const)
580+
: (`${type as string}/edit/reason/${transactionID}/?backTo=${backTo}&reportID=${reportID}` as const);
605581
return route;
606582
},
607583
},

src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx

+7-20
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,14 @@ import {convertToDisplayString} from '@libs/CurrencyUtils';
2525
import {getThreadReportIDsForTransactions} from '@libs/MoneyRequestReportUtils';
2626
import {navigationRef} from '@libs/Navigation/Navigation';
2727
import {getIOUActionForTransactionID} from '@libs/ReportActionsUtils';
28-
import {generateReportID, getMoneyRequestSpendBreakdown} from '@libs/ReportUtils';
28+
import {getMoneyRequestSpendBreakdown} from '@libs/ReportUtils';
2929
import {compareValues} from '@libs/SearchUIUtils';
3030
import shouldShowTransactionYear from '@libs/TransactionUtils/shouldShowTransactionYear';
3131
import Navigation from '@navigation/Navigation';
32-
import type {ReportsSplitNavigatorParamList} from '@navigation/types';
3332
import variables from '@styles/variables';
3433
import CONST from '@src/CONST';
3534
import NAVIGATORS from '@src/NAVIGATORS';
36-
import type {Route} from '@src/ROUTES';
3735
import ROUTES from '@src/ROUTES';
38-
import type SCREENS from '@src/SCREENS';
3936
import type * as OnyxTypes from '@src/types/onyx';
4037
import {useMoneyRequestReportContext} from './MoneyRequestReportContext';
4138
import MoneyRequestReportTableHeader from './MoneyRequestReportTableHeader';
@@ -75,8 +72,6 @@ type SortedTransactions = {
7572
sortOrder: SortOrder;
7673
};
7774

78-
type ReportScreenNavigationProps = ReportsSplitNavigatorParamList[typeof SCREENS.REPORT];
79-
8075
const isSortableColumnName = (key: unknown): key is SortableColumnName => !!sortableColumnNames.find((val) => val === key);
8176

8277
const getTransactionKey = (transaction: OnyxTypes.Transaction, key: SortableColumnName) => {
@@ -155,27 +150,19 @@ function MoneyRequestReportTransactionList({report, transactions, reportActions,
155150
const navigateToTransaction = useCallback(
156151
(activeTransaction: OnyxTypes.Transaction) => {
157152
const iouAction = getIOUActionForTransactionID(reportActions, activeTransaction.transactionID);
158-
const reportIDToNavigate = iouAction?.childReportID ?? generateReportID();
153+
const reportIDToNavigate = iouAction?.childReportID;
154+
if (!reportIDToNavigate) {
155+
return;
156+
}
159157

160-
const backTo = Navigation.getActiveRoute() as Route;
158+
const backTo = Navigation.getActiveRoute();
161159

162160
// Single transaction report will open in RHP, and we need to find every other report ID for the rest of transactions
163161
// to display prev/next arrows in RHP for navigating between transactions
164162
const sortedSiblingTransactionReportIDs = getThreadReportIDsForTransactions(reportActions, sortedTransactions);
165163
setActiveTransactionThreadIDs(sortedSiblingTransactionReportIDs);
166164

167-
const routeParams = {
168-
reportID: reportIDToNavigate,
169-
backTo,
170-
} as ReportScreenNavigationProps;
171-
172-
if (!iouAction?.childReportID) {
173-
routeParams.moneyRequestReportActionID = iouAction?.reportActionID;
174-
routeParams.transactionID = activeTransaction.transactionID;
175-
routeParams.iouReportID = activeTransaction.reportID;
176-
}
177-
178-
Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute(routeParams));
165+
Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID: reportIDToNavigate, backTo}));
179166
},
180167
[reportActions, sortedTransactions],
181168
);

src/components/ReportActionItem/MoneyRequestAction.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function MoneyRequestAction({
9898
const transactionID = isMoneyRequestAction(action) ? getOriginalMessage(action)?.IOUTransactionID : CONST.DEFAULT_NUMBER_ID;
9999
if (!action?.childReportID && transactionID && action.reportActionID) {
100100
const optimisticReportID = generateReportID();
101-
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(optimisticReportID, undefined, undefined, action.reportActionID, transactionID, Navigation.getActiveRoute(), requestReportID));
101+
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(optimisticReportID, undefined, undefined, action.reportActionID, transactionID, Navigation.getActiveRoute()));
102102
return;
103103
}
104104

src/libs/API/parameters/CreatePerDiemRequestParams.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type CreatePerDiemRequestParams = {
1717
createdChatReportActionID?: string;
1818
createdIOUReportActionID?: string;
1919
reportPreviewReportActionID: string;
20-
transactionThreadReportID?: string;
20+
transactionThreadReportID: string;
2121
createdReportActionIDForThread: string | undefined;
2222
billable?: boolean;
2323
attendees?: string;

src/libs/API/parameters/HoldMoneyRequestParams.ts

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ type HoldMoneyRequestParams = {
33
comment: string;
44
reportActionID: string;
55
commentReportActionID: string;
6-
transactionThreadReportID?: string;
7-
createdReportActionIDForThread?: string;
86
};
97

108
export default HoldMoneyRequestParams;

src/libs/API/parameters/MergeDuplicatesParams.ts

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ type MergeDuplicatesParams = {
1313
receiptID: number;
1414
reportID: string | undefined;
1515
reportActionID?: string | undefined;
16-
transactionThreadReportID?: string;
17-
createdReportActionIDForThread?: string;
1816
};
1917

2018
export default MergeDuplicatesParams;

src/libs/API/parameters/RequestMoneyParams.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ type RequestMoneyParams = {
2525
taxAmount: number;
2626
billable?: boolean;
2727
receiptGpsPoints?: string;
28-
transactionThreadReportID?: string;
29-
createdReportActionIDForThread?: string | undefined;
28+
transactionThreadReportID: string;
29+
createdReportActionIDForThread: string | undefined;
3030
reimbursible?: boolean;
3131
description?: string;
3232
attendees?: string;

src/libs/Navigation/types.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,6 @@ type ReportsSplitNavigatorParamList = {
16441644
backTo?: Routes;
16451645
moneyRequestReportActionID?: string;
16461646
transactionID?: string;
1647-
iouReportID?: string;
16481647
};
16491648
};
16501649

src/libs/ReportActionsUtils.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,7 @@ function getOneTransactionThreadReportID(
12381238
if (
12391239
actionType &&
12401240
iouRequestTypesSet.has(actionType) &&
1241+
action.childReportID &&
12411242
// Include deleted IOU reportActions if:
12421243
// - they have an assocaited IOU transaction ID or
12431244
// - they have visibile childActions (like comments) that we'd want to display
@@ -1265,8 +1266,8 @@ function getOneTransactionThreadReportID(
12651266
return;
12661267
}
12671268

1268-
// Since we don't always create transaction thread optimistically, we return CONST.FAKE_REPORT_ID
1269-
return singleAction?.childReportID ?? CONST.FAKE_REPORT_ID;
1269+
// Ensure we have a childReportID associated with the IOU report action
1270+
return singleAction?.childReportID;
12701271
}
12711272

12721273
/**

src/libs/ReportUtils.ts

+11-30
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ type OptimisticModifiedExpenseReportAction = Pick<
609609
| 'delegateAccountID'
610610
> & {reportID?: string};
611611

612-
type BaseOptimisticMoneyRequestEntities = {
612+
type OptimisticMoneyRequestEntities = {
613613
iouReport: Report;
614614
type: ValueOf<typeof CONST.IOU.REPORT_ACTION_TYPE>;
615615
amount: number;
@@ -627,10 +627,6 @@ type BaseOptimisticMoneyRequestEntities = {
627627
linkedTrackedExpenseReportAction?: ReportAction;
628628
};
629629

630-
type OptimisticMoneyRequestEntities = BaseOptimisticMoneyRequestEntities & {shouldGenerateOptimisticTransactionThread?: boolean};
631-
type OptimisticMoneyRequestEntitiesWithTransactionThreadFlag = BaseOptimisticMoneyRequestEntities & {shouldGenerateOptimisticTransactionThread: boolean};
632-
type OptimisticMoneyRequestEntitiesWithoutTransactionThreadFlag = BaseOptimisticMoneyRequestEntities;
633-
634630
type OptimisticTaskReport = SetRequired<
635631
Pick<
636632
Report,
@@ -3998,16 +3994,16 @@ const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry<ReportAction>, sea
39983994

39993995
const transactionID = getOriginalMessage(reportAction)?.IOUTransactionID;
40003996

4001-
if (!transactionID) {
4002-
Log.warn('Missing transactionID during the change of the money request hold status');
3997+
if (!transactionID || !reportAction.childReportID) {
3998+
Log.warn('Missing transactionID and reportAction.childReportID during the change of the money request hold status');
40033999
return;
40044000
}
40054001

40064002
const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? ({} as Transaction);
40074003
const isOnHold = isOnHoldTransactionUtils(transaction);
40084004
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${moneyRequestReport.policyID}`] ?? null;
40094005

4010-
if (isOnHold && reportAction.childReportID) {
4006+
if (isOnHold) {
40114007
unholdRequest(transactionID, reportAction.childReportID, searchHash);
40124008
} else {
40134009
const activeRoute = encodeURIComponent(Navigation.getActiveRoute());
@@ -7348,7 +7344,6 @@ function buildTransactionThread(
73487344
reportAction: OnyxEntry<ReportAction | OptimisticIOUReportAction>,
73497345
moneyRequestReport: OnyxEntry<Report>,
73507346
existingTransactionThreadReportID?: string,
7351-
optimisticTransactionThreadReportID?: string,
73527347
): OptimisticChatReport {
73537348
const participantAccountIDs = [...new Set([currentUserAccountID, Number(reportAction?.actorAccountID)])].filter(Boolean) as number[];
73547349
const existingTransactionThreadReport = getReportOrDraftReport(existingTransactionThreadReportID);
@@ -7371,7 +7366,6 @@ function buildTransactionThread(
73717366
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
73727367
parentReportActionID: reportAction?.reportActionID,
73737368
parentReportID: moneyRequestReport?.reportID,
7374-
optimisticReportID: optimisticTransactionThreadReportID,
73757369
});
73767370
}
73777371

@@ -7384,12 +7378,6 @@ function buildTransactionThread(
73847378
* 4. Transaction Thread linked to the IOU action via `parentReportActionID`
73857379
* 5. CREATED action for the Transaction Thread
73867380
*/
7387-
function buildOptimisticMoneyRequestEntities(
7388-
optimisticMoneyRequestEntities: OptimisticMoneyRequestEntitiesWithoutTransactionThreadFlag,
7389-
): [OptimisticCreatedReportAction, OptimisticCreatedReportAction, OptimisticIOUReportAction, OptimisticChatReport, OptimisticCreatedReportAction | null];
7390-
function buildOptimisticMoneyRequestEntities(
7391-
optimisticMoneyRequestEntities: OptimisticMoneyRequestEntitiesWithTransactionThreadFlag,
7392-
): [OptimisticCreatedReportAction, OptimisticCreatedReportAction, OptimisticIOUReportAction, OptimisticChatReport | undefined, OptimisticCreatedReportAction | null];
73937381
function buildOptimisticMoneyRequestEntities({
73947382
iouReport,
73957383
type,
@@ -7403,17 +7391,10 @@ function buildOptimisticMoneyRequestEntities({
74037391
isSettlingUp = false,
74047392
isSendMoneyFlow = false,
74057393
isOwnPolicyExpenseChat = false,
7406-
shouldGenerateOptimisticTransactionThread = true,
74077394
isPersonalTrackingExpense,
74087395
existingTransactionThreadReportID,
74097396
linkedTrackedExpenseReportAction,
7410-
}: OptimisticMoneyRequestEntities): [
7411-
OptimisticCreatedReportAction,
7412-
OptimisticCreatedReportAction,
7413-
OptimisticIOUReportAction,
7414-
OptimisticChatReport | undefined,
7415-
OptimisticCreatedReportAction | null,
7416-
] {
7397+
}: OptimisticMoneyRequestEntities): [OptimisticCreatedReportAction, OptimisticCreatedReportAction, OptimisticIOUReportAction, OptimisticChatReport, OptimisticCreatedReportAction | null] {
74177398
const createdActionForChat = buildOptimisticCreatedReportAction(payeeEmail);
74187399

74197400
// The `CREATED` action must be optimistically generated before the IOU action so that it won't appear after the IOU action in the chat.
@@ -7438,11 +7419,11 @@ function buildOptimisticMoneyRequestEntities({
74387419
});
74397420

74407421
// Create optimistic transactionThread and the `CREATED` action for it, if existingTransactionThreadReportID is undefined
7441-
const transactionThread = shouldGenerateOptimisticTransactionThread ? buildTransactionThread(iouAction, iouReport, existingTransactionThreadReportID) : undefined;
7442-
const createdActionForTransactionThread = !!existingTransactionThreadReportID || !shouldGenerateOptimisticTransactionThread ? null : buildOptimisticCreatedReportAction(payeeEmail);
7422+
const transactionThread = buildTransactionThread(iouAction, iouReport, existingTransactionThreadReportID);
7423+
const createdActionForTransactionThread = existingTransactionThreadReportID ? null : buildOptimisticCreatedReportAction(payeeEmail);
74437424

74447425
// The IOU action and the transactionThread are co-dependent as parent-child, so we need to link them together
7445-
iouAction.childReportID = existingTransactionThreadReportID ?? transactionThread?.reportID;
7426+
iouAction.childReportID = existingTransactionThreadReportID ?? transactionThread.reportID;
74467427

74477428
return [createdActionForChat, createdActionForIOUReport, iouAction, transactionThread, createdActionForTransactionThread];
74487429
}
@@ -9231,12 +9212,12 @@ function getAllAncestorReportActionIDs(report: Report | null | undefined, includ
92319212

92329213
/**
92339214
* Get optimistic data of parent report action
9234-
* @param reportOrID The reportID of the report that is updated or the optimistic report on its own
9215+
* @param reportID The reportID of the report that is updated
92359216
* @param lastVisibleActionCreated Last visible action created of the child report
92369217
* @param type The type of action in the child report
92379218
*/
9238-
function getOptimisticDataForParentReportAction(reportOrID: Report | string | undefined, lastVisibleActionCreated: string, type: string): Array<OnyxUpdate | null> {
9239-
const report = typeof reportOrID === 'string' ? getReportOrDraftReport(reportOrID) : reportOrID;
9219+
function getOptimisticDataForParentReportAction(reportID: string | undefined, lastVisibleActionCreated: string, type: string): Array<OnyxUpdate | null> {
9220+
const report = getReportOrDraftReport(reportID);
92409221

92419222
if (!report || isEmptyObject(report)) {
92429223
return [];

0 commit comments

Comments
 (0)