Skip to content
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

fix: display thread of send money request as normal thread #43742

Merged
merged 9 commits into from
Jun 27, 2024
2 changes: 1 addition & 1 deletion src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ Onyx.connect({
const transactionThreadReportID = ReportActionUtils.getOneTransactionThreadReportID(reportID, actions[reportActions[0]]);
if (transactionThreadReportID) {
const transactionThreadReportActionsArray = Object.values(actions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`] ?? {});
sortedReportActions = ReportActionUtils.getCombinedReportActions(reportActionsArray, transactionThreadReportActionsArray, reportID);
sortedReportActions = ReportActionUtils.getCombinedReportActions(sortedReportActions, transactionThreadReportActionsArray, reportID);
}

lastReportActions[reportID] = sortedReportActions[0];
Expand Down
11 changes: 7 additions & 4 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,14 @@ function shouldIgnoreGap(currentReportAction: ReportAction | undefined, nextRepo
* transaction thread report in order to correctly display reportActions from both reports in the one-transaction report view.
*/
function getCombinedReportActions(reportActions: ReportAction[], transactionThreadReportActions: ReportAction[], reportID?: string): ReportAction[] {
if (isEmptyObject(transactionThreadReportActions)) {
const isSentMoneyReport = reportActions.some((action) => isSentMoneyReportAction(action));

// We don't want to combine report actions of transaction thread in iou report of send money request because we display the transaction report of send money request as a normal thread
if (isEmptyObject(transactionThreadReportActions) || isSentMoneyReport) {
return reportActions;
}

// Filter out the created action from the transaction thread report actions, since we already have the parent report's created action in `reportActions`
// Filter out request money actions because we don't want to show any preview actions for one transaction reports
const filteredTransactionThreadReportActions = transactionThreadReportActions?.filter((action) => action.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED);

const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
Expand All @@ -390,9 +393,9 @@ function getCombinedReportActions(reportActions: ReportAction[], transactionThre
}
const actionType = getOriginalMessage(action)?.type ?? '';
if (isSelfDM) {
return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && !isSentMoneyReportAction(action);
return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE;
}
return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && actionType !== CONST.IOU.REPORT_ACTION_TYPE.TRACK && !isSentMoneyReportAction(action);
return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && actionType !== CONST.IOU.REPORT_ACTION_TYPE.TRACK;
});

return getSortedReportActions(filteredReportActions, true);
Expand Down
12 changes: 9 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2916,7 +2916,7 @@ function getTransactionReportName(reportAction: OnyxEntry<ReportAction | Optimis
return Localize.translateLocal('iou.threadTrackReportName', {formattedAmount, comment});
}
if (ReportActionsUtils.isSentMoneyReportAction(reportAction)) {
return Localize.translateLocal('iou.threadPaySomeoneReportName', {formattedAmount, comment});
return getIOUReportActionDisplayMessage(reportAction as ReportAction, transaction);
}
return Localize.translateLocal('iou.threadExpenseReportName', {formattedAmount, comment});
}
Expand Down Expand Up @@ -6624,7 +6624,11 @@ function getAllAncestorReportActions(report: Report | null | undefined): Ancesto
const parentReport = getReportOrDraftReport(parentReportID);
const parentReportAction = ReportActionsUtils.getReportAction(parentReportID, parentReportActionID ?? '-1');

if (!parentReportAction || ReportActionsUtils.isTransactionThread(parentReportAction) || ReportActionsUtils.isReportPreviewAction(parentReportAction)) {
if (
!parentReportAction ||
(ReportActionsUtils.isTransactionThread(parentReportAction) && !ReportActionsUtils.isSentMoneyReportAction(parentReportAction)) ||
ReportActionsUtils.isReportPreviewAction(parentReportAction)
) {
break;
}

Expand Down Expand Up @@ -6670,7 +6674,9 @@ function getAllAncestorReportActionIDs(report: Report | null | undefined, includ

if (
!parentReportAction ||
(!includeTransactionThread && (ReportActionsUtils.isTransactionThread(parentReportAction) || ReportActionsUtils.isReportPreviewAction(parentReportAction)))
(!includeTransactionThread &&
((ReportActionsUtils.isTransactionThread(parentReportAction) && !ReportActionsUtils.isSentMoneyReportAction(parentReportAction)) ||
ReportActionsUtils.isReportPreviewAction(parentReportAction)))
) {
break;
}
Expand Down
3 changes: 1 addition & 2 deletions src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,7 @@ function ReportActionItem({
// For the pay flow, we only want to show MoneyRequestAction when sending money. When paying, we display a regular system message
(ReportActionsUtils.getOriginalMessage(action)?.type === CONST.IOU.REPORT_ACTION_TYPE.CREATE ||
ReportActionsUtils.getOriginalMessage(action)?.type === CONST.IOU.REPORT_ACTION_TYPE.SPLIT ||
ReportActionsUtils.getOriginalMessage(action)?.type === CONST.IOU.REPORT_ACTION_TYPE.TRACK ||
isSendingMoney)
ReportActionsUtils.getOriginalMessage(action)?.type === CONST.IOU.REPORT_ACTION_TYPE.TRACK)
) {
// There is no single iouReport for bill splits, so only 1:1 requests require an iouReportID
const iouReportID = ReportActionsUtils.getOriginalMessage(action)?.IOUReportID ? ReportActionsUtils.getOriginalMessage(action)?.IOUReportID?.toString() ?? '-1' : '-1';
Expand Down
4 changes: 3 additions & 1 deletion src/pages/home/report/ReportActionsListItemRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ function ReportActionsListItemRenderer({
parentReportActionForTransactionThread,
}: ReportActionsListItemRendererProps) {
const shouldDisplayParentAction =
reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED && ReportUtils.isChatThread(report) && !ReportActionsUtils.isTransactionThread(parentReportAction);
reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED &&
ReportUtils.isChatThread(report) &&
(!ReportActionsUtils.isTransactionThread(parentReportAction) || ReportActionsUtils.isSentMoneyReportAction(parentReportAction));

/**
* Create a lightweight ReportAction so as to keep the re-rendering as light as possible by
Expand Down
Loading