Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6029,6 +6029,40 @@ function getReportName(
function getSearchReportName(props: GetReportNameParams): string {
const {report, policy} = props;
if (isChatThread(report) && policy?.name) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we still need this policy?.name check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The check ensures we only use this special traversal logic when we have a valid policy name to return. Without it, we could return undefined instead of letting getReportName() handle the case with its fallbacks.

// Traverse up the parent chain to find the first expense report
// If found, return the expense report name instead of workspace name
let currentParent = getParentReport(report);
const visitedReportIDs = new Set<string>();

while (currentParent) {
if (!currentParent.reportID) {
break;
}
if (visitedReportIDs.has(currentParent.reportID)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we guarantee this reportID exists?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, we cannot guarantee reportID exists at runtime, even though TypeScript marks it as required. So I add a guard check logic.

break;
Copy link
Contributor

Choose a reason for hiding this comment

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

If we break, we still return policy name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

}
visitedReportIDs.add(currentParent.reportID);

if (isExpenseReport(currentParent)) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
return getReportName(
currentParent,
policy,
props.parentReportActionParam,
props.personalDetails,
props.invoiceReceiverPolicy,
undefined,
props.transactions,
props.isReportArchived,
props.reports,
props.policies,
);
}

// Continue traversing up the parent chain
currentParent = getParentReport(currentParent);
}

return policy.name;
}
// This will be fixed as follow up https://github.com/Expensify/App/pull/75357
Expand Down
Loading