From b955f5647f49f54258af1892525e8626fb90bdf0 Mon Sep 17 00:00:00 2001 From: Pavlo Tsimura Date: Wed, 7 Feb 2024 12:36:39 +0100 Subject: [PATCH] Show loader while fetching the report --- .../home/report/withReportOrNotFound.tsx | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/pages/home/report/withReportOrNotFound.tsx b/src/pages/home/report/withReportOrNotFound.tsx index 94000f8a6bd8..238b97dd190d 100644 --- a/src/pages/home/report/withReportOrNotFound.tsx +++ b/src/pages/home/report/withReportOrNotFound.tsx @@ -17,6 +17,9 @@ type WithReportOrNotFoundOnyxProps = { /** The report currently being looked at */ report: OnyxEntry; + /** Metadata of the report currently being looked at */ + reportMetadata: OnyxEntry; + /** The policies which the user has access to */ policies: OnyxCollection; @@ -42,28 +45,29 @@ export default function ( return function (WrappedComponent: ComponentType>) { function WithReportOrNotFound(props: TProps, ref: ForwardedRef) { const contentShown = React.useRef(false); + const isReportIdInRoute = !!props.route.params.reportID?.length; + const isReportLoaded = !isEmptyObject(props.report) && !!props.report?.reportID; - const isReportIdInRoute = props.route.params.reportID?.length; + // The `isLoadingInitialReportActions` value will become `false` only after the first OpenReport API call is finished (either succeeded or failed) + const shouldFetchReport = isReportIdInRoute && props.reportMetadata?.isLoadingInitialReportActions !== false; // When accessing certain report-dependant pages (e.g. Task Title) by deeplink, the OpenReport API is not called, // So we need to call OpenReport API here to make sure the report data is loaded if it exists on the Server useEffect(() => { - if (!isReportIdInRoute || !isEmptyObject(props.report)) { + if (isReportLoaded || !shouldFetchReport) { // If the report is not required or is already loaded, we don't need to call the API return; } Report.openReport(props.route.params.reportID); // eslint-disable-next-line react-hooks/exhaustive-deps - }, [isReportIdInRoute, props.route.params.reportID]); + }, [shouldFetchReport, isReportLoaded, props.route.params.reportID]); if (shouldRequireReportID || isReportIdInRoute) { - const shouldShowFullScreenLoadingIndicator = props.isLoadingReportData !== false && (!Object.entries(props.report ?? {}).length || !props.report?.reportID); - - const shouldShowNotFoundPage = - !Object.entries(props.report ?? {}).length || !props.report?.reportID || !ReportUtils.canAccessReport(props.report, props.policies, props.betas); + const shouldShowFullScreenLoadingIndicator = !isReportLoaded && (props.isLoadingReportData !== false || shouldFetchReport); + const shouldShowNotFoundPage = !isReportLoaded || !ReportUtils.canAccessReport(props.report, props.policies, props.betas); - // If the content was shown but it's not anymore that means the report was deleted and we are probably navigating out of this screen. + // If the content was shown, but it's not anymore, that means the report was deleted, and we are probably navigating out of this screen. // Return null for this case to avoid rendering FullScreenLoadingIndicator or NotFoundPage when animating transition. if (shouldShowNotFoundPage && contentShown.current) { return null; @@ -97,6 +101,9 @@ export default function ( report: { key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.reportID}`, }, + reportMetadata: { + key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT_METADATA}${route.params.reportID}`, + }, isLoadingReportData: { key: ONYXKEYS.IS_LOADING_REPORT_DATA, },