Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the getPolicyName function for when the report or policies are not ready #48621

10 changes: 7 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,13 +739,17 @@
*/
function getPolicyName(report: OnyxInputOrEntry<Report>, returnEmptyIfNotFound = false, policy?: OnyxInputOrEntry<Policy>): string {
const noPolicyFound = returnEmptyIfNotFound ? '' : unavailableTranslation;
if (isEmptyObject(report)) {

Check failure on line 742 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Delete `····`
// Ensure policies and report are fully loaded before proceeding.
// On initial login, they may be partially loaded, so additional checks are necessary to prevent unexpected behavior.
if (isEmptyObject(report) || !report.reportID || isEmptyObject(allPolicies)) {
return noPolicyFound;
}

if ((!allPolicies || Object.keys(allPolicies).length === 0) && !report?.policyName) {

Check failure on line 748 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Delete `····`
if (isEmptyObject(allPolicies) && !report?.policyName) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@allgandalf upon further consideration, I believe the second check is unreachable. My suggestion would be to eliminate it. Your thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah i too checked, it is unreachable , lets remove this

return unavailableTranslation;
}

const finalPolicy = policy ?? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`];

const parentReport = getRootParentReport(report);
Expand Down
Loading