Skip to content

Commit

Permalink
move combined reportAction logic into ReportActionUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
NikkiWines committed Apr 5, 2024
1 parent a0a3ff0 commit 2e030d9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
22 changes: 22 additions & 0 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ function getOneTransactionThreadReportID(reportActions: OnyxEntry<ReportActions>
(iouRequestTypes.includes(action.originalMessage.type) ?? []) &&
action.childReportID &&
// Include deleted IOU reportActions if they have childAactions because we want to display those comments
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
((action.originalMessage.deleted && action.childVisibleActionCount) || action.originalMessage.IOUTransactionID),
);

Expand Down Expand Up @@ -279,6 +280,26 @@ function getSortedReportActions(reportActions: ReportAction[] | null, shouldSort
return sortedActions;
}

/**
* Returns a combined list of report actions for a report and associated transaction thread report
*/
function getCombinedReportActions(reportActions: ReportAction[], transactionThreadReportActions: ReportAction[]): ReportAction[] {
if (isEmptyObject(transactionThreadReportActions)) {
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`
const filteredTransactionThreadReportActions = transactionThreadReportActions?.filter((action) => action.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED);

This comment has been minimized.

Copy link
@c3024

c3024 Jul 29, 2024

If we change some details in a track expense and then submit it to someone then the parent report thread created action can be newer than the transaction thread report created action. In this case, the transaction thread report created action needs to be retained. More details here Expensify#42795


// Filter out request and send money request actions because we don't want to show any preview actions for one transaction reports
const filteredReportActions = [...reportActions, ...filteredTransactionThreadReportActions].filter((action) => {
const actionType = (action as OriginalMessageIOU).originalMessage?.type ?? '';
return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && !isSentMoneyReportAction(action);
});

return getSortedReportActions(filteredReportActions, true);
}

/**
* Returns the largest gapless range of reportActions including a the provided reportActionID, where a "gap" is defined as a reportAction's `previousReportActionID` not matching the previous reportAction in the sortedReportActions array.
* See unit tests for example of inputs and expected outputs.
Expand Down Expand Up @@ -1077,6 +1098,7 @@ export {
isApprovedOrSubmittedReportAction,
getReportPreviewAction,
getSortedReportActions,
getCombinedReportActions,
getSortedReportActionsForDisplay,
isConsecutiveActionMadeByPreviousActor,
isCreatedAction,
Expand Down
14 changes: 1 addition & 13 deletions src/pages/home/report/ReportActionsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,7 @@ function ReportActionsView({
// Get a sorted array of reportActions for both the current report and the transaction thread report associated with this report (if there is one)
// so that we display transaction-level and report-level report actions in order in the one-transaction view
const combinedReportActions = useMemo(() => {
if (isEmptyObject(transactionThreadReportActions)) {
return allReportActions;
}

// Filter out the created action from the transaction thread report actions, since we already have the parent report's created action in `reportActions`
const filteredTransactionThreadReportActions = transactionThreadReportActions?.filter((action) => action.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED);

// Filter out request and send money request actions because we don't want to show any preview actions for one transaction reports
const filteredReportActions = [...allReportActions, ...filteredTransactionThreadReportActions].filter((action) => {
const actionType = (action as OnyxTypes.OriginalMessageIOU).originalMessage?.type ?? '';
return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && !ReportActionsUtils.isSentMoneyReportAction(action);
});
return ReportActionsUtils.getSortedReportActions(filteredReportActions, true);
return ReportActionsUtils.getCombinedReportActions(allReportActions, transactionThreadReportActions);
}, [allReportActions, transactionThreadReportActions]);

const indexOfLinkedAction = useMemo(() => {
Expand Down

0 comments on commit 2e030d9

Please sign in to comment.