Skip to content

Commit 13da2f9

Browse files
authored
Merge pull request Expensify#81871 from callstack-internal/personal-card-for-search
Personal card for search
2 parents 6910a73 + fa2c1af commit 13da2f9

23 files changed

Lines changed: 232 additions & 29 deletions

src/ONYXKEYS.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,7 @@ const ONYXKEYS = {
10221022
REPORT_TRANSACTIONS_AND_VIOLATIONS: 'reportTransactionsAndViolations',
10231023
OUTSTANDING_REPORTS_BY_POLICY_ID: 'outstandingReportsByPolicyID',
10241024
NON_PERSONAL_AND_WORKSPACE_CARD_LIST: 'nonPersonalAndWorkspaceCardList',
1025+
PERSONAL_AND_WORKSPACE_CARD_LIST: 'personalAndWorkspaceCardList',
10251026
CARD_FEED_ERRORS: 'cardFeedErrors',
10261027
TODOS: 'todos',
10271028
},
@@ -1445,6 +1446,7 @@ type OnyxDerivedValuesMapping = {
14451446
[ONYXKEYS.DERIVED.REPORT_TRANSACTIONS_AND_VIOLATIONS]: OnyxTypes.ReportTransactionsAndViolationsDerivedValue;
14461447
[ONYXKEYS.DERIVED.OUTSTANDING_REPORTS_BY_POLICY_ID]: OnyxTypes.OutstandingReportsByPolicyIDDerivedValue;
14471448
[ONYXKEYS.DERIVED.NON_PERSONAL_AND_WORKSPACE_CARD_LIST]: OnyxTypes.NonPersonalAndWorkspaceCardListDerivedValue;
1449+
[ONYXKEYS.DERIVED.PERSONAL_AND_WORKSPACE_CARD_LIST]: OnyxTypes.PersonalAndWorkspaceCardListDerivedValue;
14481450
[ONYXKEYS.DERIVED.CARD_FEED_ERRORS]: OnyxTypes.CardFeedErrorsDerivedValue;
14491451
[ONYXKEYS.DERIVED.TODOS]: OnyxTypes.TodosDerivedValue;
14501452
};

src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function MoneyRequestReportNavigation({reportID, shouldDisplayNarrowVersion}: Mo
3737
const [cardFeeds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER, {canBeMissing: true});
3838
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true});
3939
const [allReportMetadata] = useOnyx(ONYXKEYS.COLLECTION.REPORT_METADATA, {canBeMissing: true});
40+
const [cardList] = useOnyx(ONYXKEYS.CARD_LIST, {canBeMissing: true});
4041

4142
const archivedReportsIdSet = useArchivedReportsIdSet();
4243

@@ -58,6 +59,7 @@ function MoneyRequestReportNavigation({reportID, shouldDisplayNarrowVersion}: Mo
5859
isActionLoadingSet,
5960
cardFeeds,
6061
allReportMetadata,
62+
cardList,
6163
});
6264
results = getSortedSections(type, status ?? '', searchData, localeCompare, translate, sortBy, sortOrder, groupBy).map((value) => value.reportID);
6365
}

src/components/Search/SearchPageHeader/SearchFiltersBar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function SearchFiltersBar({
117117
const {getCurrencySymbol} = useCurrencyListActions();
118118

119119
const [email] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: true, selector: emailSelector});
120-
const [nonPersonalAndWorkspaceCards] = useOnyx(ONYXKEYS.DERIVED.NON_PERSONAL_AND_WORKSPACE_CARD_LIST, {canBeMissing: true});
120+
const [personalAndWorkspaceCards] = useOnyx(ONYXKEYS.DERIVED.PERSONAL_AND_WORKSPACE_CARD_LIST, {canBeMissing: true});
121121
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true});
122122
const [hasMultipleOutputCurrency] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {selector: hasMultipleOutputCurrenciesSelector, canBeMissing: true});
123123
const [allFeeds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER, {canBeMissing: true});
@@ -204,10 +204,10 @@ function SearchFiltersBar({
204204

205205
const [feedOptions, feed] = useMemo(() => {
206206
const feedFilterValues = flatFilters.find((filter) => filter.key === CONST.SEARCH.SYNTAX_FILTER_KEYS.FEED)?.filters?.map((filter) => filter.value);
207-
const options = getFeedOptions(allFeeds, nonPersonalAndWorkspaceCards, translate, feedKeysWithCards);
207+
const options = getFeedOptions(allFeeds, personalAndWorkspaceCards, translate, feedKeysWithCards);
208208
const value = feedFilterValues ? options.filter((option) => feedFilterValues.includes(option.value)) : [];
209209
return [options, value];
210-
}, [flatFilters, allFeeds, nonPersonalAndWorkspaceCards, translate, feedKeysWithCards]);
210+
}, [flatFilters, allFeeds, personalAndWorkspaceCards, translate, feedKeysWithCards]);
211211

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

src/components/Search/SearchPageHeader/SearchPageHeaderInput.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function SearchPageHeaderInput({queryJSON, searchRouterListVisible, hideSearchRo
6565
const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: true});
6666
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: false});
6767
const taxRates = useMemo(() => getAllTaxRates(policies), [policies]);
68-
const [nonPersonalAndWorkspaceCards] = useOnyx(ONYXKEYS.DERIVED.NON_PERSONAL_AND_WORKSPACE_CARD_LIST, {canBeMissing: true});
68+
const [personalAndWorkspaceCards] = useOnyx(ONYXKEYS.DERIVED.PERSONAL_AND_WORKSPACE_CARD_LIST, {canBeMissing: true});
6969
const [allFeeds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER, {canBeMissing: true});
7070
const [feedKeysWithCards] = useOnyx(ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST, {selector: feedKeysWithAssignedCardsSelector, canBeMissing: true});
7171
const {inputQuery: originalInputQuery} = queryJSON;
@@ -75,7 +75,7 @@ function SearchPageHeaderInput({queryJSON, searchRouterListVisible, hideSearchRo
7575
PersonalDetails: personalDetails,
7676
reports,
7777
taxRates,
78-
cardList: nonPersonalAndWorkspaceCards,
78+
cardList: personalAndWorkspaceCards,
7979
cardFeeds: allFeeds,
8080
policies,
8181
currentUserAccountID,
@@ -134,14 +134,14 @@ function SearchPageHeaderInput({queryJSON, searchRouterListVisible, hideSearchRo
134134
personalDetails,
135135
reports,
136136
taxRates,
137-
nonPersonalAndWorkspaceCards,
137+
personalAndWorkspaceCards,
138138
allFeeds,
139139
policies,
140140
currentUserAccountID,
141141
translate,
142142
);
143143
setAutocompleteSubstitutions(substitutionsMap);
144-
}, [allFeeds, nonPersonalAndWorkspaceCards, originalInputQuery, personalDetails, reports, taxRates, policies, currentUserAccountID, translate]);
144+
}, [allFeeds, personalAndWorkspaceCards, originalInputQuery, personalDetails, reports, taxRates, policies, currentUserAccountID, translate]);
145145

146146
useEffect(() => {
147147
if (searchRouterListVisible) {
@@ -404,7 +404,7 @@ function SearchPageHeaderInput({queryJSON, searchRouterListVisible, hideSearchRo
404404
ref={listRef}
405405
personalDetails={personalDetails}
406406
reports={reports}
407-
allCards={nonPersonalAndWorkspaceCards}
407+
allCards={personalAndWorkspaceCards}
408408
allFeeds={allFeeds}
409409
textInputRef={textInputRef}
410410
/>
@@ -476,7 +476,7 @@ function SearchPageHeaderInput({queryJSON, searchRouterListVisible, hideSearchRo
476476
shouldSubscribeToArrowKeyEvents={isAutocompleteListVisible}
477477
personalDetails={personalDetails}
478478
reports={reports}
479-
allCards={nonPersonalAndWorkspaceCards}
479+
allCards={personalAndWorkspaceCards}
480480
allFeeds={allFeeds}
481481
textInputRef={textInputRef}
482482
/>

src/components/Search/SearchRouter/SearchRouter.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla
7373
const personalDetails = usePersonalDetails();
7474
const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: true});
7575
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true});
76-
const [nonPersonalAndWorkspaceCards] = useOnyx(ONYXKEYS.DERIVED.NON_PERSONAL_AND_WORKSPACE_CARD_LIST, {canBeMissing: true});
76+
const [personalAndWorkspaceCards] = useOnyx(ONYXKEYS.DERIVED.PERSONAL_AND_WORKSPACE_CARD_LIST, {canBeMissing: true});
7777
const [allFeeds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER, {canBeMissing: true});
7878
const privateIsArchivedMap = usePrivateIsArchivedMap();
7979
const {shouldUseNarrowLayout} = useResponsiveLayout();
@@ -497,7 +497,7 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla
497497
personalDetails={personalDetails}
498498
reports={reports}
499499
allFeeds={allFeeds}
500-
allCards={nonPersonalAndWorkspaceCards}
500+
allCards={personalAndWorkspaceCards}
501501
textInputRef={textInputRef}
502502
/>
503503
)}

src/components/Search/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ function Search({
269269
const [allReportMetadata] = useOnyx(ONYXKEYS.COLLECTION.REPORT_METADATA, {canBeMissing: true});
270270
const [visibleColumns] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM, {canBeMissing: true, selector: columnsSelector});
271271
const [customCardNames] = useOnyx(ONYXKEYS.NVP_EXPENSIFY_COMPANY_CARDS_CUSTOM_NAMES, {canBeMissing: true});
272+
const [cardList] = useOnyx(ONYXKEYS.CARD_LIST, {canBeMissing: true});
272273

273274
const isExpenseReportType = type === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT;
274275
const {markReportIDAsMultiTransactionExpense, unmarkReportIDAsMultiTransactionExpense} = useWideRHPActions();
@@ -451,6 +452,7 @@ function Search({
451452
allTransactionViolations: violations,
452453
customCardNames,
453454
allReportMetadata,
455+
cardList,
454456
});
455457
return [filteredData1, filteredData1.length, allLength];
456458
}, [
@@ -474,6 +476,7 @@ function Search({
474476
violations,
475477
customCardNames,
476478
allReportMetadata,
479+
cardList,
477480
]);
478481

479482
// For group-by views, each grouped item has a transactionsQueryJSON with a hash pointing to a separate snapshot
@@ -511,6 +514,7 @@ function Search({
511514
isActionLoadingSet,
512515
cardFeeds,
513516
allReportMetadata,
517+
cardList,
514518
});
515519
return {...item, transactions: transactions1 as TransactionListItemType[]};
516520
});
@@ -529,6 +533,7 @@ function Search({
529533
cardFeeds,
530534
bankAccountList,
531535
allReportMetadata,
536+
cardList,
532537
]);
533538

534539
const hasLoadedAllTransactions = useMemo(() => {

src/components/SelectionListWithSections/Search/TransactionGroupListItem.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ function TransactionGroupListItem<TItem extends ListItem>({
116116
const [allReportMetadata] = useOnyx(ONYXKEYS.COLLECTION.REPORT_METADATA, {canBeMissing: true});
117117
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true});
118118
const [cardFeeds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER, {canBeMissing: true});
119+
const [cardList] = useOnyx(ONYXKEYS.CARD_LIST, {canBeMissing: true});
119120

120121
const transactions = useMemo(() => {
121122
if (isExpenseReportType) {
@@ -135,6 +136,7 @@ function TransactionGroupListItem<TItem extends ListItem>({
135136
isActionLoadingSet,
136137
allReportMetadata,
137138
cardFeeds,
139+
cardList,
138140
}) as [TransactionListItemType[], number];
139141
return sectionData.map((transactionItem) => ({
140142
...transactionItem,
@@ -153,6 +155,7 @@ function TransactionGroupListItem<TItem extends ListItem>({
153155
bankAccountList,
154156
allReportMetadata,
155157
cardFeeds,
158+
cardList,
156159
]);
157160

158161
const selectedItemsLength = useMemo(() => {

src/hooks/useAdvancedSearchFilters.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ function useAdvancedSearchFilters() {
207207
const {localeCompare} = useLocalize();
208208
const [searchAdvancedFilters = getEmptyObject<SearchAdvancedFiltersForm>()] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM, {canBeMissing: true});
209209
const policyID = searchAdvancedFilters.policyID;
210-
const [searchCards] = useOnyx(ONYXKEYS.DERIVED.NON_PERSONAL_AND_WORKSPACE_CARD_LIST, {canBeMissing: true, selector: filterCardsHiddenFromSearch});
210+
const [searchCards] = useOnyx(ONYXKEYS.DERIVED.PERSONAL_AND_WORKSPACE_CARD_LIST, {canBeMissing: true, selector: filterCardsHiddenFromSearch});
211211
const [policies = getEmptyObject<NonNullable<OnyxCollection<Policy>>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: false});
212212
const [allPolicyCategories = getEmptyObject<NonNullable<OnyxCollection<PolicyCategories>>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY_CATEGORIES, {
213213
canBeMissing: false,
@@ -243,14 +243,11 @@ function useAdvancedSearchFilters() {
243243

244244
const areCategoriesEnabled = isFeatureEnabledInPolicies(policies, CONST.POLICY.MORE_FEATURES.ARE_CATEGORIES_ENABLED);
245245
const areTagsEnabled = isFeatureEnabledInPolicies(policies, CONST.POLICY.MORE_FEATURES.ARE_TAGS_ENABLED);
246-
const areCardsEnabled =
247-
isFeatureEnabledInPolicies(policies, CONST.POLICY.MORE_FEATURES.ARE_COMPANY_CARDS_ENABLED) ||
248-
isFeatureEnabledInPolicies(policies, CONST.POLICY.MORE_FEATURES.ARE_EXPENSIFY_CARDS_ENABLED);
249246
const areTaxEnabled = isFeatureEnabledInPolicies(policies, CONST.POLICY.MORE_FEATURES.ARE_TAXES_ENABLED);
250247
const shouldDisplayAttendeeFilter = isFeatureEnabledInPolicies(policies, CONST.POLICY.MORE_FEATURES.IS_ATTENDEE_TRACKING_ENABLED);
251248
const shouldDisplayCategoryFilter = shouldDisplayFilter(nonPersonalPolicyCategoryCount, areCategoriesEnabled, selectedPolicyCategories?.length > 0);
252249
const shouldDisplayTagFilter = shouldDisplayFilter(tagListsUnpacked.length, areTagsEnabled, !!selectedPolicyTagLists);
253-
const shouldDisplayCardFilter = shouldDisplayFilter(Object.keys(searchCards ?? {}).length, areCardsEnabled);
250+
const shouldDisplayCardFilter = shouldDisplayFilter(Object.keys(searchCards ?? {}).length, true);
254251
const shouldDisplayTaxFilter = shouldDisplayFilter(Object.keys(taxRates).length, areTaxEnabled);
255252
const shouldDisplayWorkspaceFilter = workspaces.some((section) => section.data.length > 1);
256253
const shouldDisplayGroupCurrencyFilter = !!searchAdvancedFilters.groupBy;

src/hooks/useSearchTypeMenu.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default function useSearchTypeMenu(queryJSON: SearchQueryJSON) {
4646
const personalDetails = usePersonalDetails();
4747
const [reports = getEmptyObject<NonNullable<OnyxCollection<Report>>>()] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: true});
4848
const taxRates = getAllTaxRates(allPolicies);
49-
const [nonPersonalAndWorkspaceCards] = useOnyx(ONYXKEYS.DERIVED.NON_PERSONAL_AND_WORKSPACE_CARD_LIST, {canBeMissing: true});
49+
const [personalAndWorkspaceCards] = useOnyx(ONYXKEYS.DERIVED.PERSONAL_AND_WORKSPACE_CARD_LIST, {canBeMissing: true});
5050
const [savedSearches] = useOnyx(ONYXKEYS.SAVED_SEARCHES, {canBeMissing: true});
5151
const [currentUserAccountID = -1] = useOnyx(ONYXKEYS.SESSION, {selector: accountIDSelector, canBeMissing: false});
5252
const expensifyIcons = useMemoizedLazyExpensifyIcons([
@@ -117,7 +117,7 @@ export default function useSearchTypeMenu(queryJSON: SearchQueryJSON) {
117117
PersonalDetails: personalDetails,
118118
reports,
119119
taxRates,
120-
cardList: nonPersonalAndWorkspaceCards,
120+
cardList: personalAndWorkspaceCards,
121121
cardFeeds: allFeeds,
122122
policies: allPolicies,
123123
currentUserAccountID,
@@ -171,7 +171,7 @@ export default function useSearchTypeMenu(queryJSON: SearchQueryJSON) {
171171
personalDetails,
172172
reports,
173173
taxRates,
174-
nonPersonalAndWorkspaceCards,
174+
personalAndWorkspaceCards,
175175
allFeeds,
176176
feedKeysWithCards,
177177
allPolicies,

src/libs/CardFeedUtils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ function createCardFilterItem(
100100
const cardName = card?.nameValuePairs?.cardTitle;
101101
const text = personalDetails?.displayName ?? cardName;
102102
const plaidUrl = getPlaidInstitutionIconUrl(card?.bank);
103+
const isCSVImportCard = card?.bank === CONST.PERSONAL_CARD.BANK_NAME.CSV;
103104

104105
return {
105-
lastFourPAN: card.lastFourPAN,
106+
lastFourPAN: isCSVImportCard ? card?.cardName : card.lastFourPAN,
106107
isVirtual: card?.nameValuePairs?.isVirtual,
107108
shouldShowOwnersAvatar: true,
108109
cardName,

0 commit comments

Comments
 (0)