From 11788a873c73a1013ddb76707bd1bd1074929eec Mon Sep 17 00:00:00 2001 From: Tomasz Lesniakiewicz Date: Thu, 27 Jun 2024 11:56:56 +0200 Subject: [PATCH 1/4] fix: remove flickering effect when loading one-expense reports --- src/libs/ReportActionsUtils.ts | 36 +++++++++++++------ .../report/ReportActionItemContentCreated.tsx | 2 +- src/pages/home/report/ReportActionsView.tsx | 2 +- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 2132b97ef555a..2ca09efbc8abb 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -373,6 +373,30 @@ function shouldIgnoreGap(currentReportAction: ReportAction | undefined, nextRepo ); } +/** + * Returns filtered list for one transaction view + * Separated it from getCombinedReportActions, so it can be reused + */ +function getFilteredForOneTransactionView(reportActions: ReportAction[], isSelfDM = false): ReportAction[] { + const filteredReportActions = reportActions.filter((action) => { + // const actionType = (action as OriginalMessageIOU).originalMessage?.type ?? ''; + // if (isSelfDM) { + // return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && !isSentMoneyReportAction(action); + // } + // return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && actionType !== CONST.IOU.REPORT_ACTION_TYPE.TRACK && !isSentMoneyReportAction(action); + if (!isMoneyRequestAction(action)) { + return true; + } + 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 && actionType !== CONST.IOU.REPORT_ACTION_TYPE.TRACK && !isSentMoneyReportAction(action); + }); + + return filteredReportActions; +} + /** * 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. @@ -392,16 +416,7 @@ function getCombinedReportActions( const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; const isSelfDM = report?.chatType === CONST.REPORT.CHAT_TYPE.SELF_DM; // 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) => { - if (!isMoneyRequestAction(action)) { - return true; - } - 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 && actionType !== CONST.IOU.REPORT_ACTION_TYPE.TRACK && !isSentMoneyReportAction(action); - }); + const filteredReportActions = getFilteredForOneTransactionView([...reportActions, ...filteredTransactionThreadReportActions]); return getSortedReportActions(filteredReportActions, true); } @@ -1459,6 +1474,7 @@ export { getTextFromHtml, isTripPreview, getIOUActionForReportID, + getFilteredForOneTransactionView, }; export type {LastVisibleMessage}; diff --git a/src/pages/home/report/ReportActionItemContentCreated.tsx b/src/pages/home/report/ReportActionItemContentCreated.tsx index a48d1d370db23..5cf247a201211 100644 --- a/src/pages/home/report/ReportActionItemContentCreated.tsx +++ b/src/pages/home/report/ReportActionItemContentCreated.tsx @@ -149,7 +149,7 @@ function ReportActionItemContentCreated({contextValue, parentReportAction, trans {transactionThreadReport && !isEmptyObject(transactionThreadReport) ? ( <> - {transactionCurrency !== report.currency && ( + {!!transaction && transactionCurrency !== report.currency && ( <> Date: Thu, 27 Jun 2024 12:21:12 +0200 Subject: [PATCH 2/4] fix lint, cleanup --- src/libs/ReportActionsUtils.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 2ca09efbc8abb..8079e5b25378e 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -379,11 +379,6 @@ function shouldIgnoreGap(currentReportAction: ReportAction | undefined, nextRepo */ function getFilteredForOneTransactionView(reportActions: ReportAction[], isSelfDM = false): ReportAction[] { const filteredReportActions = reportActions.filter((action) => { - // const actionType = (action as OriginalMessageIOU).originalMessage?.type ?? ''; - // if (isSelfDM) { - // return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && !isSentMoneyReportAction(action); - // } - // return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && actionType !== CONST.IOU.REPORT_ACTION_TYPE.TRACK && !isSentMoneyReportAction(action); if (!isMoneyRequestAction(action)) { return true; } @@ -416,7 +411,7 @@ function getCombinedReportActions( const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; const isSelfDM = report?.chatType === CONST.REPORT.CHAT_TYPE.SELF_DM; // Filter out request and send money request actions because we don't want to show any preview actions for one transaction reports - const filteredReportActions = getFilteredForOneTransactionView([...reportActions, ...filteredTransactionThreadReportActions]); + const filteredReportActions = getFilteredForOneTransactionView([...reportActions, ...filteredTransactionThreadReportActions], isSelfDM); return getSortedReportActions(filteredReportActions, true); } From bcca27bafdeb736fde103d08febb57772de88e48 Mon Sep 17 00:00:00 2001 From: Tomasz Lesniakiewicz Date: Fri, 28 Jun 2024 11:55:07 +0200 Subject: [PATCH 3/4] adjust to new changes from main --- src/libs/ReportActionsUtils.ts | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 431662e75b3b0..7653e46d213f4 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -377,19 +377,8 @@ function shouldIgnoreGap(currentReportAction: ReportAction | undefined, nextRepo * Returns filtered list for one transaction view * Separated it from getCombinedReportActions, so it can be reused */ -function getFilteredForOneTransactionView(reportActions: ReportAction[], isSelfDM = false): ReportAction[] { - const filteredReportActions = reportActions.filter((action) => { - if (!isMoneyRequestAction(action)) { - return true; - } - 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 && actionType !== CONST.IOU.REPORT_ACTION_TYPE.TRACK && !isSentMoneyReportAction(action); - }); - - return filteredReportActions; +function getFilteredForOneTransactionView(reportActions: ReportAction[]): ReportAction[] { + return reportActions.filter((action) => !isSentMoneyReportAction(action)); } /** @@ -414,7 +403,16 @@ function getCombinedReportActions( const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; const isSelfDM = report?.chatType === CONST.REPORT.CHAT_TYPE.SELF_DM; // Filter out request and send money request actions because we don't want to show any preview actions for one transaction reports - const filteredReportActions = getFilteredForOneTransactionView([...reportActions, ...filteredTransactionThreadReportActions], isSelfDM); + const filteredReportActions = [...reportActions, ...filteredTransactionThreadReportActions].filter((action) => { + if (!isMoneyRequestAction(action)) { + return true; + } + const actionType = getOriginalMessage(action)?.type ?? ''; + if (isSelfDM) { + return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE; + } + return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && actionType !== CONST.IOU.REPORT_ACTION_TYPE.TRACK; + }); return getSortedReportActions(filteredReportActions, true); } From 580243df4323aeb51cd4a44b28431ba29b9d5b21 Mon Sep 17 00:00:00 2001 From: Tomasz Lesniakiewicz Date: Thu, 4 Jul 2024 15:12:25 +0200 Subject: [PATCH 4/4] add comments --- src/libs/ReportActionsUtils.ts | 2 +- src/pages/home/report/ReportActionsView.tsx | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 7653e46d213f4..30f8355260cdb 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -374,7 +374,7 @@ function shouldIgnoreGap(currentReportAction: ReportAction | undefined, nextRepo } /** - * Returns filtered list for one transaction view + * Returns filtered list for one transaction view as we don't want to display IOU action type in the one-transaction view * Separated it from getCombinedReportActions, so it can be reused */ function getFilteredForOneTransactionView(reportActions: ReportAction[]): ReportAction[] { diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index 167a07c9b07c4..220ab1aa1af13 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -213,6 +213,7 @@ function ReportActionsView({ createdAction.pendingAction = CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE; } + // moneyRequestActions.length === 1 indicates that we have one-transaction report and we don't want to display additonal IOU action return moneyRequestActions.length === 1 ? ReportActionsUtils.getFilteredForOneTransactionView([...actions, createdAction]) : [...actions, createdAction]; }, [allReportActions, report, transactionThreadReport]);