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

5 changes: 1 addition & 4 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,13 +735,10 @@ const unavailableTranslation = Localize.translateLocal('workspace.common.unavail
*/
function getPolicyName(report: OnyxInputOrEntry<Report>, returnEmptyIfNotFound = false, policy?: OnyxInputOrEntry<Policy>): string {
const noPolicyFound = returnEmptyIfNotFound ? '' : unavailableTranslation;
if (isEmptyObject(report)) {
if (isEmptyObject(report) || (isEmptyObject(allPolicies) && !report?.policyName)) {
return noPolicyFound;
}

if ((!allPolicies || Object.keys(allPolicies).length === 0) && !report?.policyName) {
return unavailableTranslation;
}
const finalPolicy = policy ?? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`];

const parentReport = getRootParentReport(report);
Expand Down
Loading