From b028f9d7fd2a5f4fe6cf0d78f28787d9fe009263 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 16 Feb 2024 11:46:10 +0700 Subject: [PATCH 01/14] display total and money request in offline --- src/pages/home/report/ReportActionsView.js | 49 +++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index 064187855b572..8378cab1be8ae 100755 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -12,10 +12,13 @@ import useCopySelectionHelper from '@hooks/useCopySelectionHelper'; import useInitialValue from '@hooks/useInitialValue'; import usePrevious from '@hooks/usePrevious'; import compose from '@libs/compose'; +import DateUtils from '@libs/DateUtils'; import getIsReportFullyVisible from '@libs/getIsReportFullyVisible'; +import * as NumberUtils from '@libs/NumberUtils'; import Performance from '@libs/Performance'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import {isUserCreatedPolicyRoom} from '@libs/ReportUtils'; +import * as ReportUtils from '@libs/ReportUtils'; import {didUserLogInDuringSession} from '@libs/SessionUtils'; import {ReactionListContext} from '@pages/home/ReportScreenContext'; import reportPropTypes from '@pages/reportPropTypes'; @@ -245,6 +248,50 @@ function ReportActionsView(props) { } }, [hasCachedActions]); + const reportActionsToDisplay = useMemo(() => { + if (!ReportUtils.isMoneyRequestReport(props.report) || !_.size(props.reportActions)) { + return props.reportActions; + } + + const actions = [...props.reportActions]; + + if (!ReportActionsUtils.isCreatedAction(_.last(props.reportActions))) { + const optimisticCreatedAction = ReportUtils.buildOptimisticCreatedReportAction( + props.report.ownerAccountID, + DateUtils.subtractMillisecondsFromDateTime(_.last(props.reportActions).created, 1), + ); + actions.push(optimisticCreatedAction); + } + + if ( + props.report.total && + _.filter( + props.reportActions, + (action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && action.originalMessage && action.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.CREATE, + ).length === 0 + ) { + const optimisticIOUAction = ReportUtils.buildOptimisticIOUReportAction( + CONST.IOU.REPORT_ACTION_TYPE.CREATE, + 0, + CONST.CURRENCY.USD, + '', + [], + NumberUtils.rand64(), + undefined, + props.report.reportID, + false, + false, + {}, + false, + DateUtils.subtractMillisecondsFromDateTime(_.last(actions).created, 1), + ); + + actions.splice(actions.length - 1, 0, optimisticIOUAction); + } + + return actions; + }, [props.reportActions, props.report]); + // Comments have not loaded at all yet do nothing if (!_.size(props.reportActions)) { return null; @@ -255,7 +302,7 @@ function ReportActionsView(props) { Date: Wed, 21 Feb 2024 16:25:25 +0700 Subject: [PATCH 02/14] add explain comment --- src/pages/home/report/ReportActionsView.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index 8378cab1be8ae..e7e5743ce0b02 100755 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -248,6 +248,11 @@ function ReportActionsView(props) { } }, [hasCachedActions]); + // When we offline before opening a money request report, + // the total of the report and sometimes the money request aren't displayed because these actions aren't returned until `OpenReport` API is complete. + // We generate a fake created action here if it doesn't exist to display the total whenever possible because the total just depends on report data + // and we also generate a money request action if there is no such action to display at least one money request action to match the total data. + // For more details: https://github.com/Expensify/App/issues/26424#issuecomment-1869154198 const reportActionsToDisplay = useMemo(() => { if (!ReportUtils.isMoneyRequestReport(props.report) || !_.size(props.reportActions)) { return props.reportActions; From dd6fb2d3c991fc52b297c4ea6cfbd2a56bdfe06f Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 21 Feb 2024 16:45:14 +0700 Subject: [PATCH 03/14] fix lint --- src/pages/home/report/ReportActionsView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index e7e5743ce0b02..abdd0aa6386e8 100755 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -248,7 +248,7 @@ function ReportActionsView(props) { } }, [hasCachedActions]); - // When we offline before opening a money request report, + // When we offline before opening a money request report, // the total of the report and sometimes the money request aren't displayed because these actions aren't returned until `OpenReport` API is complete. // We generate a fake created action here if it doesn't exist to display the total whenever possible because the total just depends on report data // and we also generate a money request action if there is no such action to display at least one money request action to match the total data. From d6493cf11cc65df8a3c216ebbf7ed7c7ff3296e3 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 22 Feb 2024 10:44:19 +0700 Subject: [PATCH 04/14] update logic to add money request action --- src/pages/home/report/ReportActionsView.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index abdd0aa6386e8..29ce6af76a27d 100755 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -248,10 +248,11 @@ function ReportActionsView(props) { } }, [hasCachedActions]); - // When we offline before opening a money request report, + // When we are offline before opening a money request report, // the total of the report and sometimes the money request aren't displayed because these actions aren't returned until `OpenReport` API is complete. // We generate a fake created action here if it doesn't exist to display the total whenever possible because the total just depends on report data - // and we also generate a money request action if there is no such action to display at least one money request action to match the total data. + // and we also generate a money request action if If the number of money requests in reportActions is less than the total number of money requests + // to display at least one money request action to match the total data. // For more details: https://github.com/Expensify/App/issues/26424#issuecomment-1869154198 const reportActionsToDisplay = useMemo(() => { if (!ReportUtils.isMoneyRequestReport(props.report) || !_.size(props.reportActions)) { @@ -268,12 +269,14 @@ function ReportActionsView(props) { actions.push(optimisticCreatedAction); } + const reportPreviewAction = ReportActionsUtils.getReportPreviewAction(props.report.chatReportID, props.report.reportID); + if ( props.report.total && _.filter( props.reportActions, (action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && action.originalMessage && action.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.CREATE, - ).length === 0 + ).length < reportPreviewAction.childMoneyRequestCount ) { const optimisticIOUAction = ReportUtils.buildOptimisticIOUReportAction( CONST.IOU.REPORT_ACTION_TYPE.CREATE, From e76216c619141ec2b0c8a504008b623a196aba1a Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 23 Feb 2024 15:02:30 +0700 Subject: [PATCH 05/14] only grey out the total if have some requests are pending --- src/pages/home/report/ReportActionsView.js | 26 +++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index 29ce6af76a27d..df487693e0cd7 100755 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -259,25 +259,24 @@ function ReportActionsView(props) { return props.reportActions; } - const actions = [...props.reportActions]; + let actions = [...props.reportActions]; if (!ReportActionsUtils.isCreatedAction(_.last(props.reportActions))) { const optimisticCreatedAction = ReportUtils.buildOptimisticCreatedReportAction( props.report.ownerAccountID, DateUtils.subtractMillisecondsFromDateTime(_.last(props.reportActions).created, 1), ); + optimisticCreatedAction.pendingAction = null; actions.push(optimisticCreatedAction); } const reportPreviewAction = ReportActionsUtils.getReportPreviewAction(props.report.chatReportID, props.report.reportID); + const moneyRequestActions = _.filter( + props.reportActions, + (action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && action.originalMessage && action.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.CREATE, + ); - if ( - props.report.total && - _.filter( - props.reportActions, - (action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && action.originalMessage && action.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.CREATE, - ).length < reportPreviewAction.childMoneyRequestCount - ) { + if (props.report.total && moneyRequestActions.length < reportPreviewAction.childMoneyRequestCount) { const optimisticIOUAction = ReportUtils.buildOptimisticIOUReportAction( CONST.IOU.REPORT_ACTION_TYPE.CREATE, 0, @@ -293,11 +292,18 @@ function ReportActionsView(props) { false, DateUtils.subtractMillisecondsFromDateTime(_.last(actions).created, 1), ); - + moneyRequestActions.push(optimisticIOUAction); actions.splice(actions.length - 1, 0, optimisticIOUAction); } - return actions; + // Update pending action of created action if we have some requests that are pending + const createdAction = _.last(actions); + actions = _.without(actions, createdAction); + if (_.filter(moneyRequestActions, (action) => !!action.pendingAction).length > 0) { + createdAction.pendingAction = CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE; + } + + return [...actions, createdAction]; }, [props.reportActions, props.report]); // Comments have not loaded at all yet do nothing From 4d14104a003df1e36e2a176724ca2633a29228c4 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 12 Mar 2024 17:44:38 +0700 Subject: [PATCH 06/14] remove underscore --- src/pages/home/report/ReportActionsView.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index 2fff1cca38c2c..eda7193c6a12e 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -231,7 +231,7 @@ function ReportActionsView({ // to display at least one money request action to match the total data. // For more details: https://github.com/Expensify/App/issues/26424#issuecomment-1869154198 const reportActionsToDisplay = useMemo(() => { - if (!ReportUtils.isMoneyRequestReport(report) || !_.size(reportActions)) { + if (!ReportUtils.isMoneyRequestReport(report) || !reportActions.length) { return reportActions; } From db3a7ba86f2a20ba3505dae0eade336d53290c8b Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 12 Mar 2024 17:51:33 +0700 Subject: [PATCH 07/14] fix lint --- src/pages/home/report/ReportActionsView.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index eda7193c6a12e..127f6a0845f6a 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -235,7 +235,7 @@ function ReportActionsView({ return reportActions; } - let actions = [...reportActions]; + const actions = [...reportActions]; const lastAction = reportActions[reportActions.length - 1]; if (!ReportActionsUtils.isCreatedAction(lastAction)) { @@ -271,7 +271,7 @@ function ReportActionsView({ // Update pending action of created action if we have some requests that are pending const createdAction = actions.pop() as OnyxTypes.ReportAction; - if (moneyRequestActions.filter((action) => !!action.pendingAction).length > 0) { + if (moneyRequestActions.filter((action) => Boolean(action.pendingAction)).length > 0) { createdAction.pendingAction = CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE; } From 615ca72a6a41a9227e9be3dfa4020fa983587597 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 12 Mar 2024 18:16:07 +0700 Subject: [PATCH 08/14] fix lint --- src/pages/home/report/ReportActionsView.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index 127f6a0845f6a..b1d63ba8efcda 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -270,7 +270,7 @@ function ReportActionsView({ } // Update pending action of created action if we have some requests that are pending - const createdAction = actions.pop() as OnyxTypes.ReportAction; + const createdAction = actions.pop()!; if (moneyRequestActions.filter((action) => Boolean(action.pendingAction)).length > 0) { createdAction.pendingAction = CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE; } From 2de87ad3cf279475827594fd177f0a8bd8ebf227 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 12 Mar 2024 18:29:43 +0700 Subject: [PATCH 09/14] disable lint --- src/pages/home/report/ReportActionsView.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index b1d63ba8efcda..7319851cfeca3 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -270,6 +270,7 @@ function ReportActionsView({ } // Update pending action of created action if we have some requests that are pending + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const createdAction = actions.pop()!; if (moneyRequestActions.filter((action) => Boolean(action.pendingAction)).length > 0) { createdAction.pendingAction = CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE; From 7bc845b78a4830c1d4a097831657085109323a78 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 21 Mar 2024 10:18:44 +0700 Subject: [PATCH 10/14] fix lint --- src/pages/home/report/ReportActionsView.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index 63ed1ea39ef09..f86cb6dd43222 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -12,8 +12,8 @@ import usePrevious from '@hooks/usePrevious'; import useWindowDimensions from '@hooks/useWindowDimensions'; import DateUtils from '@libs/DateUtils'; import getIsReportFullyVisible from '@libs/getIsReportFullyVisible'; -import * as NumberUtils from '@libs/NumberUtils'; import type {CentralPaneNavigatorParamList} from '@libs/Navigation/types'; +import * as NumberUtils from '@libs/NumberUtils'; import {generateNewRandomInt} from '@libs/NumberUtils'; import Performance from '@libs/Performance'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; From 22f379c7084a4113a2c5b6bf6fb8900af94018b7 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 21 Mar 2024 11:22:37 +0700 Subject: [PATCH 11/14] fix test --- src/pages/home/report/ReportActionsView.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index f86cb6dd43222..c6af9a2b0f654 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -445,6 +445,7 @@ function ReportActionsView({ ) as OnyxTypes.ReportAction; moneyRequestActions.push(optimisticIOUAction); actions.splice(actions.length - 1, 0, optimisticIOUAction); + } // Update pending action of created action if we have some requests that are pending From d1f49c12bf2ad9460b51cfc57f8bba3ad65856ca Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 21 Mar 2024 11:23:56 +0700 Subject: [PATCH 12/14] fix lint --- src/pages/home/report/ReportActionsView.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index c6af9a2b0f654..f86cb6dd43222 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -445,7 +445,6 @@ function ReportActionsView({ ) as OnyxTypes.ReportAction; moneyRequestActions.push(optimisticIOUAction); actions.splice(actions.length - 1, 0, optimisticIOUAction); - } // Update pending action of created action if we have some requests that are pending From 992c1a31718248d2539249a2f10ae0015b33c0e3 Mon Sep 17 00:00:00 2001 From: dukenv0307 <129500732+dukenv0307@users.noreply.github.com> Date: Thu, 28 Mar 2024 16:40:37 +0700 Subject: [PATCH 13/14] Update src/pages/home/report/ReportActionsView.tsx Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- src/pages/home/report/ReportActionsView.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index d0619eb3dc650..23293517d0a21 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -415,7 +415,7 @@ function ReportActionsView({ // When we are offline before opening a money request report, // the total of the report and sometimes the money request aren't displayed because these actions aren't returned until `OpenReport` API is complete. // We generate a fake created action here if it doesn't exist to display the total whenever possible because the total just depends on report data - // and we also generate a money request action if If the number of money requests in reportActions is less than the total number of money requests + // and we also generate a money request action if the number of money requests in reportActions is less than the total number of money requests // to display at least one money request action to match the total data. // For more details: https://github.com/Expensify/App/issues/26424#issuecomment-1869154198 const reportActionsToDisplay = useMemo(() => { From 4922224b518c5b48cc548526486e60c284f9b204 Mon Sep 17 00:00:00 2001 From: dukenv0307 <129500732+dukenv0307@users.noreply.github.com> Date: Thu, 28 Mar 2024 16:40:46 +0700 Subject: [PATCH 14/14] Update src/pages/home/report/ReportActionsView.tsx Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- src/pages/home/report/ReportActionsView.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index 23293517d0a21..462a8801aa2d6 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -417,7 +417,6 @@ function ReportActionsView({ // We generate a fake created action here if it doesn't exist to display the total whenever possible because the total just depends on report data // and we also generate a money request action if the number of money requests in reportActions is less than the total number of money requests // to display at least one money request action to match the total data. - // For more details: https://github.com/Expensify/App/issues/26424#issuecomment-1869154198 const reportActionsToDisplay = useMemo(() => { if (!ReportUtils.isMoneyRequestReport(report) || !reportActions.length) { return reportActions;