Skip to content

Commit

Permalink
Merge pull request #28584 from margelo/osp/fix-not-found-page
Browse files Browse the repository at this point in the history
[CP Staging] Fixes not found page not being shown properly when not having access to report

(cherry picked from commit fac61c8)
  • Loading branch information
mountiny authored and OSBotify committed Oct 2, 2023
1 parent 5e42dec commit f6c11e0
Showing 1 changed file with 7 additions and 26 deletions.
33 changes: 7 additions & 26 deletions src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const defaultProps = {
hasOutstandingIOU: false,
},
reportMetadata: {
isLoadingReportActions: false,
isLoadingReportActions: true,
isLoadingMoreReportActions: false,
},
isComposerFullSize: false,
Expand All @@ -118,15 +118,6 @@ const defaultProps = {
...withCurrentReportIDDefaultProps,
};

/**
*
* Function to check weather the report available in props is default
*
* @param {Object} report
* @returns {Boolean}
*/
const checkDefaultReport = (report) => report === defaultProps.report;

/**
* Get the currently viewed report ID as number
*
Expand Down Expand Up @@ -188,8 +179,6 @@ function ReportScreen({
const isTopMostReportId = currentReportID === getReportID(route);
const didSubscribeToReportLeavingEvents = useRef(false);

const isDefaultReport = checkDefaultReport(report);

let headerView = (
<HeaderView
reportID={reportID}
Expand Down Expand Up @@ -248,11 +237,12 @@ function ReportScreen({
// It possible that we may not have the report object yet in Onyx yet e.g. we navigated to a URL for an accessible report that
// is not stored locally yet. If report.reportID exists, then the report has been stored locally and nothing more needs to be done.
// If it doesn't exist, then we fetch the report from the API.
if (report.reportID && report.reportID === getReportID(route)) {
if (report.reportID && report.reportID === getReportID(route) && !isLoadingInitialReportActions) {
return;
}

Report.openReport(reportIDFromPath);
}, [report.reportID, route]);
}, [report.reportID, route, isLoadingInitialReportActions]);

const dismissBanner = useCallback(() => {
setIsBannerVisible(false);
Expand Down Expand Up @@ -364,17 +354,8 @@ function ReportScreen({

// eslint-disable-next-line rulesdir/no-negated-variables
const shouldShowNotFoundPage = useMemo(
() =>
(!firstRenderRef.current &&
!_.isEmpty(report) &&
!isDefaultReport &&
!report.reportID &&
!isOptimisticDelete &&
!report.isLoadingReportActions &&
!isLoading &&
!userLeavingStatus) ||
shouldHideReport,
[report, isLoading, shouldHideReport, isDefaultReport, isOptimisticDelete, userLeavingStatus],
() => (!firstRenderRef.current && !report.reportID && !isOptimisticDelete && !reportMetadata.isLoadingReportActions && !isLoading && !userLeavingStatus) || shouldHideReport,
[report, reportMetadata, isLoading, shouldHideReport, isOptimisticDelete, userLeavingStatus],
);

return (
Expand Down Expand Up @@ -486,7 +467,7 @@ export default compose(
reportMetadata: {
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT_METADATA}${getReportID(route)}`,
initialValue: {
isLoadingReportActions: false,
isLoadingReportActions: true,
isLoadingMoreReportActions: false,
},
},
Expand Down

0 comments on commit f6c11e0

Please sign in to comment.