Skip to content

Commit

Permalink
Merge pull request #28560 from mkhutornyi/fix-28504
Browse files Browse the repository at this point in the history
[CP Staging] prevent OpenReport api call with "null" report
  • Loading branch information
mountiny authored Oct 2, 2023
2 parents 4842282 + 5540727 commit 5865e08
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3382,7 +3382,16 @@ function shouldReportShowSubscript(report) {
* @returns {Boolean}
*/
function isReportDataReady() {
return !_.isEmpty(allReports) && _.some(_.keys(allReports), (key) => allReports[key].reportID);
return !_.isEmpty(allReports) && _.some(_.keys(allReports), (key) => allReports[key] && allReports[key].reportID);
}

/**
* Return true if reportID from path is valid
* @param {String} reportIDFromPath
* @returns {Boolean}
*/
function isValidReportIDFromPath(reportIDFromPath) {
return typeof reportIDFromPath === 'string' && !['', 'null', '0'].includes(reportIDFromPath);
}

/**
Expand Down Expand Up @@ -3764,6 +3773,7 @@ export {
isChildReport,
shouldReportShowSubscript,
isReportDataReady,
isValidReportIDFromPath,
isSettled,
isAllowedToComment,
getBankAccountRoute,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function ReportScreen({

// Report ID will be empty when the reports collection is empty.
// This could happen when we are loading the collection for the first time after logging in.
if (!reportIDFromPath) {
if (!ReportUtils.isValidReportIDFromPath(reportIDFromPath)) {
return;
}

Expand Down

0 comments on commit 5865e08

Please sign in to comment.