Skip to content

Commit cf8b46a

Browse files
authored
Merge pull request Expensify#66948 from allgandalf/fixSearchPage
[Part 5]: Remove usage of Onyx.connect for ONYXKEYS.COUNTRY_CODE
2 parents fb3ca5f + 1ef2856 commit cf8b46a

3 files changed

Lines changed: 32 additions & 20 deletions

File tree

src/components/Search/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
257257
.flatMap((filteredReportActions) => Object.values(filteredReportActions ?? {})),
258258
[reportActions],
259259
);
260-
const {translate, localeCompare} = useLocalize();
260+
const {translate, localeCompare, formatPhoneNumber} = useLocalize();
261261
const searchListRef = useRef<SelectionListHandle | null>(null);
262262

263263
const clearTransactionsAndSetHashAndKey = useCallback(() => {
@@ -359,8 +359,9 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
359359
if (groupBy && (isChat || isTask)) {
360360
return [];
361361
}
362-
return getSections(type, searchResults.data, searchResults.search, groupBy, exportReportActions, searchKey, archivedReportsIdSet);
363-
}, [searchKey, exportReportActions, groupBy, isDataLoaded, searchResults, type, archivedReportsIdSet]);
362+
363+
return getSections(type, searchResults.data, searchResults.search, formatPhoneNumber, groupBy, exportReportActions, searchKey, archivedReportsIdSet);
364+
}, [searchKey, exportReportActions, groupBy, isDataLoaded, searchResults, type, archivedReportsIdSet, formatPhoneNumber]);
364365

365366
useEffect(() => {
366367
/** We only want to display the skeleton for the status filters the first time we load them for a specific data type */

src/libs/SearchUIUtils.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ import {getCardFeedsForDisplay} from './CardFeedUtils';
5151
import {convertToDisplayString} from './CurrencyUtils';
5252
import DateUtils from './DateUtils';
5353
import interceptAnonymousUser from './interceptAnonymousUser';
54-
import {formatPhoneNumber} from './LocalePhoneNumber';
5554
import {translateLocal} from './Localize';
5655
import Navigation from './Navigation/Navigation';
5756
import Parser from './Parser';
@@ -446,6 +445,7 @@ function getTransactionItemCommonFormattedProperties(
446445
from: SearchPersonalDetails,
447446
to: SearchPersonalDetails,
448447
policy: SearchPolicy,
448+
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'],
449449
): Pick<TransactionListItemType, 'formattedFrom' | 'formattedTo' | 'formattedTotal' | 'formattedMerchant' | 'date'> {
450450
const isExpenseReport = transactionItem.reportType === CONST.REPORT.TYPE.EXPENSE;
451451

@@ -729,7 +729,12 @@ function getTransactionViolations(allViolations: OnyxCollection<OnyxTypes.Transa
729729
*
730730
* Do not use directly, use only via `getSections()` facade.
731731
*/
732-
function getTransactionsSections(data: OnyxTypes.SearchResults['data'], metadata: OnyxTypes.SearchResults['search'], currentSearch: SearchKey): TransactionListItemType[] {
732+
function getTransactionsSections(
733+
data: OnyxTypes.SearchResults['data'],
734+
metadata: OnyxTypes.SearchResults['search'],
735+
currentSearch: SearchKey,
736+
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'],
737+
): TransactionListItemType[] {
733738
const shouldShowMerchant = getShouldShowMerchant(data);
734739
const doesDataContainAPastYearTransaction = shouldShowYear(data);
735740
const {shouldShowAmountInWideColumn, shouldShowTaxAmountInWideColumn} = getWideAmountIndicators(data);
@@ -759,7 +764,7 @@ function getTransactionsSections(data: OnyxTypes.SearchResults['data'], metadata
759764
const from = personalDetailsMap.get(transactionItem.accountID.toString()) ?? emptyPersonalDetails;
760765
const to = transactionItem.managerID && !shouldShowBlankTo ? (personalDetailsMap.get(transactionItem.managerID.toString()) ?? emptyPersonalDetails) : emptyPersonalDetails;
761766

762-
const {formattedFrom, formattedTo, formattedTotal, formattedMerchant, date} = getTransactionItemCommonFormattedProperties(transactionItem, from, to, policy);
767+
const {formattedFrom, formattedTo, formattedTotal, formattedMerchant, date} = getTransactionItemCommonFormattedProperties(transactionItem, from, to, policy, formatPhoneNumber);
763768

764769
const transactionSection: TransactionListItemType = {
765770
action: getAction(data, allViolations, key, currentSearch),
@@ -1022,7 +1027,11 @@ function getAction(
10221027
*
10231028
* Do not use directly, use only via `getSections()` facade.
10241029
*/
1025-
function getTaskSections(data: OnyxTypes.SearchResults['data'], archivedReportsIDList?: ArchivedReportsIDSet): TaskListItemType[] {
1030+
function getTaskSections(
1031+
data: OnyxTypes.SearchResults['data'],
1032+
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'],
1033+
archivedReportsIDList?: ArchivedReportsIDSet,
1034+
): TaskListItemType[] {
10261035
return (
10271036
Object.keys(data)
10281037
.filter(isReportEntry)
@@ -1147,6 +1156,7 @@ function getReportSections(
11471156
data: OnyxTypes.SearchResults['data'],
11481157
metadata: OnyxTypes.SearchResults['search'],
11491158
currentSearch: SearchKey,
1159+
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'],
11501160
reportActions: Record<string, OnyxTypes.ReportAction[]> = {},
11511161
): TransactionGroupListItemType[] {
11521162
const shouldShowMerchant = getShouldShowMerchant(data);
@@ -1195,7 +1205,7 @@ function getReportSections(
11951205
const from = data.personalDetailsList?.[transactionItem.accountID];
11961206
const to = transactionItem.managerID && !shouldShowBlankTo ? (data.personalDetailsList?.[transactionItem.managerID] ?? emptyPersonalDetails) : emptyPersonalDetails;
11971207

1198-
const {formattedFrom, formattedTo, formattedTotal, formattedMerchant, date} = getTransactionItemCommonFormattedProperties(transactionItem, from, to, policy);
1208+
const {formattedFrom, formattedTo, formattedTotal, formattedMerchant, date} = getTransactionItemCommonFormattedProperties(transactionItem, from, to, policy, formatPhoneNumber);
11991209

12001210
const transaction = {
12011211
...transactionItem,
@@ -1274,6 +1284,7 @@ function getSections(
12741284
type: SearchDataTypes,
12751285
data: OnyxTypes.SearchResults['data'],
12761286
metadata: OnyxTypes.SearchResults['search'],
1287+
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'],
12771288
groupBy?: SearchGroupBy,
12781289
reportActions: Record<string, OnyxTypes.ReportAction[]> = {},
12791290
currentSearch: SearchKey = CONST.SEARCH.SEARCH_KEYS.EXPENSES,
@@ -1283,23 +1294,23 @@ function getSections(
12831294
return getReportActionsSections(data);
12841295
}
12851296
if (type === CONST.SEARCH.DATA_TYPES.TASK) {
1286-
return getTaskSections(data, archivedReportsIDList);
1297+
return getTaskSections(data, formatPhoneNumber, archivedReportsIDList);
12871298
}
12881299

12891300
if (groupBy) {
12901301
// Disabling the default-case lint rule here is actually safer as this forces us to make the switch cases exhaustive
12911302
// eslint-disable-next-line default-case
12921303
switch (groupBy) {
12931304
case CONST.SEARCH.GROUP_BY.REPORTS:
1294-
return getReportSections(data, metadata, currentSearch, reportActions);
1305+
return getReportSections(data, metadata, currentSearch, formatPhoneNumber, reportActions);
12951306
case CONST.SEARCH.GROUP_BY.MEMBERS:
12961307
return getMemberSections(data, metadata);
12971308
case CONST.SEARCH.GROUP_BY.CARDS:
12981309
return getCardSections(data, metadata);
12991310
}
13001311
}
13011312

1302-
return getTransactionsSections(data, metadata, currentSearch);
1313+
return getTransactionsSections(data, metadata, currentSearch, formatPhoneNumber);
13031314
}
13041315

13051316
/**

tests/unit/Search/SearchUIUtilsTest.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as SearchUIUtils from '@src/libs/SearchUIUtils';
1010
import ONYXKEYS from '@src/ONYXKEYS';
1111
import type * as OnyxTypes from '@src/types/onyx';
1212
import type {SearchDataTypes} from '@src/types/onyx/SearchResults';
13-
import {localeCompare} from '../../utils/TestHelper';
13+
import {formatPhoneNumber, localeCompare} from '../../utils/TestHelper';
1414
import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates';
1515

1616
jest.mock('@src/components/ConfirmedRoute.tsx');
@@ -1298,41 +1298,41 @@ describe('SearchUIUtils', () => {
12981298

12991299
describe('Test getSections', () => {
13001300
it('should return getReportActionsSections result when type is CHAT', () => {
1301-
expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.CHAT, searchResults.data, searchResults.search)).toStrictEqual(reportActionListItems);
1301+
expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.CHAT, searchResults.data, searchResults.search, formatPhoneNumber)).toStrictEqual(reportActionListItems);
13021302
});
13031303

13041304
it('should return getTransactionsSections result when groupBy is undefined', () => {
1305-
expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.EXPENSE, searchResults.data, searchResults.search, undefined)).toStrictEqual(transactionsListItems);
1305+
expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.EXPENSE, searchResults.data, searchResults.search, formatPhoneNumber, undefined)).toStrictEqual(transactionsListItems);
13061306
});
13071307

13081308
it('should return getReportSections result when type is EXPENSE and groupBy is report', () => {
1309-
expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.EXPENSE, searchResults.data, searchResults.search, CONST.SEARCH.GROUP_BY.REPORTS)).toStrictEqual(
1309+
expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.EXPENSE, searchResults.data, searchResults.search, formatPhoneNumber, CONST.SEARCH.GROUP_BY.REPORTS)).toStrictEqual(
13101310
transactionReportGroupListItems,
13111311
);
13121312
});
13131313

13141314
it('should return getReportSections result when type is TRIP and groupBy is report', () => {
1315-
expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.TRIP, searchResults.data, searchResults.search, CONST.SEARCH.GROUP_BY.REPORTS)).toStrictEqual(
1315+
expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.TRIP, searchResults.data, searchResults.search, formatPhoneNumber, CONST.SEARCH.GROUP_BY.REPORTS)).toStrictEqual(
13161316
transactionReportGroupListItems,
13171317
);
13181318
});
13191319

13201320
it('should return getReportSections result when type is INVOICE and groupBy is report', () => {
1321-
expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.INVOICE, searchResults.data, searchResults.search, CONST.SEARCH.GROUP_BY.REPORTS)).toStrictEqual(
1321+
expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.INVOICE, searchResults.data, searchResults.search, formatPhoneNumber, CONST.SEARCH.GROUP_BY.REPORTS)).toStrictEqual(
13221322
transactionReportGroupListItems,
13231323
);
13241324
});
13251325

13261326
it('should return getMemberSections result when type is EXPENSE and groupBy is member', () => {
1327-
expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.EXPENSE, searchResults.data, searchResults.search, CONST.SEARCH.GROUP_BY.MEMBERS)).toStrictEqual([]); // s77rt update test
1327+
expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.EXPENSE, searchResults.data, searchResults.search, formatPhoneNumber, CONST.SEARCH.GROUP_BY.MEMBERS)).toStrictEqual([]); // s77rt update test
13281328
});
13291329

13301330
it('should return getMemberSections result when type is TRIP and groupBy is member', () => {
1331-
expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.TRIP, searchResults.data, searchResults.search, CONST.SEARCH.GROUP_BY.MEMBERS)).toStrictEqual([]); // s77rt update test
1331+
expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.TRIP, searchResults.data, searchResults.search, formatPhoneNumber, CONST.SEARCH.GROUP_BY.MEMBERS)).toStrictEqual([]); // s77rt update test
13321332
});
13331333

13341334
it('should return getMemberSections result when type is INVOICE and groupBy is member', () => {
1335-
expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.INVOICE, searchResults.data, searchResults.search, CONST.SEARCH.GROUP_BY.MEMBERS)).toStrictEqual([]); // s77rt update test
1335+
expect(SearchUIUtils.getSections(CONST.SEARCH.DATA_TYPES.INVOICE, searchResults.data, searchResults.search, formatPhoneNumber, CONST.SEARCH.GROUP_BY.MEMBERS)).toStrictEqual([]); // s77rt update test
13361336
});
13371337

13381338
// s77rt add test for group by card

0 commit comments

Comments
 (0)