From c6212dc7c1b91f60102e14e25d16b71c61d5ba0f Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 2 Oct 2023 12:38:42 -0600 Subject: [PATCH 1/4] Load report action and transaction from withonyx --- src/pages/EditRequestPage.js | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index a0c60fe597fad..60ccaba9cb575 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -90,9 +90,8 @@ const defaultProps = { policyTags: {}, }; -function EditRequestPage({betas, report, route, parentReport, policy, session, policyCategories, policyTags}) { - const parentReportAction = ReportActionsUtils.getParentReportAction(report); - const transaction = TransactionUtils.getLinkedTransaction(parentReportAction); +function EditRequestPage({betas, report, route, parentReport, policy, session, policyCategories, policyTags, parentReportActions, transaction}) { + const parentReportAction = parentReportActions[report.parentReportActionID]; const { amount: transactionAmount, currency: transactionCurrency, @@ -292,18 +291,15 @@ EditRequestPage.defaultProps = defaultProps; export default compose( withCurrentUserPersonalDetails, withOnyx({ + betas: { + key: ONYXKEYS.BETAS, + }, report: { key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.threadReportID}`, }, }), // eslint-disable-next-line rulesdir/no-multiple-onyx-in-file withOnyx({ - betas: { - key: ONYXKEYS.BETAS, - }, - parentReport: { - key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT}${report ? report.parentReportID : '0'}`, - }, policy: { key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`, }, @@ -313,5 +309,20 @@ export default compose( policyTags: { key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report ? report.policyID : '0'}`, }, + parentReport: { + key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT}${report ? report.parentReportID : '0'}`, + }, + parentReportActions: { + key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report ? report.parentReportID : '0'}`, + canEvict: false, + }, + }), + withOnyx({ + transaction: { + key: ({report, parentReportActions}) => { + const parentReportAction = lodashGet(parentReportActions, [report.parentReportActionID]); + return `${ONYXKEYS.COLLECTION.TRANSACTION}${lodashGet(parentReportAction, 'originalMessage.IOUTransactionID', 0)}`; + }, + }, }), )(EditRequestPage); From 7efd88552072ddabb8ce49a5c5ca1d3f7ee98dbc Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 2 Oct 2023 12:54:30 -0600 Subject: [PATCH 2/4] Fix code so that data is loaded properly --- src/components/MoneyRequestHeader.js | 39 ++++++++++++++++------------ 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/components/MoneyRequestHeader.js b/src/components/MoneyRequestHeader.js index 9db9c87c4eb15..b080f81397b59 100644 --- a/src/components/MoneyRequestHeader.js +++ b/src/components/MoneyRequestHeader.js @@ -6,6 +6,7 @@ import lodashGet from 'lodash/get'; import HeaderWithBackButton from './HeaderWithBackButton'; import iouReportPropTypes from '../pages/iouReportPropTypes'; import * as ReportUtils from '../libs/ReportUtils'; +import compose from '../libs/compose'; import * as Expensicons from './Icon/Expensicons'; import participantPropTypes from './participantPropTypes'; import styles from '../styles/styles'; @@ -132,19 +133,25 @@ MoneyRequestHeader.displayName = 'MoneyRequestHeader'; MoneyRequestHeader.propTypes = propTypes; MoneyRequestHeader.defaultProps = defaultProps; -export default withOnyx({ - session: { - key: ONYXKEYS.SESSION, - }, - parentReport: { - key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`, - }, - parentReportAction: { - key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${(report.parentReportID, report.parentReportActionID)}`, - selector: (reportActions, props) => props && props.parentReport && reportActions && reportActions[props.parentReport.parentReportActionID], - canEvict: false, - }, - transaction: { - key: ({parentReportAction}) => `${ONYXKEYS.COLLECTION.TRANSACTION}${lodashGet(parentReportAction, 'originalMessage.IOUTransactionID', 0)}`, - }, -})(MoneyRequestHeader); +export default compose( + withOnyx({ + session: { + key: ONYXKEYS.SESSION, + }, + parentReport: { + key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`, + }, + parentReportActions: { + key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report ? report.parentReportID : '0'}`, + canEvict: false, + }, + }), + withOnyx({ + transaction: { + key: ({report, parentReportActions}) => { + const parentReportAction = lodashGet(parentReportActions, [report.parentReportActionID]); + return `${ONYXKEYS.COLLECTION.TRANSACTION}${lodashGet(parentReportAction, 'originalMessage.IOUTransactionID', 0)}`; + }, + }, + }), +)(MoneyRequestHeader); From 429427f447874f38042c62af7f1fe5091aa7bbbc Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 2 Oct 2023 12:54:47 -0600 Subject: [PATCH 3/4] Make this code more consistent with our patterns --- src/components/LHNOptionsList/OptionRowLHNData.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/LHNOptionsList/OptionRowLHNData.js b/src/components/LHNOptionsList/OptionRowLHNData.js index 87358f05b9c97..4190b36762d22 100644 --- a/src/components/LHNOptionsList/OptionRowLHNData.js +++ b/src/components/LHNOptionsList/OptionRowLHNData.js @@ -182,7 +182,7 @@ export default React.memo( }), withOnyx({ fullReport: { - key: (props) => ONYXKEYS.COLLECTION.REPORT + props.reportID, + key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, }, reportActions: { key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, From 6311f805e47beed35d798b3249769c8626fd511e Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 2 Oct 2023 13:20:53 -0600 Subject: [PATCH 4/4] Disable lint rule --- src/components/MoneyRequestHeader.js | 1 + src/pages/EditRequestPage.js | 1 + 2 files changed, 2 insertions(+) diff --git a/src/components/MoneyRequestHeader.js b/src/components/MoneyRequestHeader.js index b080f81397b59..5584da7007e1c 100644 --- a/src/components/MoneyRequestHeader.js +++ b/src/components/MoneyRequestHeader.js @@ -146,6 +146,7 @@ export default compose( canEvict: false, }, }), + // eslint-disable-next-line rulesdir/no-multiple-onyx-in-file withOnyx({ transaction: { key: ({report, parentReportActions}) => { diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index 60ccaba9cb575..28e70dc1a47ec 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -317,6 +317,7 @@ export default compose( canEvict: false, }, }), + // eslint-disable-next-line rulesdir/no-multiple-onyx-in-file withOnyx({ transaction: { key: ({report, parentReportActions}) => {