From 3a9e3530013912081e48478805ea638e0ab2af4c Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 5 Dec 2023 12:09:02 +0700 Subject: [PATCH 01/12] subscribe transaction in report preview --- .../ReportActionItem/ReportPreview.js | 34 +++++++++++++++---- src/libs/ReportUtils.ts | 15 ++++---- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index 615e91dc5fc4..65d117b7a251 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -1,6 +1,6 @@ import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; -import React from 'react'; +import React, {useEffect, useMemo, useState} from 'react'; import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; @@ -19,6 +19,7 @@ import ControlSelection from '@libs/ControlSelection'; import * as CurrencyUtils from '@libs/CurrencyUtils'; import * as DeviceCapabilities from '@libs/DeviceCapabilities'; import Navigation from '@libs/Navigation/Navigation'; +import onyxSubscribe from '@libs/onyxSubscribe'; import * as ReceiptUtils from '@libs/ReceiptUtils'; import * as ReportActionUtils from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; @@ -110,10 +111,12 @@ function ReportPreview(props) { const theme = useTheme(); const styles = useThemeStyles(); const {translate} = useLocalize(); + const [transactions, setTransactions] = useState([]); const managerID = props.iouReport.managerID || 0; const isCurrentUserManager = managerID === lodashGet(props.session, 'accountID'); const {totalDisplaySpend, reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(props.iouReport); + const transactionsWithReceipts = useMemo(() => _.filter(transactions, (transaction) => TransactionUtils.hasReceipt(transaction)), [transactions]); const iouSettled = ReportUtils.isSettled(props.iouReportID); const iouCanceled = ReportUtils.isArchivedRoom(props.chatReport); @@ -122,15 +125,14 @@ function ReportPreview(props) { const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(props.chatReport); const isDraftExpenseReport = isPolicyExpenseChat && ReportUtils.isDraftExpenseReport(props.iouReport); - const transactionsWithReceipts = ReportUtils.getTransactionsWithReceipts(props.iouReportID); const numberOfScanningReceipts = _.filter(transactionsWithReceipts, (transaction) => TransactionUtils.isReceiptBeingScanned(transaction)).length; const hasReceipts = transactionsWithReceipts.length > 0; - const hasOnlyDistanceRequests = ReportUtils.hasOnlyDistanceRequestTransactions(props.iouReportID); - const isScanning = hasReceipts && ReportUtils.areAllRequestsBeingSmartScanned(props.iouReportID, props.action); - const hasErrors = hasReceipts && ReportUtils.hasMissingSmartscanFields(props.iouReportID); + const hasOnlyDistanceRequests = ReportUtils.hasOnlyDistanceRequestTransactions(props.iouReportID, transactions); + const isScanning = hasReceipts && ReportUtils.areAllRequestsBeingSmartScanned(props.iouReportID, props.action, transactionsWithReceipts); + const hasErrors = hasReceipts && ReportUtils.hasMissingSmartscanFields(props.iouReportID, transactionsWithReceipts); const lastThreeTransactionsWithReceipts = transactionsWithReceipts.slice(-3); const lastThreeReceipts = _.map(lastThreeTransactionsWithReceipts, (transaction) => ReceiptUtils.getThumbnailAndImageURIs(transaction)); - const hasNonReimbursableTransactions = ReportUtils.hasNonReimbursableTransactions(props.iouReportID); + const hasNonReimbursableTransactions = ReportUtils.hasNonReimbursableTransactions(props.iouReportID, transactions); let formattedMerchant = numberOfRequests === 1 && hasReceipts ? TransactionUtils.getMerchant(transactionsWithReceipts[0]) : null; const hasPendingWaypoints = formattedMerchant && hasOnlyDistanceRequests && _.every(transactionsWithReceipts, (transaction) => lodashGet(transaction, 'pendingFields.waypoints', null)); if (hasPendingWaypoints) { @@ -191,6 +193,26 @@ function ReportPreview(props) { ? props.policy.role === CONST.POLICY.ROLE.ADMIN && ReportUtils.isReportApproved(props.iouReport) && !iouSettled && !iouCanceled : !_.isEmpty(props.iouReport) && isCurrentUserManager && !isDraftExpenseReport && !iouSettled && !iouCanceled && !props.iouReport.isWaitingOnBankAccount && reimbursableSpend !== 0; + useEffect(() => { + const unsubscribeOnyxTransaction = onyxSubscribe({ + key: ONYXKEYS.COLLECTION.TRANSACTION, + waitForCollectionCallback: true, + callback: (transactionAgrs) => { + if (_.isEmpty(transactionAgrs)) { + return; + } + + const allTransaction = _.filter(transactionAgrs, (transaction) => `${transaction.reportID}` === `${props.iouReportID}`); + setTransactions(allTransaction); + }, + }); + + return () => { + unsubscribeOnyxTransaction(); + }; + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + return ( ): boolean { * Checks whether all the transactions linked to the IOU report are of the Distance Request type * */ -function hasOnlyDistanceRequestTransactions(iouReportID: string | undefined): boolean { - const allTransactions = TransactionUtils.getAllReportTransactions(iouReportID); +function hasOnlyDistanceRequestTransactions(iouReportID: string | undefined, transactions: Transaction[] | undefined = undefined): boolean { + const allTransactions = transactions ?? TransactionUtils.getAllReportTransactions(iouReportID); return allTransactions.every((transaction) => TransactionUtils.isDistanceRequest(transaction)); } @@ -1586,8 +1586,8 @@ function requiresAttentionFromCurrentUser(option: OnyxEntry | OptionData * Returns number of transactions that are nonReimbursable * */ -function hasNonReimbursableTransactions(iouReportID: string | undefined): boolean { - const allTransactions = TransactionUtils.getAllReportTransactions(iouReportID); +function hasNonReimbursableTransactions(iouReportID: string | undefined, transactions: Transaction[] | undefined = undefined): boolean { + const allTransactions = transactions ?? TransactionUtils.getAllReportTransactions(iouReportID); return allTransactions.filter((transaction) => transaction.reimbursable === false).length > 0; } @@ -1851,8 +1851,7 @@ function getTransactionsWithReceipts(iouReportID: string | undefined): Transacti * or as soon as one receipt request is done scanning, we have at least one * "ready" money request, and we remove this indicator to show the partial report total. */ -function areAllRequestsBeingSmartScanned(iouReportID: string, reportPreviewAction: OnyxEntry): boolean { - const transactionsWithReceipts = getTransactionsWithReceipts(iouReportID); +function areAllRequestsBeingSmartScanned(iouReportID: string, reportPreviewAction: OnyxEntry, transactionsWithReceipts: Transaction[] = []): boolean { // If we have more requests than requests with receipts, we have some manual requests if (ReportActionsUtils.getNumberOfMoneyRequests(reportPreviewAction) > transactionsWithReceipts.length) { return false; @@ -1864,8 +1863,8 @@ function areAllRequestsBeingSmartScanned(iouReportID: string, reportPreviewActio * Check if any of the transactions in the report has required missing fields * */ -function hasMissingSmartscanFields(iouReportID: string): boolean { - const transactionsWithReceipts = getTransactionsWithReceipts(iouReportID); +function hasMissingSmartscanFields(iouReportID: string, transactions: Transaction[] | undefined = undefined): boolean { + const transactionsWithReceipts = transactions ?? getTransactionsWithReceipts(iouReportID); return transactionsWithReceipts.some((transaction) => TransactionUtils.hasMissingSmartscanFields(transaction)); } From 969df42343d67c9604401501de2511397177f3e6 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 8 Dec 2023 11:42:15 +0700 Subject: [PATCH 02/12] rename variable --- src/libs/ReportUtils.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index c1e49d61b34a..7ca6ff396817 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -911,8 +911,8 @@ function hasSingleParticipant(report: OnyxEntry): boolean { * */ function hasOnlyDistanceRequestTransactions(iouReportID: string | undefined, transactions: Transaction[] | undefined = undefined): boolean { - const allTransactions = transactions ?? TransactionUtils.getAllReportTransactions(iouReportID); - return allTransactions.every((transaction) => TransactionUtils.isDistanceRequest(transaction)); + const allTransactionsOfPreview = transactions ?? TransactionUtils.getAllReportTransactions(iouReportID); + return allTransactionsOfPreview.every((transaction) => TransactionUtils.isDistanceRequest(transaction)); } /** @@ -1601,8 +1601,8 @@ function requiresAttentionFromCurrentUser(option: OnyxEntry | OptionData * */ function hasNonReimbursableTransactions(iouReportID: string | undefined, transactions: Transaction[] | undefined = undefined): boolean { - const allTransactions = transactions ?? TransactionUtils.getAllReportTransactions(iouReportID); - return allTransactions.filter((transaction) => transaction.reimbursable === false).length > 0; + const allTransactionsOfPreview = transactions ?? TransactionUtils.getAllReportTransactions(iouReportID); + return allTransactionsOfPreview.filter((transaction) => transaction.reimbursable === false).length > 0; } function getMoneyRequestReimbursableTotal(report: OnyxEntry, allReportsDict: OnyxCollection = null): number { From b6e9f4975d6b8417245b59b2b1f84e18542aea1b Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 12 Dec 2023 16:51:58 +0700 Subject: [PATCH 03/12] use getAllReportTransaction function --- src/components/ReportActionItem/ReportPreview.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index 5eaeb475310d..d682e68e3620 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -199,8 +199,8 @@ function ReportPreview(props) { return; } - const allTransaction = _.filter(transactionAgrs, (transaction) => `${transaction.reportID}` === `${props.iouReportID}`); - setTransactions(allTransaction); + const allTransactions = TransactionUtils.getAllReportTransactions(props.iouReportID); + setTransactions(allTransactions); }, }); From ce804f4410b7fca20f302066e61e702f24d4a473 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 13 Dec 2023 15:32:38 +0700 Subject: [PATCH 04/12] fix lint --- src/components/ReportActionItem/ReportPreview.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index f4f8af9260ef..935051055cca 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -1,10 +1,6 @@ import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; -<<<<<<< HEAD import React, {useEffect, useMemo, useState} from 'react'; -======= -import React, {useMemo} from 'react'; ->>>>>>> main import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; From d0eed0e9ae4b4d124f83333473f334b3b06bdd31 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 19 Dec 2023 12:55:31 +0700 Subject: [PATCH 05/12] merge main --- .../ReportActionItem/ReportPreview.js | 20 +++++++++++-------- src/libs/ReportUtils.ts | 15 +++++++------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index c1a571bf4fa8..00d548719d17 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -121,12 +121,15 @@ function ReportPreview(props) { const theme = useTheme(); const styles = useThemeStyles(); const {translate} = useLocalize(); - const [transactions, setTransactions] = useState([]); + + const [hasMissingSmartscanFields, sethasMissingSmartscanFields] = useState(false); + const [areAllRequestsBeingSmartScanned, setAreAllRequestsBeingSmartScanned] = useState(false); + const [hasOnlyDistanceRequests, setHasOnlyDistanceRequests] = useState(false); + const [hasNonReimbursableTransactions, setHasNonReimbursableTransactions] = useState(false); const managerID = props.iouReport.managerID || 0; const isCurrentUserManager = managerID === lodashGet(props.session, 'accountID'); const {totalDisplaySpend, reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(props.iouReport); - const transactionsWithReceipts = useMemo(() => _.filter(transactions, (transaction) => TransactionUtils.hasReceipt(transaction)), [transactions]); const policyType = lodashGet(props.policy, 'type'); const iouSettled = ReportUtils.isSettled(props.iouReportID); @@ -138,14 +141,13 @@ function ReportPreview(props) { const isApproved = ReportUtils.isReportApproved(props.iouReport); const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(props.iouReport); + const transactionsWithReceipts = ReportUtils.getTransactionsWithReceipts(props.iouReportID); const numberOfScanningReceipts = _.filter(transactionsWithReceipts, (transaction) => TransactionUtils.isReceiptBeingScanned(transaction)).length; const hasReceipts = transactionsWithReceipts.length > 0; - const hasOnlyDistanceRequests = ReportUtils.hasOnlyDistanceRequestTransactions(props.iouReportID, transactions); - const isScanning = hasReceipts && ReportUtils.areAllRequestsBeingSmartScanned(props.iouReportID, props.action, transactionsWithReceipts); - const hasErrors = hasReceipts && ReportUtils.hasMissingSmartscanFields(props.iouReportID, transactionsWithReceipts); + const isScanning = hasReceipts && areAllRequestsBeingSmartScanned; + const hasErrors = hasReceipts && hasMissingSmartscanFields; const lastThreeTransactionsWithReceipts = transactionsWithReceipts.slice(-3); const lastThreeReceipts = _.map(lastThreeTransactionsWithReceipts, (transaction) => ReceiptUtils.getThumbnailAndImageURIs(transaction)); - const hasNonReimbursableTransactions = ReportUtils.hasNonReimbursableTransactions(props.iouReportID, transactions); let formattedMerchant = numberOfRequests === 1 && hasReceipts ? TransactionUtils.getMerchant(transactionsWithReceipts[0]) : null; const hasPendingWaypoints = formattedMerchant && hasOnlyDistanceRequests && _.every(transactionsWithReceipts, (transaction) => lodashGet(transaction, 'pendingFields.waypoints', null)); if (hasPendingWaypoints) { @@ -213,8 +215,10 @@ function ReportPreview(props) { return; } - const allTransactions = TransactionUtils.getAllReportTransactions(props.iouReportID); - setTransactions(allTransactions); + sethasMissingSmartscanFields(ReportUtils.hasMissingSmartscanFields(props.iouReportID)); + setAreAllRequestsBeingSmartScanned(ReportUtils.areAllRequestsBeingSmartScanned(props.iouReportID)); + setHasOnlyDistanceRequests(ReportUtils.hasOnlyDistanceRequestTransactions(props.iouReportID)); + setHasNonReimbursableTransactions(ReportUtils.hasNonReimbursableTransactions(props.iouReportID)); }, }); diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 071934b99111..a0343dfc9d31 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -937,8 +937,8 @@ function hasSingleParticipant(report: OnyxEntry): boolean { * Checks whether all the transactions linked to the IOU report are of the Distance Request type * */ -function hasOnlyDistanceRequestTransactions(iouReportID: string | undefined, transactions: Transaction[] | undefined = undefined): boolean { - const allTransactionsOfPreview = transactions ?? TransactionUtils.getAllReportTransactions(iouReportID); +function hasOnlyDistanceRequestTransactions(iouReportID: string | undefined): boolean { + const allTransactionsOfPreview = TransactionUtils.getAllReportTransactions(iouReportID); return allTransactionsOfPreview.every((transaction) => TransactionUtils.isDistanceRequest(transaction)); } @@ -1624,8 +1624,8 @@ function requiresAttentionFromCurrentUser(optionOrReport: OnyxEntry | Op * Returns number of transactions that are nonReimbursable * */ -function hasNonReimbursableTransactions(iouReportID: string | undefined, transactions: Transaction[] | undefined = undefined): boolean { - const allTransactionsOfPreview = transactions ?? TransactionUtils.getAllReportTransactions(iouReportID); +function hasNonReimbursableTransactions(iouReportID: string | undefined): boolean { + const allTransactionsOfPreview = TransactionUtils.getAllReportTransactions(iouReportID); return allTransactionsOfPreview.filter((transaction) => transaction.reimbursable === false).length > 0; } @@ -1901,7 +1901,8 @@ function getTransactionsWithReceipts(iouReportID: string | undefined): Transacti * or as soon as one receipt request is done scanning, we have at least one * "ready" money request, and we remove this indicator to show the partial report total. */ -function areAllRequestsBeingSmartScanned(iouReportID: string, reportPreviewAction: OnyxEntry, transactionsWithReceipts: Transaction[] = []): boolean { +function areAllRequestsBeingSmartScanned(iouReportID: string, reportPreviewAction: OnyxEntry): boolean { + const transactionsWithReceipts = getTransactionsWithReceipts(iouReportID); // If we have more requests than requests with receipts, we have some manual requests if (ReportActionsUtils.getNumberOfMoneyRequests(reportPreviewAction) > transactionsWithReceipts.length) { return false; @@ -1913,8 +1914,8 @@ function areAllRequestsBeingSmartScanned(iouReportID: string, reportPreviewActio * Check if any of the transactions in the report has required missing fields * */ -function hasMissingSmartscanFields(iouReportID: string, transactions: Transaction[] | undefined = undefined): boolean { - const transactionsWithReceipts = transactions ?? getTransactionsWithReceipts(iouReportID); +function hasMissingSmartscanFields(iouReportID: string): boolean { + const transactionsWithReceipts = getTransactionsWithReceipts(iouReportID); return transactionsWithReceipts.some((transaction) => TransactionUtils.hasMissingSmartscanFields(transaction)); } From 5dedcd57cdcf8e8035dbffbb3d5d26d6c8fd6f3d Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 20 Dec 2023 13:27:50 +0700 Subject: [PATCH 06/12] revert change --- src/libs/ReportUtils.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index ecf9113fa674..8ac32675bb4e 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -918,8 +918,8 @@ function hasSingleParticipant(report: OnyxEntry): boolean { * */ function hasOnlyDistanceRequestTransactions(iouReportID: string | undefined): boolean { - const allTransactionsOfPreview = TransactionUtils.getAllReportTransactions(iouReportID); - return allTransactionsOfPreview.every((transaction) => TransactionUtils.isDistanceRequest(transaction)); + const transactions = TransactionUtils.getAllReportTransactions(iouReportID); + return transactions.every((transaction) => TransactionUtils.isDistanceRequest(transaction)); } /** @@ -1605,8 +1605,8 @@ function requiresAttentionFromCurrentUser(optionOrReport: OnyxEntry | Op * */ function hasNonReimbursableTransactions(iouReportID: string | undefined): boolean { - const allTransactionsOfPreview = TransactionUtils.getAllReportTransactions(iouReportID); - return allTransactionsOfPreview.filter((transaction) => transaction.reimbursable === false).length > 0; + const transactions = TransactionUtils.getAllReportTransactions(iouReportID); + return transactions.filter((transaction) => transaction.reimbursable === false).length > 0; } function getMoneyRequestReimbursableTotal(report: OnyxEntry, allReportsDict: OnyxCollection = null): number { From f3a1cf4d3ab70d260bc4dd36cff51401cded3fb3 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 21 Dec 2023 10:40:02 +0700 Subject: [PATCH 07/12] remove unuse variable --- src/components/ReportActionItem/ReportPreview.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index 00d548719d17..b07d0fc5f8f8 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -210,11 +210,7 @@ function ReportPreview(props) { const unsubscribeOnyxTransaction = onyxSubscribe({ key: ONYXKEYS.COLLECTION.TRANSACTION, waitForCollectionCallback: true, - callback: (transactionAgrs) => { - if (_.isEmpty(transactionAgrs)) { - return; - } - + callback: () => { sethasMissingSmartscanFields(ReportUtils.hasMissingSmartscanFields(props.iouReportID)); setAreAllRequestsBeingSmartScanned(ReportUtils.areAllRequestsBeingSmartScanned(props.iouReportID)); setHasOnlyDistanceRequests(ReportUtils.hasOnlyDistanceRequestTransactions(props.iouReportID)); From 31a70ebf6368d0b052228f3dcb1b01a654ef103e Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 21 Dec 2023 11:11:28 +0700 Subject: [PATCH 08/12] fix perf test --- src/components/ReportActionItem/ReportPreview.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index b07d0fc5f8f8..a8816f4318f1 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -210,7 +210,11 @@ function ReportPreview(props) { const unsubscribeOnyxTransaction = onyxSubscribe({ key: ONYXKEYS.COLLECTION.TRANSACTION, waitForCollectionCallback: true, - callback: () => { + callback: (allTransactions) => { + if (_.isEmpty(allTransactions)) { + return; + } + sethasMissingSmartscanFields(ReportUtils.hasMissingSmartscanFields(props.iouReportID)); setAreAllRequestsBeingSmartScanned(ReportUtils.areAllRequestsBeingSmartScanned(props.iouReportID)); setHasOnlyDistanceRequests(ReportUtils.hasOnlyDistanceRequestTransactions(props.iouReportID)); From bf6a2afdf08a2042999816123f78b01e0dfaa913 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 21 Dec 2023 11:18:03 +0700 Subject: [PATCH 09/12] fix linnt --- src/components/ReportActionItem/ReportPreview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index a8816f4318f1..39f3e189f8ab 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -214,7 +214,7 @@ function ReportPreview(props) { if (_.isEmpty(allTransactions)) { return; } - + sethasMissingSmartscanFields(ReportUtils.hasMissingSmartscanFields(props.iouReportID)); setAreAllRequestsBeingSmartScanned(ReportUtils.areAllRequestsBeingSmartScanned(props.iouReportID)); setHasOnlyDistanceRequests(ReportUtils.hasOnlyDistanceRequestTransactions(props.iouReportID)); From 96b1a0b92e190bb8399809fb48619707da63e651 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 21 Dec 2023 12:01:51 +0700 Subject: [PATCH 10/12] test perf test --- src/components/ReportActionItem/ReportPreview.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index 39f3e189f8ab..f2e09eb6b2dc 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -211,9 +211,6 @@ function ReportPreview(props) { key: ONYXKEYS.COLLECTION.TRANSACTION, waitForCollectionCallback: true, callback: (allTransactions) => { - if (_.isEmpty(allTransactions)) { - return; - } sethasMissingSmartscanFields(ReportUtils.hasMissingSmartscanFields(props.iouReportID)); setAreAllRequestsBeingSmartScanned(ReportUtils.areAllRequestsBeingSmartScanned(props.iouReportID)); From f2dae8032394032c860260c1b869d0c1c0e1bb35 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 21 Dec 2023 12:29:24 +0700 Subject: [PATCH 11/12] fix perf test --- src/components/ReportActionItem/ReportPreview.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index f2e09eb6b2dc..a8816f4318f1 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -211,7 +211,10 @@ function ReportPreview(props) { key: ONYXKEYS.COLLECTION.TRANSACTION, waitForCollectionCallback: true, callback: (allTransactions) => { - + if (_.isEmpty(allTransactions)) { + return; + } + sethasMissingSmartscanFields(ReportUtils.hasMissingSmartscanFields(props.iouReportID)); setAreAllRequestsBeingSmartScanned(ReportUtils.areAllRequestsBeingSmartScanned(props.iouReportID)); setHasOnlyDistanceRequests(ReportUtils.hasOnlyDistanceRequestTransactions(props.iouReportID)); From b90ee2e973aae1570514f9af489035c7e31b9255 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 21 Dec 2023 12:37:58 +0700 Subject: [PATCH 12/12] fix linnt --- src/components/ReportActionItem/ReportPreview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index a8816f4318f1..39f3e189f8ab 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -214,7 +214,7 @@ function ReportPreview(props) { if (_.isEmpty(allTransactions)) { return; } - + sethasMissingSmartscanFields(ReportUtils.hasMissingSmartscanFields(props.iouReportID)); setAreAllRequestsBeingSmartScanned(ReportUtils.areAllRequestsBeingSmartScanned(props.iouReportID)); setHasOnlyDistanceRequests(ReportUtils.hasOnlyDistanceRequestTransactions(props.iouReportID));