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 @@ -156,8 +156,9 @@ function TransactionPreviewContent({
currentUserEmail,
currentUserAccountID,
originalTransaction,
convertToDisplayString,
}),
[transactionPreviewCommonArguments, shouldShowRBR, violationMessage, reportActions, currentUserEmail, currentUserAccountID, originalTransaction],
[transactionPreviewCommonArguments, shouldShowRBR, violationMessage, reportActions, currentUserEmail, currentUserAccountID, originalTransaction, convertToDisplayString],
);
const getTranslatedText = (item: TranslationPathOrText) => (item.translationPath ? translate(item.translationPath) : (item.text ?? ''));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {SearchGroupBy} from '@components/Search/types';
import type {ListItem} from '@components/SelectionList/types';
import useActionLoadingReportIDs from '@hooks/useActionLoadingReportIDs';
import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle';
import {useCurrencyListActions} from '@hooks/useCurrencyList';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
Expand Down Expand Up @@ -94,6 +95,7 @@ function TransactionGroupListItem<TItem extends ListItem>({
const {isLargeScreenWidth} = useResponsiveLayout();
const currentUserDetails = useCurrentUserPersonalDetails();
const isScreenFocused = useIsFocused();
const {convertToDisplayString} = useCurrencyListActions();

const oneTransactionItem = groupItem.isOneTransactionReport ? groupItem.transactions.at(0) : undefined;
const [parentReport] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(oneTransactionItem?.reportID)}`);
Expand Down Expand Up @@ -141,6 +143,7 @@ function TransactionGroupListItem<TItem extends ListItem>({
allReportMetadata,
cardFeeds,
conciergeReportID,
convertToDisplayString,
}) as [TransactionListItemType[], number, boolean];
transactions = sectionData.map((transactionItem) => ({
...transactionItem,
Expand Down
3 changes: 3 additions & 0 deletions src/components/Search/SearchStaticList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeed
import SearchRowSkeleton from '@components/Skeletons/SearchRowSkeleton';
import StatusBadge from '@components/StatusBadge';
import TransactionItemRow from '@components/TransactionItemRow';
import {useCurrencyListActions} from '@hooks/useCurrencyList';
import useLocalize from '@hooks/useLocalize';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
Expand Down Expand Up @@ -69,6 +70,7 @@ function SearchStaticList({
const theme = useTheme();
const StyleUtils = useStyleUtils();
const {translate, localeCompare, formatPhoneNumber} = useLocalize();
const {convertToDisplayString} = useCurrencyListActions();
const session = useSession();
const accountID = session?.accountID ?? CONST.DEFAULT_NUMBER_ID;
const email = session?.email;
Expand Down Expand Up @@ -96,6 +98,7 @@ function SearchStaticList({
bankAccountList: undefined,
allReportMetadata: undefined,
conciergeReportID: undefined,
convertToDisplayString,
});

return getSortedSections(type, status, filteredData, localeCompare, translate, sortBy, sortOrder, validGroupBy)
Expand Down
7 changes: 7 additions & 0 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import SearchRowSkeleton from '@components/Skeletons/SearchRowSkeleton';
import {useWideRHPActions} from '@components/WideRHPContextProvider';
import useActionLoadingReportIDs from '@hooks/useActionLoadingReportIDs';
import useArchivedReportsIdSet from '@hooks/useArchivedReportsIdSet';
import {useCurrencyListActions} from '@hooks/useCurrencyList';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useMultipleSnapshots from '@hooks/useMultipleSnapshots';
Expand Down Expand Up @@ -352,6 +353,8 @@ function Search({
selector: savedSearchSelector,
});

const {convertToDisplayString} = useCurrencyListActions();

const validGroupBy = getValidGroupBy(groupBy);
const prevValidGroupBy = usePrevious(validGroupBy);
const isSearchResultsEmpty = !searchResults?.data || isSearchResultsEmptyUtil(searchResults, validGroupBy);
Expand Down Expand Up @@ -544,6 +547,7 @@ function Search({
conciergeReportID,
onyxPersonalDetailsList,
policyForMovingExpenses,
convertToDisplayString,
});
return {
baseFilteredData: filteredData1,
Expand Down Expand Up @@ -576,6 +580,7 @@ function Search({
conciergeReportID,
onyxPersonalDetailsList,
policyForMovingExpenses,
convertToDisplayString,
]);

// For group-by views, each grouped item has a transactionsQueryJSON with a hash pointing to a separate snapshot
Expand Down Expand Up @@ -612,6 +617,7 @@ function Search({
cardFeeds,
allReportMetadata,
conciergeReportID,
convertToDisplayString,
});
return {
...item,
Expand All @@ -635,6 +641,7 @@ function Search({
bankAccountList,
allReportMetadata,
conciergeReportID,
convertToDisplayString,
]);

const hasLoadedAllTransactions = useMemo(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useSearchBulkActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
'Workflows',
]);

const {getCurrencyDecimals} = useCurrencyListActions();
const {getCurrencyDecimals, convertToDisplayString} = useCurrencyListActions();

const selectedTransactionReportIDs = useMemo(
() => [
Expand Down Expand Up @@ -315,7 +315,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
[selectedTransactions],
);
const selectedBulkCurrency = selectedReports.at(0)?.currency ?? Object.values(selectedTransactions).at(0)?.currency;
const totalFormattedAmount = getTotalFormattedAmount(selectedReports, selectedTransactions, selectedBulkCurrency);
const totalFormattedAmount = getTotalFormattedAmount(convertToDisplayString, selectedReports, selectedTransactions, selectedBulkCurrency);

const onlyShowPayElsewhere = useMemo(() => {
const firstPolicyID = selectedPolicyIDs.at(0);
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/useSearchSections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {Report} from '@src/types/onyx';
import type LastSearchParams from '@src/types/onyx/ReportNavigation';
import useActionLoadingReportIDs from './useActionLoadingReportIDs';
import useArchivedReportsIdSet from './useArchivedReportsIdSet';
import {useCurrencyListActions} from './useCurrencyList';
import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails';
import useLocalize from './useLocalize';
import useOnyx from './useOnyx';
Expand Down Expand Up @@ -39,6 +40,7 @@ function useSearchSections(): UseSearchSectionsResult {
const currentUserDetails = useCurrentUserPersonalDetails();
const {localeCompare, formatPhoneNumber, translate} = useLocalize();
const isActionLoadingSet = useActionLoadingReportIDs();
const {convertToDisplayString} = useCurrencyListActions();

const [exportReportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, {
selector: selectFilteredReportActions,
Expand Down Expand Up @@ -76,6 +78,7 @@ function useSearchSections(): UseSearchSectionsResult {
cardFeeds,
allReportMetadata,
conciergeReportID,
convertToDisplayString,
});
results = getSortedSections(type, status ?? '', searchData, localeCompare, translate, sortBy, sortOrder, groupBy).map((value) => value.reportID);
}
Expand Down
16 changes: 13 additions & 3 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ import type {CardFeedForDisplay} from './CardFeedUtils';
import {getCardFeedsForDisplay} from './CardFeedUtils';
import {getCardDescriptionForSearchTable, getFeedNameForDisplay} from './CardUtils';
import {getDecodedCategoryName} from './CategoryUtils';
import {convertToDisplayString, convertToDisplayStringWithoutCurrency} from './CurrencyUtils';
import {convertToDisplayStringWithoutCurrency} from './CurrencyUtils';
import DateUtils from './DateUtils';
import interceptAnonymousUser from './interceptAnonymousUser';
import isSearchTopmostFullScreenRoute from './Navigation/helpers/isSearchTopmostFullScreenRoute';
Expand Down Expand Up @@ -239,6 +239,7 @@ type GetReportSectionsParams = {
currentUserEmail: string;
translate: LocalizedTranslate;
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'];
convertToDisplayString: CurrencyListActionsContextType['convertToDisplayString'];
isActionLoadingSet: ReadonlySet<string> | undefined;
isOffline: boolean | undefined;
allTransactionViolations: OnyxCollection<OnyxTypes.TransactionViolation[]>;
Expand Down Expand Up @@ -570,6 +571,7 @@ type GetSectionsParams = {
translate: LocalizedTranslate;
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'];
bankAccountList: OnyxEntry<OnyxTypes.BankAccountList>;
convertToDisplayString: CurrencyListActionsContextType['convertToDisplayString'];
groupBy?: SearchGroupBy;
reportActions?: Record<string, OnyxTypes.ReportAction[]>;
currentSearch?: SearchKey;
Expand Down Expand Up @@ -1565,7 +1567,12 @@ function shouldShowYear(
* @private
* Generates a display name for IOU reports considering the personal details of the payer and the transaction details.
*/
function getIOUReportName(translate: LocalizedTranslate, data: OnyxTypes.SearchResults['data'], reportItem: TransactionReportGroupListItemType) {
function getIOUReportName(
translate: LocalizedTranslate,
convertToDisplayString: CurrencyListActionsContextType['convertToDisplayString'],
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.
Expand Down Expand Up @@ -2606,6 +2613,7 @@ function getReportSections({
allReportMetadata,
queryJSON,
onyxPersonalDetailsList,
convertToDisplayString,
}: GetReportSectionsParams): [TransactionGroupListItemType[], number, boolean] {
const {
transactionKeys,
Expand Down Expand Up @@ -2740,7 +2748,7 @@ function getReportSections({
};

if (isIOUReport) {
reportIDToTransactions[reportKey].reportName = getIOUReportName(translate, data, reportIDToTransactions[reportKey]);
reportIDToTransactions[reportKey].reportName = getIOUReportName(translate, convertToDisplayString, data, reportIDToTransactions[reportKey]);
}
}
} else if (isTransactionEntry(key)) {
Expand Down Expand Up @@ -3391,6 +3399,7 @@ function getSections({
conciergeReportID,
onyxPersonalDetailsList,
policyForMovingExpenses,
convertToDisplayString,
}: GetSectionsParams): GetSectionsResult {
if (type === CONST.SEARCH.DATA_TYPES.CHAT) {
return [...getReportActionsSections(data, visibleReportActionsData), false];
Expand All @@ -3416,6 +3425,7 @@ function getSections({
allReportMetadata,
queryJSON,
onyxPersonalDetailsList,
convertToDisplayString,
});
}

Expand Down
4 changes: 3 additions & 1 deletion src/libs/TransactionPreviewUtils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import truncate from 'lodash/truncate';
import type {OnyxEntry} from 'react-native-onyx';
import type {CurrencyListActionsContextType} from '@hooks/useCurrencyList';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ROUTES from '@src/ROUTES';
import type * as OnyxTypes from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import {setReviewDuplicatesKey} from './actions/Transaction';
import {isCategoryMissing} from './CategoryUtils';
import {convertToDisplayString} from './CurrencyUtils';
import DateUtils from './DateUtils';
import {hasDynamicExternalWorkflow} from './PolicyUtils';
import {getMostRecentActiveDEWSubmitFailedAction, getOriginalMessage, isDynamicExternalWorkflowSubmitFailedAction, isMessageDeleted, isMoneyRequestAction} from './ReportActionsUtils';
Expand Down Expand Up @@ -211,6 +211,7 @@ function getTransactionPreviewTextAndTranslationPaths({
currentUserEmail,
currentUserAccountID,
originalTransaction,
convertToDisplayString,
}: {
iouReport: OnyxEntry<OnyxTypes.Report>;
policy: OnyxEntry<OnyxTypes.Policy>;
Expand All @@ -225,6 +226,7 @@ function getTransactionPreviewTextAndTranslationPaths({
currentUserEmail: string;
currentUserAccountID: number;
originalTransaction?: OnyxEntry<OnyxTypes.Transaction>;
convertToDisplayString: CurrencyListActionsContextType['convertToDisplayString'];
}) {
const isFetchingWaypoints = isFetchingWaypointsFromServer(transaction);
const isTransactionOnHold = isOnHold(transaction);
Expand Down
9 changes: 7 additions & 2 deletions src/libs/actions/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {LocalizedTranslate} from '@components/LocaleContextProvider';
import type {PopoverMenuItem} from '@components/PopoverMenu';
import type {TransactionListItemType, TransactionReportGroupListItemType} from '@components/Search/SearchList/ListItem/types';
import type {BankAccountMenuItem, BulkPaySelectionData, PaymentData, SearchQueryJSON, SelectedReports, SelectedTransactionInfo, SelectedTransactions} from '@components/Search/types';
import type {CurrencyListActionsContextType} from '@hooks/useCurrencyList';
import * as API from '@libs/API';
import {waitForWrites} from '@libs/API';
import type {
Expand All @@ -20,7 +21,6 @@ import type {
} from '@libs/API/parameters';
import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
import {getCommandURL} from '@libs/ApiUtils';
import {convertToDisplayString} from '@libs/CurrencyUtils';
import {getMicroSecondOnyxErrorWithTranslationKey} from '@libs/ErrorUtils';
import fileDownload from '@libs/fileDownload';
import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute';
Expand Down Expand Up @@ -1458,7 +1458,12 @@ function getPayMoneyOnSearchInvoiceParams(policyID: string | undefined, payAsBus
/**
* Return the total amount of selected transactions/reports.
*/
function getTotalFormattedAmount(selectedReports: SelectedReports[], selectedTransactions: SelectedTransactions, currency?: string): string {
function getTotalFormattedAmount(
convertToDisplayString: CurrencyListActionsContextType['convertToDisplayString'],
selectedReports: SelectedReports[],
selectedTransactions: SelectedTransactions,
currency?: string,
): string {
const transactionKeys = Object.keys(selectedTransactions ?? {});
const totalAmount =
selectedReports.length > 0
Expand Down
3 changes: 3 additions & 0 deletions src/pages/home/SpendOverTimeSection/useSpendOverTimeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {useEffect, useEffectEvent} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import type {GroupedItem, SearchQueryJSON} from '@components/Search/types';
import {useCurrencyListActions} from '@hooks/useCurrencyList';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
Expand Down Expand Up @@ -52,6 +53,7 @@ function useSpendOverTimeData() {
const {groupBy, view} = queryJSON ?? {};

const {translate, localeCompare, formatPhoneNumber} = useLocalize();
const {convertToDisplayString} = useCurrencyListActions();
const {accountID, login} = useCurrentUserPersonalDetails();
const [searchResults] = useOnyx(`${ONYXKEYS.COLLECTION.SNAPSHOT}${queryJSON?.hash}`);
const isSearchLoading = !!searchResults?.search?.isLoading;
Expand Down Expand Up @@ -98,6 +100,7 @@ function useSpendOverTimeData() {
bankAccountList: undefined,
allReportMetadata: undefined,
conciergeReportID: undefined,
convertToDisplayString,
})[0],
localeCompare,
translate,
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/MoneyRequestReportPreview.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {act, fireEvent, render, screen} from '@testing-library/react-native';
import type {OnyxCollection, OnyxEntry, OnyxMergeInput} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import ComposeProviders from '@components/ComposeProviders';
import {CurrencyListContextProvider} from '@components/CurrencyListContextProvider';
import {LocaleContextProvider} from '@components/LocaleContextProvider';
import OnyxListItemProvider from '@components/OnyxListItemProvider';
import OptionsListContextProvider from '@components/OptionListContextProvider';
Expand Down Expand Up @@ -81,7 +82,7 @@ const hasViolations = (

const renderPage = ({isWhisper = false, isHovered = false, contextMenuAnchor = null}: Partial<MoneyRequestReportPreviewProps>) => {
return render(
<ComposeProviders components={[OnyxListItemProvider, LocaleContextProvider]}>
<ComposeProviders components={[OnyxListItemProvider, LocaleContextProvider, CurrencyListContextProvider]}>
<OptionsListContextProvider>
<ScreenWrapper testID="test">
<PortalProvider>
Expand Down
Loading
Loading