From 255255bdcf12d6ae5116f33ede11cdec33119abd Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Tue, 2 Apr 2024 19:49:54 -0700 Subject: [PATCH 01/16] fix reversed actions logic --- src/pages/home/report/ReportActionsView.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index 99fa266aa0de5..bced0fdbea226 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -360,13 +360,13 @@ function ReportActionsView({ } if (!isEmptyObject(transactionThreadReport)) { - // Get newer actions based on the newest reportAction for the current report + // Get older actions based on the oldest reportAction for the current report const oldestActionCurrentReport = reportActionIDMap.findLast((item) => item.reportID === reportID); - Report.getNewerActions(oldestActionCurrentReport?.reportID ?? '0', oldestActionCurrentReport?.reportActionID ?? '0'); + Report.getOlderActions(oldestActionCurrentReport?.reportID ?? '0', oldestActionCurrentReport?.reportActionID ?? '0'); - // Get newer actions based on the newest reportAction for the transaction thread report + // Get older actions based on the oldest reportAction for the transaction thread report const oldestActionTransactionThreadReport = reportActionIDMap.findLast((item) => item.reportID === transactionThreadReport.reportID); - Report.getNewerActions(oldestActionTransactionThreadReport?.reportID ?? '0', oldestActionTransactionThreadReport?.reportActionID ?? '0'); + Report.getOlderActions(oldestActionTransactionThreadReport?.reportID ?? '0', oldestActionTransactionThreadReport?.reportActionID ?? '0'); } else { // Retrieve the next REPORT.ACTIONS.LIMIT sized page of comments Report.getOlderActions(reportID, oldestReportAction.reportActionID); From f9d5eaafd9e2063dee81d0b4e1696bd6260c021c Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Thu, 4 Apr 2024 16:38:19 -0700 Subject: [PATCH 02/16] don't display report as one-transaction report if it has previously deleted IOU requests --- src/libs/ReportActionsUtils.ts | 3 ++- src/types/onyx/OriginalMessage.ts | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index bf1a9f994c372..434cabbf2bb6d 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -230,7 +230,8 @@ function getOneTransactionThreadReportID(reportActions: OnyxEntry action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && (iouRequestTypes.includes(action.originalMessage.type) ?? []) && action.childReportID && - action.originalMessage.IOUTransactionID, + // Include deleted IOU reportActions because they might have associated comments that we'd want to display + (action.originalMessage.deleted || action.originalMessage.IOUTransactionID), ); // If we don't have any IOU request actions, or we have more than one IOU request actions, this isn't a oneTransaction report diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index 2e24fe00539a1..764a490cc9176 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -66,6 +66,7 @@ type IOUMessage = { type: ValueOf; cancellationReason?: string; paymentType?: PaymentMethodType; + deleted?: string; /** Only exists when we are sending money */ IOUDetails?: IOUDetails; }; From a0a3ff047054fb3b79f56369ee5cca6c78da28b6 Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Thu, 4 Apr 2024 16:49:44 -0700 Subject: [PATCH 03/16] only include deleted IOUs if they have visible child actions we need to display --- src/libs/ReportActionsUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 434cabbf2bb6d..e6c63df9d9a96 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -230,8 +230,8 @@ function getOneTransactionThreadReportID(reportActions: OnyxEntry action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && (iouRequestTypes.includes(action.originalMessage.type) ?? []) && action.childReportID && - // Include deleted IOU reportActions because they might have associated comments that we'd want to display - (action.originalMessage.deleted || action.originalMessage.IOUTransactionID), + // Include deleted IOU reportActions if they have childAactions because we want to display those comments + ((action.originalMessage.deleted && action.childVisibleActionCount) || action.originalMessage.IOUTransactionID), ); // If we don't have any IOU request actions, or we have more than one IOU request actions, this isn't a oneTransaction report From 2e030d9709cf90a886f386c63324b92108e62ea3 Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Fri, 5 Apr 2024 11:30:30 -0700 Subject: [PATCH 04/16] move combined reportAction logic into ReportActionUtils --- src/libs/ReportActionsUtils.ts | 22 +++++++++++++++++++++ src/pages/home/report/ReportActionsView.tsx | 14 +------------ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index e6c63df9d9a96..881aabdd7493e 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -231,6 +231,7 @@ function getOneTransactionThreadReportID(reportActions: OnyxEntry (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), ); @@ -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); + + // 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. @@ -1077,6 +1098,7 @@ export { isApprovedOrSubmittedReportAction, getReportPreviewAction, getSortedReportActions, + getCombinedReportActions, getSortedReportActionsForDisplay, isConsecutiveActionMadeByPreviousActor, isCreatedAction, diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index 43081cf72a33c..7c2f15705788b 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -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(() => { From 1ca6f0d3f1136abaa5439dd3419acb067d55ccf2 Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Fri, 5 Apr 2024 11:30:46 -0700 Subject: [PATCH 05/16] ensure lastMessageText is correct for oneTransaction reports --- src/libs/OptionsListUtils.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index bd8b799bdc527..63a41e785cffb 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -560,7 +560,13 @@ function getAlternateText( * Get the last message text from the report directly or from other sources for special cases. */ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails: Partial | null, policy?: OnyxEntry): string { - const lastReportAction = allSortedReportActions[report?.reportID ?? '']?.find((reportAction) => ReportActionUtils.shouldReportActionBeVisibleAsLastAction(reportAction)) ?? null; + let reportActions = allSortedReportActions[report?.reportID ?? '']; + const transactionThreadReportID = ReportActionUtils.getOneTransactionThreadReportID(allReportActions[report?.reportID ?? '']); + if (transactionThreadReportID) { + reportActions = ReportActionUtils.getCombinedReportActions(reportActions, allSortedReportActions[transactionThreadReportID]); + } + + const lastReportAction = reportActions?.find((reportAction) => ReportActionUtils.shouldReportActionBeVisibleAsLastAction(reportAction)) ?? null; // some types of actions are filtered out for lastReportAction, in some cases we need to check the actual last action const lastOriginalReportAction = lastReportActions[report?.reportID ?? ''] ?? null; let lastMessageTextFromReport = ''; From 7936ff1685130c28cb1ab33fece14710ae55fabe Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Fri, 5 Apr 2024 14:42:05 -0700 Subject: [PATCH 06/16] clarifying comment --- src/libs/ReportActionsUtils.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 881aabdd7493e..78ec1600be121 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -281,7 +281,8 @@ function getSortedReportActions(reportActions: ReportAction[] | null, shouldSort } /** - * Returns a combined list of report actions for a report and associated transaction thread report + * Returns a sorted and filtered list of report actions from both the parent report and the child + * transaction thread report in order to display details from both report s in the one-transaction report view. */ function getCombinedReportActions(reportActions: ReportAction[], transactionThreadReportActions: ReportAction[]): ReportAction[] { if (isEmptyObject(transactionThreadReportActions)) { From 50a275cbd65575cd303f0b2c538e8e7ebf5a5833 Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Fri, 5 Apr 2024 16:18:20 -0700 Subject: [PATCH 07/16] minor style change and also use isMessageDeleted instead of originalMessage.deleted --- src/libs/ReportActionsUtils.ts | 74 ++++++++++++--------- src/pages/home/report/ReportActionsView.tsx | 8 +-- 2 files changed, 45 insertions(+), 37 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 78ec1600be121..0f6ca4168332d 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -213,37 +213,6 @@ function isTransactionThread(parentReportAction: OnyxEntry | Empty ); } -/** - * Returns the reportID for the transaction thread associated with a report by iterating over the reportActions and identifying the IOU report actions with a childReportID. Returns a reportID if there is exactly one transaction thread for the report, and null otherwise. - */ -function getOneTransactionThreadReportID(reportActions: OnyxEntry | ReportAction[]): string | null { - const reportActionsArray = Object.values(reportActions ?? {}); - - if (!reportActionsArray.length) { - return null; - } - - // Get all IOU report actions for the report. - const iouRequestTypes: Array> = [CONST.IOU.REPORT_ACTION_TYPE.CREATE, CONST.IOU.REPORT_ACTION_TYPE.SPLIT, CONST.IOU.REPORT_ACTION_TYPE.PAY]; - const iouRequestActions = reportActionsArray.filter( - (action) => - action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && - (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), - ); - - // If we don't have any IOU request actions, or we have more than one IOU request actions, this isn't a oneTransaction report - if (!iouRequestActions.length || iouRequestActions.length > 1) { - return null; - } - - // Ensure we have a childReportID associated with the IOU report action - return iouRequestActions[0].childReportID ?? null; -} - /** * Sort an array of reportActions by their created timestamp first, and reportActionID second * This gives us a stable order even in the case of multiple reportActions created on the same millisecond @@ -281,8 +250,8 @@ function getSortedReportActions(reportActions: ReportAction[] | null, shouldSort } /** - * Returns a sorted and filtered list of report actions from both the parent report and the child - * transaction thread report in order to display details from both report s in the one-transaction report view. + * Returns a sorted and filtered list of report actions from a report and it's associated child + * transaction thread report in order to correctly display reportActions from both reports in the one-transaction report view. */ function getCombinedReportActions(reportActions: ReportAction[], transactionThreadReportActions: ReportAction[]): ReportAction[] { if (isEmptyObject(transactionThreadReportActions)) { @@ -803,6 +772,45 @@ function isTaskAction(reportAction: OnyxEntry): boolean { ); } +/** + * Gets the reportID for the transaction thread associated with a report by iterating over the reportActions and identifying the IOU report actions. + * Returns a reportID if there is exactly one transaction thread for the report, and null otherwise. + */ +function getOneTransactionThreadReportID(reportActions: OnyxEntry | ReportAction[]): string | null { + const reportActionsArray = Object.values(reportActions ?? {}); + + if (!reportActionsArray.length) { + return null; + } + + // Get all IOU report actions for the report. + const iouRequestTypes: Array> = [CONST.IOU.REPORT_ACTION_TYPE.CREATE, CONST.IOU.REPORT_ACTION_TYPE.SPLIT, CONST.IOU.REPORT_ACTION_TYPE.PAY]; + const iouRequestActions = reportActionsArray.filter( + (action) => + action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && + (iouRequestTypes.includes(action.originalMessage.type) ?? []) && + action.childReportID && + // Include deleted IOU reportActions if they have visibile childActions (like comments) because we'll want to display + // those reports using the standard report view + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + ((isMessageDeleted(action) && action.childVisibleActionCount) || action.originalMessage.IOUTransactionID), + ); + + // If we don't have any IOU request actions, or we have more than one IOU request actions, this isn't a oneTransaction report + if (!iouRequestActions.length || iouRequestActions.length > 1) { + return null; + } + + // If there's only IOU request action associated with the report but it's been deleted, then we don't consider this a oneTransaction report + // and want to display it using the standard view + if (((iouRequestActions[0] as OriginalMessageIOU).originalMessage?.deleted ?? '') !== '') { + return null; + } + + // Ensure we have a childReportID associated with the IOU report action + return iouRequestActions[0].childReportID ?? null; +} + /** * When we delete certain reports, we want to check whether there are any visible actions left to display. * If there are no visible actions left (including system messages), we can hide the report from view entirely diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index 7c2f15705788b..88650995d8bd7 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -137,10 +137,10 @@ 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(() => { - return ReportActionsUtils.getCombinedReportActions(allReportActions, transactionThreadReportActions); - }, [allReportActions, transactionThreadReportActions]); - + const combinedReportActions = useMemo( + () => ReportActionsUtils.getCombinedReportActions(allReportActions, transactionThreadReportActions), + [allReportActions, transactionThreadReportActions], + ); const indexOfLinkedAction = useMemo(() => { if (!reportActionID) { return -1; From 48976d7127c241319af855dffdf93c2223926593 Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Thu, 11 Apr 2024 15:01:04 -0700 Subject: [PATCH 08/16] update stray function to pass correct params --- src/libs/OptionsListUtils.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 24b5ff311e4b0..71fa4d0920d5e 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -565,8 +565,9 @@ function getAlternateText( * Get the last message text from the report directly or from other sources for special cases. */ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails: Partial | null, policy?: OnyxEntry): string { - let reportActions = allSortedReportActions[report?.reportID ?? '']; - const transactionThreadReportID = ReportActionUtils.getOneTransactionThreadReportID(allReportActions[report?.reportID ?? '']); + let reportID = report?.reportID ?? ''; + let reportActions = allSortedReportActions[reportID]; + const transactionThreadReportID = ReportActionUtils.getOneTransactionThreadReportID(reportID, allReportActions[reportID]); if (transactionThreadReportID) { reportActions = ReportActionUtils.getCombinedReportActions(reportActions, allSortedReportActions[transactionThreadReportID]); } From 6423f2b808a7bc9bb4b1528169f858e95dc3890d Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Thu, 11 Apr 2024 15:25:53 -0700 Subject: [PATCH 09/16] use const --- src/libs/OptionsListUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 71fa4d0920d5e..ca0214eaf50b6 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -565,7 +565,7 @@ function getAlternateText( * Get the last message text from the report directly or from other sources for special cases. */ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails: Partial | null, policy?: OnyxEntry): string { - let reportID = report?.reportID ?? ''; + const reportID = report?.reportID ?? ''; let reportActions = allSortedReportActions[reportID]; const transactionThreadReportID = ReportActionUtils.getOneTransactionThreadReportID(reportID, allReportActions[reportID]); if (transactionThreadReportID) { From f9149cc43093bd37b9086d0a85bd07092109f42c Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Mon, 22 Apr 2024 16:37:29 +0200 Subject: [PATCH 10/16] fix typing --- src/pages/home/report/ReportActionsView.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index fbb71f62147c4..1701f427f5648 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -143,7 +143,10 @@ function ReportActionsView({ ); const parentReportActionForTransactionThread = useMemo( - () => (isEmptyObject(transactionThreadReportActions) ? null : allReportActions.find((action) => action.reportActionID === transactionThreadReport?.parentReportActionID)), + () => + isEmptyObject(transactionThreadReportActions) + ? null + : (allReportActions.find((action) => action.reportActionID === transactionThreadReport?.parentReportActionID) as OnyxEntry), [allReportActions, transactionThreadReportActions, transactionThreadReport?.parentReportActionID], ); From 6d319508fdf1cb39eafbb6c993ca0208d25b5dbc Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Mon, 22 Apr 2024 23:56:16 +0200 Subject: [PATCH 11/16] lint --- src/libs/ReportActionsUtils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index f2228bc3018ee..11e26652e253c 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -831,6 +831,7 @@ function getOneTransactionThreadReportID(reportID: string, reportActions: OnyxEn // - they have an assocaited IOU transaction ID or // - they have visibile childActions (like comments) that we'd want to display // - the action is pending deletion and the user is offline + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing (Boolean(action.originalMessage.IOUTransactionID) || (isMessageDeleted(action) && action.childVisibleActionCount) || (action.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && (isOffline ?? isNetworkOffline))), From b1e1957d776ea96e7ea983c636883961cad3c8de Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Tue, 23 Apr 2024 00:29:12 +0200 Subject: [PATCH 12/16] lint 2 --- src/libs/ReportActionsUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 11e26652e253c..2109651561559 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -831,8 +831,8 @@ function getOneTransactionThreadReportID(reportID: string, reportActions: OnyxEn // - they have an assocaited IOU transaction ID or // - they have visibile childActions (like comments) that we'd want to display // - the action is pending deletion and the user is offline - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing (Boolean(action.originalMessage.IOUTransactionID) || + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing (isMessageDeleted(action) && action.childVisibleActionCount) || (action.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && (isOffline ?? isNetworkOffline))), ); From 3714c389c35ae3c075bc8404d73fb94a7ca42d15 Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Tue, 30 Apr 2024 16:36:15 -0700 Subject: [PATCH 13/16] prettier --- src/libs/ReportActionsUtils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 47a76517d6925..0ab74ceafcac2 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -805,7 +805,6 @@ function isTaskAction(reportAction: OnyxEntry): boolean { * Returns a reportID if there is exactly one transaction thread for the report, and null otherwise. */ function getOneTransactionThreadReportID(reportID: string, reportActions: OnyxEntry | ReportAction[], isOffline: boolean | undefined = undefined): string | null { - // If the report is not an IOU, Expense report, or Invoice, it shouldn't be treated as one-transaction report. const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; if (report?.type !== CONST.REPORT.TYPE.IOU && report?.type !== CONST.REPORT.TYPE.EXPENSE && report?.type !== CONST.REPORT.TYPE.INVOICE) { From 9fc901081fa9de9f8e8c8dd997881bd5ed713dbc Mon Sep 17 00:00:00 2001 From: Nikki Wines Date: Fri, 3 May 2024 09:36:15 -0700 Subject: [PATCH 14/16] Comment update Co-authored-by: Amy Evans --- src/libs/ReportActionsUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 0ab74ceafcac2..67099154e8637 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -844,7 +844,7 @@ function getOneTransactionThreadReportID(reportID: string, reportActions: OnyxEn return null; } - // If there's only IOU request action associated with the report but it's been deleted, then we don't consider this a oneTransaction report + // If there's only one IOU request action associated with the report but it's been deleted, then we don't consider this a oneTransaction report // and want to display it using the standard view if (((iouRequestActions[0] as OriginalMessageIOU).originalMessage?.deleted ?? '') !== '') { return null; From f7cdd3f2fb2427743b0d8a5e1767c969ee15f730 Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Fri, 3 May 2024 11:21:51 -0700 Subject: [PATCH 15/16] add exception for checking report type --- src/libs/OptionsListUtils.ts | 15 +++++++-------- src/libs/ReportActionsUtils.ts | 12 +++++++----- src/pages/home/ReportScreen.tsx | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 1765a7d65034e..b599fdc6d0f10 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -266,8 +266,14 @@ Onyx.connect({ } const reportID = CollectionUtils.extractCollectionItemID(key); allReportActions[reportID] = actions; - const sortedReportActions = ReportActionUtils.getSortedReportActions(Object.values(actions), true); + let sortedReportActions = ReportActionUtils.getSortedReportActions(Object.values(actions), true); allSortedReportActions[reportID] = sortedReportActions; + + const transactionThreadReportID = ReportActionUtils.getOneTransactionThreadReportID(reportID, allReportActions[reportID], true); + if (transactionThreadReportID) { + sortedReportActions = ReportActionUtils.getCombinedReportActions(allSortedReportActions[reportID], allSortedReportActions[transactionThreadReportID]); + } + lastReportActions[reportID] = sortedReportActions[0]; // The report is only visible if it is the last action not deleted that @@ -553,13 +559,6 @@ function getAlternateText( * Get the last message text from the report directly or from other sources for special cases. */ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails: Partial | null, policy?: OnyxEntry): string { - const reportID = report?.reportID ?? ''; - let reportActions = allSortedReportActions[reportID]; - const transactionThreadReportID = ReportActionUtils.getOneTransactionThreadReportID(reportID, allReportActions[reportID]); - if (transactionThreadReportID) { - reportActions = ReportActionUtils.getCombinedReportActions(reportActions, allSortedReportActions[transactionThreadReportID]); - } - const lastReportAction = visibleReportActionItems[report?.reportID ?? ''] ?? null; // some types of actions are filtered out for lastReportAction, in some cases we need to check the actual last action diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 4201ae34d4296..9e8ba6caf9035 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -806,11 +806,13 @@ function isTaskAction(reportAction: OnyxEntry): boolean { * Gets the reportID for the transaction thread associated with a report by iterating over the reportActions and identifying the IOU report actions. * Returns a reportID if there is exactly one transaction thread for the report, and null otherwise. */ -function getOneTransactionThreadReportID(reportID: string, reportActions: OnyxEntry | ReportAction[], isOffline: boolean | undefined = undefined): string | null { - // If the report is not an IOU, Expense report, or Invoice, it shouldn't be treated as one-transaction report. - const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; - if (report?.type !== CONST.REPORT.TYPE.IOU && report?.type !== CONST.REPORT.TYPE.EXPENSE && report?.type !== CONST.REPORT.TYPE.INVOICE) { - return null; +function getOneTransactionThreadReportID(reportID: string, reportActions: OnyxEntry | ReportAction[], skipReportTypeCheck: boolean | false = false, isOffline: boolean | undefined = undefined): string | null { + if (!skipReportTypeCheck) { + // If the report is not an IOU, Expense report, or Invoice, it shouldn't be treated as one-transaction report. + const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; + if (report?.type !== CONST.REPORT.TYPE.IOU && report?.type !== CONST.REPORT.TYPE.EXPENSE && report?.type !== CONST.REPORT.TYPE.INVOICE) { + return null; + } } const reportActionsArray = Object.values(reportActions ?? {}); diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index d84d610a171a9..b82137756a284 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -347,7 +347,7 @@ function ReportScreen({ } const transactionThreadReportID = useMemo( - () => ReportActionsUtils.getOneTransactionThreadReportID(report.reportID, reportActions ?? [], isOffline), + () => ReportActionsUtils.getOneTransactionThreadReportID(report.reportID, reportActions ?? [], false, isOffline), [report.reportID, reportActions, isOffline], ); From 007011d9567128f88807dedca636a9a88e8438d3 Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Fri, 3 May 2024 12:16:29 -0700 Subject: [PATCH 16/16] lint/style --- src/libs/ReportActionsUtils.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 9e8ba6caf9035..64c4ed61f7fdf 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -806,7 +806,12 @@ function isTaskAction(reportAction: OnyxEntry): boolean { * Gets the reportID for the transaction thread associated with a report by iterating over the reportActions and identifying the IOU report actions. * Returns a reportID if there is exactly one transaction thread for the report, and null otherwise. */ -function getOneTransactionThreadReportID(reportID: string, reportActions: OnyxEntry | ReportAction[], skipReportTypeCheck: boolean | false = false, isOffline: boolean | undefined = undefined): string | null { +function getOneTransactionThreadReportID( + reportID: string, + reportActions: OnyxEntry | ReportAction[], + skipReportTypeCheck: boolean | undefined = undefined, + isOffline: boolean | undefined = undefined, +): string | null { if (!skipReportTypeCheck) { // If the report is not an IOU, Expense report, or Invoice, it shouldn't be treated as one-transaction report. const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];