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: report title is incorrect for IOU grouped expense in search page #47029

Merged
merged 7 commits into from
Aug 14, 2024
Merged
Changes from 4 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
30 changes: 29 additions & 1 deletion src/libs/SearchUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,19 @@ import type {SearchAdvancedFiltersForm} from '@src/types/form';
import FILTER_KEYS from '@src/types/form/SearchAdvancedFiltersForm';
import type * as OnyxTypes from '@src/types/onyx';
import type SearchResults from '@src/types/onyx/SearchResults';
import type {ListItemDataType, ListItemType, SearchAccountDetails, SearchDataTypes, SearchPersonalDetails, SearchTransaction} from '@src/types/onyx/SearchResults';
import type {
ListItemDataType,
ListItemType,
SearchAccountDetails,
SearchDataTypes,
SearchPersonalDetails,
SearchPolicyDetails,
SearchReport,
SearchTransaction,
} from '@src/types/onyx/SearchResults';
import * as CurrencyUtils from './CurrencyUtils';
import DateUtils from './DateUtils';
import {translateLocal} from './Localize';
import navigationRef from './Navigation/navigationRef';
import type {AuthScreensParamList, BottomTabNavigatorParamList, RootStackParamList, State} from './Navigation/types';
import * as searchParser from './SearchParser/searchParser';
Expand Down Expand Up @@ -173,6 +184,21 @@ function getTransactionsSections(data: OnyxTypes.SearchResults['data'], metadata
});
}

function getIOUReportName(data: OnyxTypes.SearchResults['data'], reportItem: SearchTransaction & Record<string, SearchPersonalDetails> & SearchPolicyDetails & SearchReport) {
const payerPersonalDetails = data.personalDetailsList?.[reportItem.managerID] as SearchAccountDetails;
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const payerName = payerPersonalDetails?.name || payerPersonalDetails?.displayName || payerPersonalDetails?.login || translateLocal('common.hidden');
const formattedAmount = CurrencyUtils.convertToDisplayString(reportItem.total ?? 0, reportItem?.currency ?? CONST.CURRENCY.USD);
if (reportItem.action === CONST.SEARCH.ACTION_TYPES.VIEW) {
return translateLocal('iou.payerOwesAmount', {payer: payerName, amount: formattedAmount});
}

return translateLocal('iou.payerPaidAmount', {
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
payer: payerName,
amount: formattedAmount,
});
}

function getReportSections(data: OnyxTypes.SearchResults['data'], metadata: OnyxTypes.SearchResults['search']): ReportListItemType[] {
const shouldShowMerchant = getShouldShowMerchant(data);

Expand All @@ -185,6 +211,7 @@ function getReportSections(data: OnyxTypes.SearchResults['data'], metadata: Onyx
const reportKey = `${ONYXKEYS.COLLECTION.REPORT}${reportItem.reportID}`;
const transactions = reportIDToTransactions[reportKey]?.transactions ?? [];
const isExpenseReport = reportItem.type === CONST.REPORT.TYPE.EXPENSE;
const isIOUReport = reportItem.type === CONST.REPORT.TYPE.IOU;

const to = isExpenseReport
? (data[`${ONYXKEYS.COLLECTION.POLICY}${reportItem.policyID}`] as SearchAccountDetails)
Expand All @@ -196,6 +223,7 @@ function getReportSections(data: OnyxTypes.SearchResults['data'], metadata: Onyx
from: data.personalDetailsList?.[reportItem.accountID],
to,
transactions,
reportName: isIOUReport ? getIOUReportName(data, reportItem) : reportItem.reportName,
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
};
} else if (key.startsWith(ONYXKEYS.COLLECTION.TRANSACTION)) {
const transactionItem = {...data[key]};
Expand Down
Loading