Skip to content

Commit

Permalink
add exception for checking report type
Browse files Browse the repository at this point in the history
  • Loading branch information
NikkiWines committed May 3, 2024
1 parent 125c725 commit f7cdd3f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
15 changes: 7 additions & 8 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,14 @@ Onyx.connect({
}
const reportID = CollectionUtils.extractCollectionItemID(key);
allReportActions[reportID] = actions;
const sortedReportActions = ReportActionUtils.getSortedReportActions(Object.values(actions), true);
let sortedReportActions = ReportActionUtils.getSortedReportActions(Object.values(actions), true);
allSortedReportActions[reportID] = sortedReportActions;

const transactionThreadReportID = ReportActionUtils.getOneTransactionThreadReportID(reportID, allReportActions[reportID], true);
if (transactionThreadReportID) {
sortedReportActions = ReportActionUtils.getCombinedReportActions(allSortedReportActions[reportID], allSortedReportActions[transactionThreadReportID]);
}

lastReportActions[reportID] = sortedReportActions[0];

// The report is only visible if it is the last action not deleted that
Expand Down Expand Up @@ -553,13 +559,6 @@ function getAlternateText(
* Get the last message text from the report directly or from other sources for special cases.
*/
function getLastMessageTextForReport(report: OnyxEntry<Report>, lastActorDetails: Partial<PersonalDetails> | null, policy?: OnyxEntry<Policy>): string {
const reportID = report?.reportID ?? '';
let reportActions = allSortedReportActions[reportID];
const transactionThreadReportID = ReportActionUtils.getOneTransactionThreadReportID(reportID, allReportActions[reportID]);
if (transactionThreadReportID) {
reportActions = ReportActionUtils.getCombinedReportActions(reportActions, allSortedReportActions[transactionThreadReportID]);
}

const lastReportAction = visibleReportActionItems[report?.reportID ?? ''] ?? null;

// some types of actions are filtered out for lastReportAction, in some cases we need to check the actual last action
Expand Down
12 changes: 7 additions & 5 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,11 +806,13 @@ function isTaskAction(reportAction: OnyxEntry<ReportAction>): boolean {
* Gets the reportID for the transaction thread associated with a report by iterating over the reportActions and identifying the IOU report actions.
* Returns a reportID if there is exactly one transaction thread for the report, and null otherwise.
*/
function getOneTransactionThreadReportID(reportID: string, reportActions: OnyxEntry<ReportActions> | ReportAction[], isOffline: boolean | undefined = undefined): string | null {
// If the report is not an IOU, Expense report, or Invoice, it shouldn't be treated as one-transaction report.
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
if (report?.type !== CONST.REPORT.TYPE.IOU && report?.type !== CONST.REPORT.TYPE.EXPENSE && report?.type !== CONST.REPORT.TYPE.INVOICE) {
return null;
function getOneTransactionThreadReportID(reportID: string, reportActions: OnyxEntry<ReportActions> | ReportAction[], skipReportTypeCheck: boolean | false = false, isOffline: boolean | undefined = undefined): string | null {

Check failure on line 809 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

false is overridden by boolean in this union type
if (!skipReportTypeCheck) {
// If the report is not an IOU, Expense report, or Invoice, it shouldn't be treated as one-transaction report.
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
if (report?.type !== CONST.REPORT.TYPE.IOU && report?.type !== CONST.REPORT.TYPE.EXPENSE && report?.type !== CONST.REPORT.TYPE.INVOICE) {
return null;
}
}

const reportActionsArray = Object.values(reportActions ?? {});
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ function ReportScreen({
}

const transactionThreadReportID = useMemo(
() => ReportActionsUtils.getOneTransactionThreadReportID(report.reportID, reportActions ?? [], isOffline),
() => ReportActionsUtils.getOneTransactionThreadReportID(report.reportID, reportActions ?? [], false, isOffline),
[report.reportID, reportActions, isOffline],
);

Expand Down

0 comments on commit f7cdd3f

Please sign in to comment.