Skip to content

Commit 72fb462

Browse files
authored
Merge pull request Expensify#79679 from parasharrajat/translate/cardFeedUtils
Remove TranslateLocal from CardFeedutils
2 parents 4e3dcaf + e881323 commit 72fb462

16 files changed

Lines changed: 263 additions & 74 deletions

src/components/Search/SearchAutocompleteList.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ function SearchAutocompleteList({
303303
const feedAutoCompleteList = useMemo(() => {
304304
// We don't want to show the "Expensify Card" feeds in the autocomplete suggestion list as they don't have real "Statements"
305305
// Thus passing an empty object to the `allCards` parameter.
306-
return Object.values(getCardFeedsForDisplay(allFeeds, {}));
307-
}, [allFeeds]);
306+
return Object.values(getCardFeedsForDisplay(allFeeds, {}, translate));
307+
}, [allFeeds, translate]);
308308

309309
const [allPolicyCategories] = useOnyx(ONYXKEYS.COLLECTION.POLICY_CATEGORIES, {canBeMissing: false});
310310
const [allRecentCategories] = useOnyx(ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES, {canBeMissing: true});
@@ -682,7 +682,20 @@ function SearchAutocompleteList({
682682
const recentSearchesData = sortedRecentSearches?.slice(0, 5).map(({query, timestamp}) => {
683683
const searchQueryJSON = buildSearchQueryJSON(query);
684684
return {
685-
text: searchQueryJSON ? buildUserReadableQueryString(searchQueryJSON, personalDetails, reports, taxRates, allCards, allFeeds, policies, currentUserAccountID) : query,
685+
text: searchQueryJSON
686+
? buildUserReadableQueryString({
687+
queryJSON: searchQueryJSON,
688+
PersonalDetails: personalDetails,
689+
reports,
690+
taxRates,
691+
cardList: allCards,
692+
cardFeeds: allFeeds,
693+
policies,
694+
currentUserAccountID,
695+
autoCompleteWithSpace: false,
696+
translate,
697+
})
698+
: query,
686699
singleIcon: expensifyIcons.History,
687700
searchQuery: query,
688701
keyForList: timestamp,

src/components/Search/SearchPageHeader/SearchFiltersBar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,10 @@ function SearchFiltersBar({
212212

213213
const [feedOptions, feed] = useMemo(() => {
214214
const feedFilterValues = flatFilters.find((filter) => filter.key === CONST.SEARCH.SYNTAX_FILTER_KEYS.FEED)?.filters?.map((filter) => filter.value);
215-
const options = getFeedOptions(allFeeds, nonPersonalAndWorkspaceCards);
215+
const options = getFeedOptions(allFeeds, nonPersonalAndWorkspaceCards, translate);
216216
const value = feedFilterValues ? options.filter((option) => feedFilterValues.includes(option.value)) : [];
217217
return [options, value];
218-
}, [flatFilters, allFeeds, nonPersonalAndWorkspaceCards]);
218+
}, [flatFilters, allFeeds, nonPersonalAndWorkspaceCards, translate]);
219219

220220
const [statusOptions, status] = useMemo(() => {
221221
const options = type ? getStatusOptions(translate, type.value) : [];

src/components/Search/SearchPageHeader/SearchPageHeaderInput.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {isSearchQueryItem} from '@components/SelectionListWithSections/Search/Se
2121
import type {SelectionListHandle} from '@components/SelectionListWithSections/types';
2222
import SidePanelButton from '@components/SidePanel/SidePanelButton';
2323
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
24+
import useLocalize from '@hooks/useLocalize';
2425
import useOnyx from '@hooks/useOnyx';
2526
import useResponsiveLayout from '@hooks/useResponsiveLayout';
2627
import useTheme from '@hooks/useTheme';
@@ -56,6 +57,7 @@ function SearchPageHeaderInput({queryJSON, searchRouterListVisible, hideSearchRo
5657
const [showPopupButton, setShowPopupButton] = useState(true);
5758
const styles = useThemeStyles();
5859
const theme = useTheme();
60+
const {translate} = useLocalize();
5961
const {shouldUseNarrowLayout: displayNarrowHeader} = useResponsiveLayout();
6062
const expensifyIcons = useMemoizedLazyExpensifyIcons(['MagnifyingGlass']);
6163
const personalDetails = usePersonalDetails();
@@ -66,7 +68,18 @@ function SearchPageHeaderInput({queryJSON, searchRouterListVisible, hideSearchRo
6668
const [allFeeds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER, {canBeMissing: true});
6769
const {inputQuery: originalInputQuery} = queryJSON;
6870
const [currentUserAccountID = -1] = useOnyx(ONYXKEYS.SESSION, {selector: accountIDSelector, canBeMissing: false});
69-
const queryText = buildUserReadableQueryString(queryJSON, personalDetails, reports, taxRates, nonPersonalAndWorkspaceCards, allFeeds, policies, currentUserAccountID, true);
71+
const queryText = buildUserReadableQueryString({
72+
queryJSON,
73+
PersonalDetails: personalDetails,
74+
reports,
75+
taxRates,
76+
cardList: nonPersonalAndWorkspaceCards,
77+
cardFeeds: allFeeds,
78+
policies,
79+
currentUserAccountID,
80+
autoCompleteWithSpace: true,
81+
translate,
82+
});
7083

7184
const [searchContext] = useOnyx(ONYXKEYS.SEARCH_CONTEXT, {canBeMissing: true});
7285
const shouldShowQuery = searchContext?.shouldShowSearchQuery ?? false;
@@ -113,9 +126,19 @@ function SearchPageHeaderInput({queryJSON, searchRouterListVisible, hideSearchRo
113126
}, [queryText, shouldShowQuery]);
114127

115128
useEffect(() => {
116-
const substitutionsMap = buildSubstitutionsMap(originalInputQuery, personalDetails, reports, taxRates, nonPersonalAndWorkspaceCards, allFeeds, policies, currentUserAccountID);
129+
const substitutionsMap = buildSubstitutionsMap(
130+
originalInputQuery,
131+
personalDetails,
132+
reports,
133+
taxRates,
134+
nonPersonalAndWorkspaceCards,
135+
allFeeds,
136+
policies,
137+
currentUserAccountID,
138+
translate,
139+
);
117140
setAutocompleteSubstitutions(substitutionsMap);
118-
}, [allFeeds, nonPersonalAndWorkspaceCards, originalInputQuery, personalDetails, reports, taxRates, policies, currentUserAccountID]);
141+
}, [allFeeds, nonPersonalAndWorkspaceCards, originalInputQuery, personalDetails, reports, taxRates, policies, currentUserAccountID, translate]);
119142

120143
useEffect(() => {
121144
if (searchRouterListVisible) {

src/components/Search/SearchRouter/buildSubstitutionsMap.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {OnyxCollection} from 'react-native-onyx';
2+
import type {LocalizedTranslate} from '@components/LocaleContextProvider';
23
import type {SearchAutocompleteQueryRange, SearchFilterKey} from '@components/Search/types';
34
import {parse} from '@libs/SearchParser/autocompleteParser';
45
import {getFilterDisplayValue} from '@libs/SearchQueryUtils';
@@ -33,6 +34,7 @@ function buildSubstitutionsMap(
3334
cardFeeds: OnyxCollection<CardFeeds>,
3435
policies: OnyxCollection<Policy>,
3536
currentUserAccountID: number,
37+
translate: LocalizedTranslate,
3638
): SubstitutionMap {
3739
const parsedQuery = parse(query) as {ranges: SearchAutocompleteQueryRange[]};
3840

@@ -71,7 +73,7 @@ function buildSubstitutionsMap(
7173
filterKey === CONST.SEARCH.SYNTAX_FILTER_KEYS.PAYER ||
7274
filterKey === CONST.SEARCH.SYNTAX_FILTER_KEYS.ATTENDEE
7375
) {
74-
const displayValue = getFilterDisplayValue(filterKey, filterValue, personalDetails, reports, cardList, cardFeeds, policies, currentUserAccountID);
76+
const displayValue = getFilterDisplayValue(filterKey, filterValue, personalDetails, reports, cardList, cardFeeds, policies, currentUserAccountID, translate);
7577

7678
// If displayValue === filterValue, then it means there is nothing to substitute, so we don't add any key to map
7779
if (displayValue !== filterValue) {

src/hooks/useCardFeedsForDisplay.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ const eligiblePoliciesSelector = (policies: OnyxCollection<Policy>) => {
1717
};
1818

1919
const useCardFeedsForDisplay = () => {
20-
const {localeCompare} = useLocalize();
20+
const {localeCompare, translate} = useLocalize();
2121
const [allFeeds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER, {canBeMissing: true});
2222
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: true});
2323
const [eligiblePoliciesIDs] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {
2424
selector: eligiblePoliciesSelector,
2525
canBeMissing: true,
2626
});
2727

28-
const cardFeedsByPolicy = getCardFeedsForDisplayPerPolicy(allFeeds);
28+
const cardFeedsByPolicy = getCardFeedsForDisplayPerPolicy(allFeeds, translate);
2929

3030
let defaultCardFeed;
3131
if (eligiblePoliciesIDs) {

src/hooks/useSearchTypeMenu.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,18 @@ export default function useSearchTypeMenu(queryJSON: SearchQueryJSON) {
109109

110110
if (savedSearchTitle === item.query) {
111111
const jsonQuery = buildSearchQueryJSON(item.query) ?? ({} as SearchQueryJSON);
112-
savedSearchTitle = buildUserReadableQueryString(jsonQuery, personalDetails, reports, taxRates, nonPersonalAndWorkspaceCards, allFeeds, allPolicies, currentUserAccountID);
112+
savedSearchTitle = buildUserReadableQueryString({
113+
queryJSON: jsonQuery,
114+
PersonalDetails: personalDetails,
115+
reports,
116+
taxRates,
117+
cardList: nonPersonalAndWorkspaceCards,
118+
cardFeeds: allFeeds,
119+
policies: allPolicies,
120+
currentUserAccountID,
121+
autoCompleteWithSpace: false,
122+
translate,
123+
});
113124
}
114125

115126
const isItemFocused = Number(key) === hash;
@@ -148,7 +159,20 @@ export default function useSearchTypeMenu(queryJSON: SearchQueryJSON) {
148159
savedSearchesMenuItems: menuItems,
149160
isSavedSearchActive: savedSearchFocused,
150161
};
151-
}, [savedSearches, hash, getOverflowMenu, expensifyIcons.Bookmark, personalDetails, reports, taxRates, nonPersonalAndWorkspaceCards, allFeeds, allPolicies, currentUserAccountID]);
162+
}, [
163+
savedSearches,
164+
hash,
165+
getOverflowMenu,
166+
expensifyIcons.Bookmark,
167+
personalDetails,
168+
reports,
169+
taxRates,
170+
nonPersonalAndWorkspaceCards,
171+
allFeeds,
172+
allPolicies,
173+
currentUserAccountID,
174+
translate,
175+
]);
152176

153177
const activeItemIndex = useMemo(() => {
154178
// If we have a suggested search, then none of the menu items are active

src/hooks/useSearchTypeMenuSections.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
55
import {areAllGroupPoliciesExpenseChatDisabled} from '@libs/PolicyUtils';
66
import {createTypeMenuSections} from '@libs/SearchUIUtils';
77
import ONYXKEYS from '@src/ONYXKEYS';
8-
import type {Policy, Session} from '@src/types/onyx';
8+
import type {NonPersonalAndWorkspaceCardListDerivedValue, Policy, Session} from '@src/types/onyx';
99
import useCardFeedsForDisplay from './useCardFeedsForDisplay';
1010
import useCreateEmptyReportConfirmation from './useCreateEmptyReportConfirmation';
1111
import {useMemoizedLazyExpensifyIcons} from './useLazyAsset';
12+
import useLocalize from './useLocalize';
1213
import useNetwork from './useNetwork';
1314
import useOnyx from './useOnyx';
1415
import useTodos from './useTodos';
@@ -47,7 +48,9 @@ const currentUserLoginAndAccountIDSelector = (session: OnyxEntry<Session>) => ({
4748
* currently focused search, based on the hash
4849
*/
4950
const useSearchTypeMenuSections = () => {
50-
const [defaultExpensifyCard] = useOnyx(ONYXKEYS.DERIVED.NON_PERSONAL_AND_WORKSPACE_CARD_LIST, {canBeMissing: true, selector: defaultExpensifyCardSelector});
51+
const {translate} = useLocalize();
52+
const cardSelector = (allCards: OnyxEntry<NonPersonalAndWorkspaceCardListDerivedValue>) => defaultExpensifyCardSelector(allCards, translate);
53+
const [defaultExpensifyCard] = useOnyx(ONYXKEYS.DERIVED.NON_PERSONAL_AND_WORKSPACE_CARD_LIST, {canBeMissing: true, selector: cardSelector}, [cardSelector]);
5154

5255
const {defaultCardFeed, cardFeedsByPolicy} = useCardFeedsForDisplay();
5356

src/libs/CardFeedUtils.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {OnyxCollection} from 'react-native-onyx';
2-
import type {LocaleContextProps} from '@components/LocaleContextProvider';
2+
import type {LocaleContextProps, LocalizedTranslate} from '@components/LocaleContextProvider';
33
import type {AdditionalCardProps} from '@components/SelectionListWithSections/Search/CardListItem';
44
import type IllustrationsType from '@styles/theme/illustrations/types';
55
import CONST from '@src/CONST';
@@ -21,8 +21,6 @@ import {
2121
isCardHiddenFromSearch,
2222
} from './CardUtils';
2323
import type {CompanyCardFeedIcons} from './CardUtils';
24-
// eslint-disable-next-line @typescript-eslint/no-deprecated
25-
import {translateLocal} from './Localize';
2624
import {getDescriptionForPolicyDomainCard, getPolicy} from './PolicyUtils';
2725
import type {OptionData} from './ReportUtils';
2826

@@ -432,7 +430,7 @@ const generateSelectedCards = (
432430
*
433431
* The `allCards` parameter is only used to determine if we should add the "Expensify Card" feeds.
434432
*/
435-
function getCardFeedsForDisplay(allCardFeeds: OnyxCollection<CardFeeds>, allCards: CardList | undefined): CardFeedsForDisplay {
433+
function getCardFeedsForDisplay(allCardFeeds: OnyxCollection<CardFeeds>, allCards: CardList | undefined, translate: LocalizedTranslate): CardFeedsForDisplay {
436434
const cardFeedsForDisplay = {} as CardFeedsForDisplay;
437435

438436
for (const [domainKey, cardFeeds] of Object.entries(allCardFeeds ?? {})) {
@@ -454,8 +452,7 @@ function getCardFeedsForDisplay(allCardFeeds: OnyxCollection<CardFeeds>, allCard
454452
id,
455453
feed,
456454
fundID,
457-
// eslint-disable-next-line @typescript-eslint/no-deprecated
458-
name: getCustomOrFormattedFeedName(translateLocal, feed, cardFeeds?.settings?.companyCardNicknames?.[feed], false) ?? feed,
455+
name: getCustomOrFormattedFeedName(translate, feed, cardFeeds?.settings?.companyCardNicknames?.[feed], false) ?? feed,
459456
};
460457
}
461458
}
@@ -487,7 +484,7 @@ function getCardFeedsForDisplay(allCardFeeds: OnyxCollection<CardFeeds>, allCard
487484
*
488485
* Note: "Expensify Card" feeds are not included.
489486
*/
490-
function getCardFeedsForDisplayPerPolicy(allCardFeeds: OnyxCollection<CardFeeds>): Record<string, CardFeedForDisplay[]> {
487+
function getCardFeedsForDisplayPerPolicy(allCardFeeds: OnyxCollection<CardFeeds>, translate: LocalizedTranslate): Record<string, CardFeedForDisplay[]> {
491488
const cardFeedsForDisplayPerPolicy = {} as Record<string, CardFeedForDisplay[]>;
492489

493490
for (const [domainKey, cardFeeds] of Object.entries(allCardFeeds ?? {})) {
@@ -506,8 +503,7 @@ function getCardFeedsForDisplayPerPolicy(allCardFeeds: OnyxCollection<CardFeeds>
506503
id,
507504
feed,
508505
fundID,
509-
// eslint-disable-next-line @typescript-eslint/no-deprecated
510-
name: getCustomOrFormattedFeedName(translateLocal, feed, cardFeeds?.settings?.companyCardNicknames?.[feed], false) ?? feed,
506+
name: getCustomOrFormattedFeedName(translate, feed, cardFeeds?.settings?.companyCardNicknames?.[feed], false) ?? feed,
511507
});
512508
}
513509
}

0 commit comments

Comments
 (0)