Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function MoneyRequestReportNavigation({reportID, shouldDisplayNarrowVersion}: Mo
data: currentSearchResults.data,
currentAccountID: currentUserDetails.accountID,
currentUserEmail: currentUserDetails.email ?? '',
translate,
formatPhoneNumber,
groupBy,
reportActions: exportReportActions,
Expand Down
2 changes: 2 additions & 0 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ function Search({
data: searchResults.data,
currentAccountID: accountID,
currentUserEmail: email ?? '',
translate,
formatPhoneNumber,
groupBy: validGroupBy,
reportActions: exportReportActions,
Expand All @@ -474,6 +475,7 @@ function Search({
searchResults,
type,
archivedReportsIdSet,
translate,
formatPhoneNumber,
accountID,
queryJSON,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function TransactionGroupListItem<TItem extends ListItem>({
const groupItem = item as unknown as TransactionGroupListItemType;
const theme = useTheme();
const styles = useThemeStyles();
const {formatPhoneNumber} = useLocalize();
const {translate, formatPhoneNumber} = useLocalize();
const {selectedTransactions} = useSearchContext();
const {isLargeScreenWidth} = useResponsiveLayout();
const currentUserDetails = useCurrentUserPersonalDetails();
Expand Down Expand Up @@ -109,14 +109,25 @@ function TransactionGroupListItem<TItem extends ListItem>({
data: transactionsSnapshot?.data,
currentAccountID: accountID,
currentUserEmail: currentUserDetails.email ?? '',
translate,
formatPhoneNumber,
isActionLoadingSet,
}) as [TransactionListItemType[], number];
return sectionData.map((transactionItem) => ({
...transactionItem,
isSelected: selectedTransactionIDsSet.has(transactionItem.transactionID),
}));
}, [isExpenseReportType, transactionsSnapshot?.data, accountID, formatPhoneNumber, groupItem.transactions, selectedTransactionIDsSet, currentUserDetails.email, isActionLoadingSet]);
}, [
isExpenseReportType,
transactionsSnapshot?.data,
accountID,
translate,
formatPhoneNumber,
groupItem.transactions,
selectedTransactionIDsSet,
currentUserDetails.email,
isActionLoadingSet,
]);

const selectedItemsLength = useMemo(() => {
return transactions.reduce((acc, transaction) => {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useSearchTypeMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ export default function useSearchTypeMenu(queryJSON: SearchQueryJSON) {
}, []);

const getOverflowMenu = useCallback(
(itemName: string, itemHash: number, itemQuery: string) => getOverflowMenuUtil(expensifyIcons, itemName, itemHash, itemQuery, showDeleteModal, true, closeMenu),
[showDeleteModal, closeMenu, expensifyIcons],
(itemName: string, itemHash: number, itemQuery: string) => getOverflowMenuUtil(expensifyIcons, itemName, itemHash, itemQuery, translate, showDeleteModal, true, closeMenu),
[translate, showDeleteModal, closeMenu, expensifyIcons],
);

const {savedSearchesMenuItems, isSavedSearchActive} = useMemo(() => {
Expand Down
27 changes: 12 additions & 15 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ import {getCardDescription, getCustomOrFormattedFeedName} from './CardUtils';
import {convertToDisplayString, getCurrencySymbol} from './CurrencyUtils';
import DateUtils from './DateUtils';
import interceptAnonymousUser from './interceptAnonymousUser';
// eslint-disable-next-line @typescript-eslint/no-deprecated
import {translateLocal} from './Localize';
import Navigation from './Navigation/Navigation';
import Parser from './Parser';
import {getDisplayNameOrDefault} from './PersonalDetailsUtils';
Expand Down Expand Up @@ -342,6 +340,7 @@ type GetSectionsParams = {
data: OnyxTypes.SearchResults['data'];
currentAccountID: number | undefined;
currentUserEmail: string;
translate: LocalizedTranslate;
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'];
groupBy?: SearchGroupBy;
reportActions?: Record<string, OnyxTypes.ReportAction[]>;
Expand Down Expand Up @@ -1084,18 +1083,16 @@ function getViolations(data: OnyxTypes.SearchResults['data']): OnyxCollection<On
* @private
* Generates a display name for IOU reports considering the personal details of the payer and the transaction details.
*/
function getIOUReportName(data: OnyxTypes.SearchResults['data'], reportItem: TransactionReportGroupListItemType) {
function getIOUReportName(translate: LocalizedTranslate, data: OnyxTypes.SearchResults['data'], reportItem: TransactionReportGroupListItemType) {
const payerPersonalDetails = reportItem.managerID ? data.personalDetailsList?.[reportItem.managerID] : emptyPersonalDetails;
// For cases where the data personal detail for manager ID do not exist in search data.personalDetailsList
// we fallback to the display name of the personal detail data from onyx.
const payerName = payerPersonalDetails?.displayName ?? payerPersonalDetails?.login ?? getDisplayNameOrDefault(getPersonalDetailsForAccountID(reportItem.managerID));
const formattedAmount = convertToDisplayString(reportItem.total ?? 0, reportItem.currency ?? CONST.CURRENCY.USD);
if (reportItem.action === CONST.SEARCH.ACTION_TYPES.PAID) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
return translateLocal('iou.payerPaidAmount', formattedAmount, payerName);
return translate('iou.payerPaidAmount', formattedAmount, payerName);
}
// eslint-disable-next-line @typescript-eslint/no-deprecated
return translateLocal('iou.payerOwesAmount', formattedAmount, payerName);
return translate('iou.payerOwesAmount', formattedAmount, payerName);
}

function getTransactionViolations(
Expand Down Expand Up @@ -1666,6 +1663,7 @@ function getReportSections(
currentSearch: SearchKey,
currentAccountID: number | undefined,
currentUserEmail: string,
translate: LocalizedTranslate,
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'],
isActionLoadingSet: ReadonlySet<string> | undefined,
reportActions: Record<string, OnyxTypes.ReportAction[]> = {},
Expand Down Expand Up @@ -1749,8 +1747,7 @@ function getReportSections(
const formattedFrom = formatPhoneNumber(getDisplayNameOrDefault(fromDetails));
const formattedTo = !shouldShowBlankTo ? formatPhoneNumber(getDisplayNameOrDefault(toDetails)) : '';

// eslint-disable-next-line @typescript-eslint/no-deprecated
const formattedStatus = getReportStatusTranslation({stateNum: reportItem.stateNum, statusNum: reportItem.statusNum, translate: translateLocal});
const formattedStatus = getReportStatusTranslation({stateNum: reportItem.stateNum, statusNum: reportItem.statusNum, translate});

const allReportTransactions = getTransactionsForReport(data, reportItem.reportID);
const policy = getPolicyFromKey(data, reportItem);
Expand Down Expand Up @@ -1790,7 +1787,7 @@ function getReportSections(
};

if (isIOUReport) {
reportIDToTransactions[reportKey].reportName = getIOUReportName(data, reportIDToTransactions[reportKey]);
reportIDToTransactions[reportKey].reportName = getIOUReportName(translate, data, reportIDToTransactions[reportKey]);
}
}
} else if (isTransactionEntry(key)) {
Expand Down Expand Up @@ -2027,6 +2024,7 @@ function getSections({
data,
currentAccountID,
currentUserEmail,
translate,
formatPhoneNumber,
groupBy,
reportActions = {},
Expand All @@ -2044,7 +2042,7 @@ function getSections({
}

if (type === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT) {
return getReportSections(data, currentSearch, currentAccountID, currentUserEmail, formatPhoneNumber, isActionLoadingSet, reportActions);
return getReportSections(data, currentSearch, currentAccountID, currentUserEmail, translate, formatPhoneNumber, isActionLoadingSet, reportActions);
}

if (groupBy) {
Expand Down Expand Up @@ -2613,14 +2611,14 @@ function getOverflowMenu(
itemName: string,
hash: number,
inputQuery: string,
translate: LocalizedTranslate,
showDeleteModal: (hash: number) => void,
isMobileMenu?: boolean,
closeMenu?: () => void,
) {
return [
{
// eslint-disable-next-line @typescript-eslint/no-deprecated
text: translateLocal('common.rename'),
text: translate('common.rename'),
onSelected: () => {
if (isMobileMenu && closeMenu) {
closeMenu();
Expand All @@ -2633,8 +2631,7 @@ function getOverflowMenu(
shouldCallAfterModalHide: true,
},
{
// eslint-disable-next-line @typescript-eslint/no-deprecated
text: translateLocal('common.delete'),
text: translate('common.delete'),
onSelected: () => {
if (isMobileMenu && closeMenu) {
closeMenu();
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Search/SearchTypeMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ function SearchTypeMenu({queryJSON}: SearchTypeMenuProps) {
});

const getOverflowMenu = useCallback(
(itemName: string, itemHash: number, itemQuery: string) => getOverflowMenuUtil(expensifyIcons, itemName, itemHash, itemQuery, showDeleteModal),
[showDeleteModal, expensifyIcons],
(itemName: string, itemHash: number, itemQuery: string) => getOverflowMenuUtil(expensifyIcons, itemName, itemHash, itemQuery, translate, showDeleteModal),
[translate, showDeleteModal, expensifyIcons],
);
const createSavedSearchMenuItem = useCallback(
(item: SaveSearchItem, key: string, index: number) => {
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/Search/SearchUIUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1865,6 +1865,7 @@ describe('SearchUIUtils', () => {
data: searchResults.data,
currentAccountID: 2074551,
currentUserEmail: '',
translate: translateLocal,
formatPhoneNumber,
});
expect(filteredReportActions).toStrictEqual(reportActionListItems);
Expand All @@ -1878,6 +1879,7 @@ describe('SearchUIUtils', () => {
data: searchResults.data,
currentAccountID: 20745,
currentUserEmail: '',
translate: translateLocal,
formatPhoneNumber,
})[0],
).toEqual(transactionsListItems);
Expand All @@ -1902,6 +1904,7 @@ describe('SearchUIUtils', () => {
data: testSearchResults.data,
currentAccountID: 2074551,
currentUserEmail: '',
translate: translateLocal,
formatPhoneNumber,
})[0] as TransactionListItemType[];

Expand Down Expand Up @@ -1933,6 +1936,7 @@ describe('SearchUIUtils', () => {
data: testSearchResults.data,
currentAccountID: 2074551,
currentUserEmail: '',
translate: translateLocal,
formatPhoneNumber,
})[0] as TransactionGroupListItemType[];

Expand All @@ -1954,6 +1958,7 @@ describe('SearchUIUtils', () => {
data: searchResults.data,
currentAccountID: 2074551,
currentUserEmail: '',
translate: translateLocal,
formatPhoneNumber,
})[0],
).toStrictEqual(transactionReportGroupListItems);
Expand Down Expand Up @@ -1993,13 +1998,15 @@ describe('SearchUIUtils', () => {
data: testDataTransactionFirst,
currentAccountID: 2074551,
currentUserEmail: '',
translate: translateLocal,
formatPhoneNumber,
})[0];
const resultReportFirst = SearchUIUtils.getSections({
type: CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT,
data: testDataReportFirst,
currentAccountID: 2074551,
currentUserEmail: '',
translate: translateLocal,
formatPhoneNumber,
})[0];

Expand All @@ -2020,6 +2027,7 @@ describe('SearchUIUtils', () => {
data: searchResultsGroupByFrom.data,
currentAccountID: 2074551,
currentUserEmail: '',
translate: translateLocal,
formatPhoneNumber,
groupBy: CONST.SEARCH.GROUP_BY.FROM,
})[0],
Expand All @@ -2033,6 +2041,7 @@ describe('SearchUIUtils', () => {
data: searchResultsGroupByCard.data,
currentAccountID: 2074551,
currentUserEmail: '',
translate: translateLocal,
formatPhoneNumber,
groupBy: CONST.SEARCH.GROUP_BY.CARD,
})[0],
Expand All @@ -2046,6 +2055,7 @@ describe('SearchUIUtils', () => {
data: searchResultsGroupByWithdrawalID.data,
currentAccountID: 2074551,
currentUserEmail: '',
translate: translateLocal,
formatPhoneNumber,
groupBy: CONST.SEARCH.GROUP_BY.WITHDRAWAL_ID,
})[0],
Expand All @@ -2068,6 +2078,7 @@ describe('SearchUIUtils', () => {
data: staleCacheData,
currentAccountID: 2074551,
currentUserEmail: '',
translate: translateLocal,
formatPhoneNumber,
groupBy: CONST.SEARCH.GROUP_BY.WITHDRAWAL_ID,
}) as [TransactionWithdrawalIDGroupListItemType[], number];
Expand Down
Loading