Skip to content

Commit

Permalink
Change solution that pass all test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
wildan-m committed Sep 9, 2024
1 parent 73c2b03 commit d49601a
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,17 +735,10 @@ const unavailableTranslation = Localize.translateLocal('workspace.common.unavail
*/
function getPolicyName(report: OnyxInputOrEntry<Report>, returnEmptyIfNotFound = false, policy?: OnyxInputOrEntry<Policy>): string {
const noPolicyFound = returnEmptyIfNotFound ? '' : unavailableTranslation;

// 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)) {
if (isEmptyObject(report) || (isEmptyObject(allPolicies) && !report?.policyName)) {
return noPolicyFound;
}

if (isEmptyObject(allPolicies) && !report?.policyName) {
return unavailableTranslation;
}

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

const parentReport = getRootParentReport(report);
Expand Down

0 comments on commit d49601a

Please sign in to comment.