From 340125530542703919edcd1ea9453d55650cda4b Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Thu, 4 Jan 2024 10:36:38 -0700 Subject: [PATCH 1/3] Subscribe to parent report actions in Onyx --- src/pages/home/ReportScreen.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 8e177e0c2e64..d1c61379a99d 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -66,8 +66,11 @@ const propTypes = { /** The report metadata loading states */ reportMetadata: reportMetadataPropTypes, - /** Array of report actions for this report */ - reportActions: PropTypes.arrayOf(PropTypes.shape(reportActionPropTypes)), + /** All the report actions for this report */ + reportActions: PropTypes.objectOf(PropTypes.shape(reportActionPropTypes)), + + /** All the report action belonging the report's parent */ + parentReportActions: PropTypes.objectOf(PropTypes.shape(reportActionPropTypes)), /** Whether the composer is full size */ isComposerFullSize: PropTypes.bool, @@ -104,7 +107,8 @@ const propTypes = { const defaultProps = { isSidebarLoaded: false, - reportActions: [], + reportActions: {}, + parentReportActions: {}, report: {}, reportMetadata: { isLoadingInitialReportActions: true, @@ -583,4 +587,14 @@ export default compose( }, true, ), + withOnyx( + { + // This is added down here so that it can access the full report object fetched from Onyx in the previous withOnyx. + parentReportActions: { + key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report ? report.parentReportID : 0}`, + canEvict: false, + }, + }, + true, + ), )(ReportScreen); From ce73e90783f1a308344668e673d9fc91d0a7f009 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Thu, 4 Jan 2024 10:49:20 -0700 Subject: [PATCH 2/3] Get parent report action from props --- src/pages/home/ReportScreen.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index d1c61379a99d..416a8b5f136e 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -148,6 +148,7 @@ function ReportScreen({ report, reportMetadata, reportActions, + parentReportActions, accountManagerReportID, personalDetails, markReadyForHydration, @@ -189,18 +190,12 @@ function ReportScreen({ // There are no reportActions at all to display and we are still in the process of loading the next set of actions. const isLoadingInitialReportActions = _.isEmpty(filteredReportActions) && reportMetadata.isLoadingInitialReportActions; - const isOptimisticDelete = lodashGet(report, 'statusNum') === CONST.REPORT.STATUS.CLOSED; - const shouldHideReport = !ReportUtils.canAccessReport(report, policies, betas); - const isLoading = !reportID || !isSidebarLoaded || _.isEmpty(personalDetails); - - const parentReportAction = ReportActionsUtils.getParentReportAction(report); + const parentReportAction = parentReportActions[report.parentReportActionID]; const isSingleTransactionView = ReportUtils.isMoneyRequest(report); - const policy = policies[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`] || {}; - const isTopMostReportId = currentReportID === getReportID(route); const didSubscribeToReportLeavingEvents = useRef(false); @@ -243,7 +238,6 @@ function ReportScreen({ policy={policy} personalDetails={personalDetails} isSingleTransactionView={isSingleTransactionView} - parentReportAction={parentReportAction} /> ); } From c89769788080cf710a7006598aaa7759f1415a76 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 8 Jan 2024 09:47:34 -0700 Subject: [PATCH 3/3] Use a selector --- src/pages/home/ReportScreen.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 416a8b5f136e..f9c7b9d2e6c1 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -69,8 +69,8 @@ const propTypes = { /** All the report actions for this report */ reportActions: PropTypes.objectOf(PropTypes.shape(reportActionPropTypes)), - /** All the report action belonging the report's parent */ - parentReportActions: PropTypes.objectOf(PropTypes.shape(reportActionPropTypes)), + /** The report's parentReportAction */ + parentReportAction: PropTypes.shape(reportActionPropTypes), /** Whether the composer is full size */ isComposerFullSize: PropTypes.bool, @@ -108,7 +108,7 @@ const propTypes = { const defaultProps = { isSidebarLoaded: false, reportActions: {}, - parentReportActions: {}, + parentReportAction: {}, report: {}, reportMetadata: { isLoadingInitialReportActions: true, @@ -148,7 +148,7 @@ function ReportScreen({ report, reportMetadata, reportActions, - parentReportActions, + parentReportAction, accountManagerReportID, personalDetails, markReadyForHydration, @@ -193,7 +193,6 @@ function ReportScreen({ const isOptimisticDelete = lodashGet(report, 'statusNum') === CONST.REPORT.STATUS.CLOSED; const shouldHideReport = !ReportUtils.canAccessReport(report, policies, betas); const isLoading = !reportID || !isSidebarLoaded || _.isEmpty(personalDetails); - const parentReportAction = parentReportActions[report.parentReportActionID]; const isSingleTransactionView = ReportUtils.isMoneyRequest(report); const policy = policies[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`] || {}; const isTopMostReportId = currentReportID === getReportID(route); @@ -578,14 +577,15 @@ export default compose( key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT_USER_IS_LEAVING_ROOM}${getReportID(route)}`, initialValue: false, }, - }, - true, - ), - withOnyx( - { - // This is added down here so that it can access the full report object fetched from Onyx in the previous withOnyx. - parentReportActions: { + parentReportAction: { key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report ? report.parentReportID : 0}`, + selector: (parentReportActions, props) => { + const parentReportActionID = lodashGet(props, 'report.parentReportActionID'); + if (!parentReportActionID) { + return {}; + } + return parentReportActions[parentReportActionID]; + }, canEvict: false, }, },