From 921679923c2f95120d228e9e1df327e04d4ea45e Mon Sep 17 00:00:00 2001 From: Alberto Date: Fri, 15 Sep 2023 12:50:52 +0800 Subject: [PATCH 1/8] Show RBR in Transaction row in LHN for requestor --- src/libs/OptionsListUtils.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 7629a1acc0a6..b94f652ac348 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -18,6 +18,9 @@ import * as UserUtils from './UserUtils'; import * as ReportActionUtils from './ReportActionsUtils'; import * as PersonalDetailsUtils from './PersonalDetailsUtils'; import * as ErrorUtils from './ErrorUtils'; +import * as ReportActionsUtils from "./ReportActionsUtils"; +import * as TransactionUtils from './TransactionUtils'; +import {isCurrentUserSubmitter} from "./ReportUtils"; /** * OptionsListUtils is used to build a list options passed to the OptionsList component. Several different UI views can @@ -351,20 +354,19 @@ function getSearchText(report, reportName, personalDetailList, isChatRoomOrPolic function getAllReportErrors(report, reportActions) { const reportErrors = report.errors || {}; const reportErrorFields = report.errorFields || {}; - const reportActionErrors = {}; - _.each(reportActions, (action) => { - if (action && !_.isEmpty(action.errors)) { - _.extend(reportActionErrors, action.errors); - } else if (ReportActionUtils.isReportPreviewAction(action)) { - const iouReportID = ReportActionUtils.getIOUReportIDFromReportActionPreview(action); - - // Instead of adding all Smartscan errors, let's just add a generic error if there are any. This - // will be more performant and provide the same result in the UI - if (ReportUtils.hasMissingSmartscanFields(iouReportID)) { - _.extend(reportActionErrors, {smartscan: ErrorUtils.getMicroSecondOnyxError('report.genericSmartscanFailureMessage')}); - } + let reportActionErrors = _.reduce( + reportActions, + (prevReportActionErrors, action) => (!action || _.isEmpty(action.errors) ? prevReportActionErrors : _.extend(prevReportActionErrors, action.errors)), + {}, + ); + + const parentReportAction = ReportActionsUtils.getParentReportAction(report); + if (parentReportAction.actorAccountID === currentUserAccountID && ReportActionsUtils.isTransactionThread(parentReportAction)) { + const transaction = TransactionUtils.getLinkedTransaction(parentReportAction); + if (TransactionUtils.hasMissingSmartscanFields(transaction)) { + _.extend(reportActionErrors, {smartscan: ErrorUtils.getMicroSecondOnyxError('report.genericSmartscanFailureMessage')}); } - }); + } // All error objects related to the report. Each object in the sources contains error messages keyed by microtime const errorSources = { From 540b784be7a0ce3e7347f76e9fb9d94b687ddaa5 Mon Sep 17 00:00:00 2001 From: Alberto Date: Fri, 15 Sep 2023 12:51:21 +0800 Subject: [PATCH 2/8] remove unneeded imports --- src/libs/OptionsListUtils.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index b94f652ac348..f1c1a517f6d4 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -18,9 +18,8 @@ import * as UserUtils from './UserUtils'; import * as ReportActionUtils from './ReportActionsUtils'; import * as PersonalDetailsUtils from './PersonalDetailsUtils'; import * as ErrorUtils from './ErrorUtils'; -import * as ReportActionsUtils from "./ReportActionsUtils"; +import * as ReportActionsUtils from './ReportActionsUtils'; import * as TransactionUtils from './TransactionUtils'; -import {isCurrentUserSubmitter} from "./ReportUtils"; /** * OptionsListUtils is used to build a list options passed to the OptionsList component. Several different UI views can From a324d01cfc243d9ef50d3a39e6c8156928918a39 Mon Sep 17 00:00:00 2001 From: Alberto Date: Fri, 15 Sep 2023 14:19:19 +0800 Subject: [PATCH 3/8] lint --- src/libs/OptionsListUtils.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index f1c1a517f6d4..b945082d78c4 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -18,7 +18,6 @@ import * as UserUtils from './UserUtils'; import * as ReportActionUtils from './ReportActionsUtils'; import * as PersonalDetailsUtils from './PersonalDetailsUtils'; import * as ErrorUtils from './ErrorUtils'; -import * as ReportActionsUtils from './ReportActionsUtils'; import * as TransactionUtils from './TransactionUtils'; /** @@ -353,14 +352,14 @@ function getSearchText(report, reportName, personalDetailList, isChatRoomOrPolic function getAllReportErrors(report, reportActions) { const reportErrors = report.errors || {}; const reportErrorFields = report.errorFields || {}; - let reportActionErrors = _.reduce( + const reportActionErrors = _.reduce( reportActions, (prevReportActionErrors, action) => (!action || _.isEmpty(action.errors) ? prevReportActionErrors : _.extend(prevReportActionErrors, action.errors)), {}, ); - const parentReportAction = ReportActionsUtils.getParentReportAction(report); - if (parentReportAction.actorAccountID === currentUserAccountID && ReportActionsUtils.isTransactionThread(parentReportAction)) { + const parentReportAction = ReportActionUtils.getParentReportAction(report); + if (parentReportAction.actorAccountID === currentUserAccountID && ReportActionUtils.isTransactionThread(parentReportAction)) { const transaction = TransactionUtils.getLinkedTransaction(parentReportAction); if (TransactionUtils.hasMissingSmartscanFields(transaction)) { _.extend(reportActionErrors, {smartscan: ErrorUtils.getMicroSecondOnyxError('report.genericSmartscanFailureMessage')}); From 212718dafee46367da507ab7a67f57ff22d6e132 Mon Sep 17 00:00:00 2001 From: Alberto Date: Mon, 18 Sep 2023 16:55:58 +0800 Subject: [PATCH 4/8] Add red dot to IOU report --- src/libs/OptionsListUtils.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index b945082d78c4..173afa3985a7 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -364,6 +364,10 @@ function getAllReportErrors(report, reportActions) { if (TransactionUtils.hasMissingSmartscanFields(transaction)) { _.extend(reportActionErrors, {smartscan: ErrorUtils.getMicroSecondOnyxError('report.genericSmartscanFailureMessage')}); } + } else if (ReportUtils.isIOUReport(report)) { + if (ReportUtils.hasMissingSmartscanFields(report.reportID)) { + _.extend(reportActionErrors, {smartscan: ErrorUtils.getMicroSecondOnyxError('report.genericSmartscanFailureMessage')}); + } } // All error objects related to the report. Each object in the sources contains error messages keyed by microtime From 349220bdc750f6084ab4ec3218b5bf297b582c44 Mon Sep 17 00:00:00 2001 From: Alberto Date: Mon, 18 Sep 2023 16:56:19 +0800 Subject: [PATCH 5/8] also request reports --- src/libs/OptionsListUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 173afa3985a7..3fbe92109447 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -364,7 +364,7 @@ function getAllReportErrors(report, reportActions) { if (TransactionUtils.hasMissingSmartscanFields(transaction)) { _.extend(reportActionErrors, {smartscan: ErrorUtils.getMicroSecondOnyxError('report.genericSmartscanFailureMessage')}); } - } else if (ReportUtils.isIOUReport(report)) { + } else if (ReportUtils.isIOUReport(report) || ReportUtils.isExpenseReport(report)) { if (ReportUtils.hasMissingSmartscanFields(report.reportID)) { _.extend(reportActionErrors, {smartscan: ErrorUtils.getMicroSecondOnyxError('report.genericSmartscanFailureMessage')}); } From 95af7e41853576ef201d9d57404a1ed7990009f8 Mon Sep 17 00:00:00 2001 From: Alberto Date: Tue, 26 Sep 2023 15:56:29 +0800 Subject: [PATCH 6/8] avoid deprecated methods --- src/libs/OptionsListUtils.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index d63272b8a591..dbf50b894e08 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -92,6 +92,18 @@ Onyx.connect({ }, }); +let allTransactions = {}; +Onyx.connect({ + key: ONYXKEYS.COLLECTION.TRANSACTION, + waitForCollectionCallback: true, + callback: (val) => { + if (!val) { + return; + } + allTransactions = _.pick(val, (transaction) => transaction); + }, +}); + /** * Get the option for a policy expense report. * @param {Object} report @@ -354,9 +366,10 @@ function getAllReportErrors(report, reportActions) { {}, ); - const parentReportAction = ReportActionUtils.getParentReportAction(report); + const parentReportAction = !report.parentReportID || !report.parentReportActionID ? {} : lodashGet(allSortedReportActions, [report.parentReportID, report.parentReportActionID], {}); if (parentReportAction.actorAccountID === currentUserAccountID && ReportActionUtils.isTransactionThread(parentReportAction)) { - const transaction = TransactionUtils.getLinkedTransaction(parentReportAction); + const transactionID = lodashGet(parentReportAction, ['originalMessage', 'IOUTransactionID'], ''); + const transaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] || {}; if (TransactionUtils.hasMissingSmartscanFields(transaction)) { _.extend(reportActionErrors, {smartscan: ErrorUtils.getMicroSecondOnyxError('report.genericSmartscanFailureMessage')}); } From d57390ebf69c5541084b675d90de0732f7dfd1f4 Mon Sep 17 00:00:00 2001 From: Alberto Date: Tue, 3 Oct 2023 23:12:49 +0800 Subject: [PATCH 7/8] fix transaction report --- src/libs/OptionsListUtils.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 7bb94014658d..c8d21ffb4c77 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -68,14 +68,16 @@ Onyx.connect({ const lastReportActions = {}; const allSortedReportActions = {}; +const allReportActions = {}; Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, callback: (actions, key) => { if (!key || !actions) { return; } - const sortedReportActions = ReportActionUtils.getSortedReportActions(_.toArray(actions), true); const reportID = CollectionUtils.extractCollectionItemID(key); + allReportActions[reportID] = actions; + const sortedReportActions = ReportActionUtils.getSortedReportActions(_.toArray(actions), true); allSortedReportActions[reportID] = sortedReportActions; lastReportActions[reportID] = _.first(sortedReportActions); }, @@ -366,7 +368,8 @@ function getAllReportErrors(report, reportActions) { {}, ); - const parentReportAction = !report.parentReportID || !report.parentReportActionID ? {} : lodashGet(allSortedReportActions, [report.parentReportID, report.parentReportActionID], {}); + const parentReportAction = !report.parentReportID || !report.parentReportActionID ? {} : lodashGet(allReportActions, [report.parentReportID, report.parentReportActionID], {}); + if (parentReportAction.actorAccountID === currentUserAccountID && ReportActionUtils.isTransactionThread(parentReportAction)) { const transactionID = lodashGet(parentReportAction, ['originalMessage', 'IOUTransactionID'], ''); const transaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] || {}; From 81e87d3494da66bb1a46bcf1f052c88cc4bd40b5 Mon Sep 17 00:00:00 2001 From: Alberto Date: Tue, 3 Oct 2023 23:22:53 +0800 Subject: [PATCH 8/8] only show for payee in IOU report --- src/libs/OptionsListUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index c8d21ffb4c77..95db528263dd 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -376,7 +376,7 @@ function getAllReportErrors(report, reportActions) { if (TransactionUtils.hasMissingSmartscanFields(transaction)) { _.extend(reportActionErrors, {smartscan: ErrorUtils.getMicroSecondOnyxError('report.genericSmartscanFailureMessage')}); } - } else if (ReportUtils.isIOUReport(report) || ReportUtils.isExpenseReport(report)) { + } else if ((ReportUtils.isIOUReport(report) || ReportUtils.isExpenseReport(report)) && report.ownerAccountID === currentUserAccountID) { if (ReportUtils.hasMissingSmartscanFields(report.reportID)) { _.extend(reportActionErrors, {smartscan: ErrorUtils.getMicroSecondOnyxError('report.genericSmartscanFailureMessage')}); }