Skip to content

Commit 69cfe20

Browse files
committed
Get correct transaction data in ReportActionItem
1 parent eda5932 commit 69cfe20

4 files changed

Lines changed: 28 additions & 7 deletions

File tree

‎src/pages/home/report/ReportActionItem.tsx‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ type ReportActionItemProps = {
120120
/** Report action belonging to the report's parent */
121121
parentReportAction: OnyxEntry<OnyxTypes.ReportAction>;
122122

123+
/** The transaction thread report's parentReportAction */
124+
/** It's used by withOnyx HOC */
125+
// eslint-disable-next-line react/no-unused-prop-types
126+
parentReportActionForTransactionThread: OnyxEntry<OnyxTypes.ReportAction>;
127+
123128
/** All the data of the action item */
124129
action: OnyxTypes.ReportAction;
125130

@@ -939,10 +944,10 @@ export default withOnyx<ReportActionItemProps, ReportActionItemOnyxProps>({
939944
key: ONYXKEYS.USER_WALLET,
940945
},
941946
transaction: {
942-
key: ({transactionThreadReport, reportActions}) => {
943-
const parentReportActionID = isEmptyObject(transactionThreadReport) ? '0' : transactionThreadReport.parentReportActionID;
944-
const action = reportActions?.find((reportAction) => reportAction.reportActionID === parentReportActionID);
945-
const transactionID = (action as OnyxTypes.OriginalMessageIOU)?.originalMessage.IOUTransactionID ? (action as OnyxTypes.OriginalMessageIOU).originalMessage.IOUTransactionID : 0;
947+
key: ({parentReportActionForTransactionThread}) => {
948+
const transactionID = (parentReportActionForTransactionThread as OnyxTypes.OriginalMessageIOU)?.originalMessage.IOUTransactionID
949+
? (parentReportActionForTransactionThread as OnyxTypes.OriginalMessageIOU).originalMessage.IOUTransactionID
950+
: 0;
946951
return `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`;
947952
},
948953
},

‎src/pages/home/report/ReportActionsList.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ type ReportActionsListProps = WithCurrentUserPersonalDetailsProps & {
5050
/** The report's parentReportAction */
5151
parentReportAction: OnyxEntry<OnyxTypes.ReportAction>;
5252

53+
/** The transaction thread report's parentReportAction */
54+
parentReportActionForTransactionThread: OnyxEntry<OnyxTypes.ReportAction>;
55+
5356
/** Sorted actions prepared for display */
5457
sortedReportActions: OnyxTypes.ReportAction[];
5558

@@ -148,6 +151,7 @@ function ReportActionsList({
148151
listID,
149152
onContentSizeChange,
150153
shouldEnableAutoScrollToTopThreshold,
154+
parentReportActionForTransactionThread,
151155
}: ReportActionsListProps) {
152156
const personalDetailsList = usePersonalDetails() || CONST.EMPTY_OBJECT;
153157
const styles = useThemeStyles();
@@ -524,6 +528,7 @@ function ReportActionsList({
524528
reportAction={reportAction}
525529
reportActions={reportActions}
526530
parentReportAction={parentReportAction}
531+
parentReportActionForTransactionThread={parentReportActionForTransactionThread}
527532
index={index}
528533
report={report}
529534
transactionThreadReport={transactionThreadReport}
@@ -546,6 +551,7 @@ function ReportActionsList({
546551
parentReportAction,
547552
reportActions,
548553
transactionThreadReport,
554+
parentReportActionForTransactionThread,
549555
],
550556
);
551557

‎src/pages/home/report/ReportActionsListItemRenderer.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ type ReportActionsListItemRendererProps = {
1717
/** The report's parentReportAction */
1818
parentReportAction: OnyxEntry<ReportAction>;
1919

20+
/** The transaction thread report's parentReportAction */
21+
parentReportActionForTransactionThread: OnyxEntry<ReportAction>;
22+
2023
/** Position index of the report action in the overall report FlatList view */
2124
index: number;
2225

@@ -58,6 +61,7 @@ function ReportActionsListItemRenderer({
5861
shouldDisplayNewMarker,
5962
linkedReportActionID = '',
6063
shouldDisplayReplyDivider,
64+
parentReportActionForTransactionThread,
6165
}: ReportActionsListItemRendererProps) {
6266
const shouldDisplayParentAction =
6367
reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED && ReportUtils.isChatThread(report) && !ReportActionsUtils.isTransactionThread(parentReportAction);
@@ -145,6 +149,7 @@ function ReportActionsListItemRenderer({
145149
parentReportAction={parentReportAction}
146150
report={report}
147151
transactionThreadReport={transactionThreadReport}
152+
parentReportActionForTransactionThread={parentReportActionForTransactionThread}
148153
action={action}
149154
reportActions={reportActions}
150155
linkedReportActionID={linkedReportActionID}

‎src/pages/home/report/ReportActionsView.tsx‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,24 @@ function ReportActionsView({
137137

138138
// Get a sorted array of reportActions for both the current report and the transaction thread report associated with this report (if there is one)
139139
// so that we display transaction-level and report-level report actions in order in the one-transaction view
140-
const combinedReportActions = useMemo(() => {
140+
const [combinedReportActions, parentReportActionForTransactionThread] = useMemo(() => {
141141
if (isEmptyObject(transactionThreadReportActions)) {
142-
return allReportActions;
142+
return [allReportActions, null];
143143
}
144144

145145
// Filter out the created action from the transaction thread report actions, since we already have the parent report's created action in `reportActions`
146146
const filteredTransactionThreadReportActions = transactionThreadReportActions?.filter((action) => action.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED);
147+
const moneyRequestAction = allReportActions.find((action) => {
148+
const actionType = (action as OnyxTypes.OriginalMessageIOU).originalMessage?.type ?? '';
149+
return actionType === CONST.IOU.REPORT_ACTION_TYPE.CREATE || actionType === CONST.IOU.REPORT_ACTION_TYPE.TRACK || !ReportActionsUtils.isSentMoneyReportAction(action);
150+
});
147151

148152
// Filter out the money request actions because we don't want to show any preview actions for one-transaction reports
149153
const filteredReportActions = [...allReportActions, ...filteredTransactionThreadReportActions].filter((action) => {
150154
const actionType = (action as OnyxTypes.OriginalMessageIOU).originalMessage?.type ?? '';
151155
return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && actionType !== CONST.IOU.REPORT_ACTION_TYPE.TRACK && !ReportActionsUtils.isSentMoneyReportAction(action);
152156
});
153-
return ReportActionsUtils.getSortedReportActions(filteredReportActions, true);
157+
return [ReportActionsUtils.getSortedReportActions(filteredReportActions, true), moneyRequestAction ?? null];
154158
}, [allReportActions, transactionThreadReportActions]);
155159

156160
const indexOfLinkedAction = useMemo(() => {
@@ -517,6 +521,7 @@ function ReportActionsView({
517521
transactionThreadReport={transactionThreadReport}
518522
reportActions={reportActions}
519523
parentReportAction={parentReportAction}
524+
parentReportActionForTransactionThread={parentReportActionForTransactionThread}
520525
onLayout={recordTimeToMeasureItemLayout}
521526
sortedReportActions={reportActionsToDisplay}
522527
mostRecentIOUReportActionID={mostRecentIOUReportActionID}

0 commit comments

Comments
 (0)