Skip to content

Commit 9b5aca3

Browse files
authored
Merge pull request Expensify#68075 from s77rt/withdrawal-type-filter
Search: Withdrawal type filter
2 parents b7d429f + 215d814 commit 9b5aca3

32 files changed

Lines changed: 915 additions & 565 deletions

src/CONST/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6284,6 +6284,10 @@ const CONST = {
62846284
DISTANCE: 'distance',
62856285
PER_DIEM: 'perDiem',
62866286
},
6287+
WITHDRAWAL_TYPE: {
6288+
EXPENSIFY_CARD: 'expensify-card',
6289+
REIMBURSEMENT: 'reimbursement',
6290+
},
62876291
SORT_ORDER: {
62886292
ASC: 'asc',
62896293
DESC: 'desc',
@@ -6395,6 +6399,7 @@ const CONST = {
63956399
PAID: 'paid',
63966400
EXPORTED: 'exported',
63976401
POSTED: 'posted',
6402+
WITHDRAWAL_TYPE: 'withdrawalType',
63986403
WITHDRAWN: 'withdrawn',
63996404
TITLE: 'title',
64006405
ASSIGNEE: 'assignee',
@@ -6440,6 +6445,7 @@ const CONST = {
64406445
PAID: 'paid',
64416446
EXPORTED: 'exported',
64426447
POSTED: 'posted',
6448+
WITHDRAWAL_TYPE: 'withdrawal-type',
64436449
WITHDRAWN: 'withdrawn',
64446450
TITLE: 'title',
64456451
ASSIGNEE: 'assignee',

src/ROUTES.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const ROUTES = {
7474
SEARCH_ADVANCED_FILTERS_CARD: 'search/filters/card',
7575
SEARCH_ADVANCED_FILTERS_TAX_RATE: 'search/filters/taxRate',
7676
SEARCH_ADVANCED_FILTERS_EXPENSE_TYPE: 'search/filters/expenseType',
77+
SEARCH_ADVANCED_FILTERS_WITHDRAWAL_TYPE: 'search/filters/withdrawal-type',
7778
SEARCH_ADVANCED_FILTERS_TAG: 'search/filters/tag',
7879
SEARCH_ADVANCED_FILTERS_FROM: 'search/filters/from',
7980
SEARCH_ADVANCED_FILTERS_TO: 'search/filters/to',

src/SCREENS.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const SCREENS = {
6363
ADVANCED_FILTERS_CARD_RHP: 'Search_Advanced_Filters_Card_RHP',
6464
ADVANCED_FILTERS_TAX_RATE_RHP: 'Search_Advanced_Filters_Tax_Rate_RHP',
6565
ADVANCED_FILTERS_EXPENSE_TYPE_RHP: 'Search_Advanced_Filters_Expense_Type_RHP',
66+
ADVANCED_FILTERS_WITHDRAWAL_TYPE_RHP: 'Search_Advanced_Filters_Withdrawal_Type_RHP',
6667
ADVANCED_FILTERS_TAG_RHP: 'Search_Advanced_Filters_Tag_RHP',
6768
ADVANCED_FILTERS_FROM_RHP: 'Search_Advanced_Filters_From_RHP',
6869
ADVANCED_FILTERS_TO_RHP: 'Search_Advanced_Filters_To_RHP',

src/components/Search/SearchAutocompleteList.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ function SearchAutocompleteList(
205205
}, [autocompleteQueryValue]);
206206

207207
const expenseTypes = Object.values(CONST.SEARCH.TRANSACTION_TYPE);
208+
const withdrawalTypes = Object.values(CONST.SEARCH.WITHDRAWAL_TYPE);
208209
const booleanTypes = Object.values(CONST.SEARCH.BOOLEAN);
209210

210211
const cardAutocompleteList = useMemo(() => Object.values(allCards), [allCards]);
@@ -374,6 +375,16 @@ function SearchAutocompleteList(
374375
text: expenseType,
375376
}));
376377
}
378+
case CONST.SEARCH.SYNTAX_FILTER_KEYS.WITHDRAWAL_TYPE: {
379+
const filteredWithdrawalTypes = withdrawalTypes
380+
.filter((withdrawalType) => withdrawalType.includes(autocompleteValue.toLowerCase()) && !alreadyAutocompletedKeys.includes(withdrawalType))
381+
.sort();
382+
383+
return filteredWithdrawalTypes.map((withdrawalType) => ({
384+
filterKey: CONST.SEARCH.SEARCH_USER_FRIENDLY_KEYS.WITHDRAWAL_TYPE,
385+
text: withdrawalType,
386+
}));
387+
}
377388
case CONST.SEARCH.SYNTAX_FILTER_KEYS.FEED: {
378389
const filteredFeeds = feedAutoCompleteList
379390
.filter((feed) => feed.name.toLowerCase().includes(autocompleteValue.toLowerCase()) && !alreadyAutocompletedKeys.includes(feed.name.toLowerCase()))
@@ -460,6 +471,7 @@ function SearchAutocompleteList(
460471
groupByAutocompleteList,
461472
statusAutocompleteList,
462473
expenseTypes,
474+
withdrawalTypes,
463475
feedAutoCompleteList,
464476
cardAutocompleteList,
465477
booleanTypes,

src/components/Search/SearchPageHeader/SearchFiltersBar.tsx

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import SingleSelectPopup from '@components/Search/FilterDropdowns/SingleSelectPo
1717
import UserSelectPopup from '@components/Search/FilterDropdowns/UserSelectPopup';
1818
import {useSearchContext} from '@components/Search/SearchContext';
1919
import type {SearchDateValues} from '@components/Search/SearchDatePresetFilterBase';
20-
import type {SearchDateFilterKeys, SearchQueryJSON, SingularSearchStatus} from '@components/Search/types';
20+
import type {SearchDateFilterKeys, SearchGroupBy, SearchQueryJSON, SingularSearchStatus} from '@components/Search/types';
2121
import SearchFiltersSkeleton from '@components/Skeletons/SearchFiltersSkeleton';
2222
import useEnvironment from '@hooks/useEnvironment';
2323
import useLocalize from '@hooks/useLocalize';
@@ -40,7 +40,7 @@ import {
4040
isFilterSupported,
4141
isSearchDatePreset,
4242
} from '@libs/SearchQueryUtils';
43-
import {getDatePresets, getFeedOptions, getGroupByOptions, getStatusOptions, getTypeOptions} from '@libs/SearchUIUtils';
43+
import {getDatePresets, getFeedOptions, getGroupByOptions, getStatusOptions, getTypeOptions, getWithdrawalTypeOptions} from '@libs/SearchUIUtils';
4444
import CONST from '@src/CONST';
4545
import type {TranslationPaths} from '@src/languages/types';
4646
import ONYXKEYS from '@src/ONYXKEYS';
@@ -189,6 +189,12 @@ function SearchFiltersBar({queryJSON, headerButtonsOptions, isMobileSelectionMod
189189
[filterFormValues.withdrawnOn, filterFormValues.withdrawnAfter, filterFormValues.withdrawnBefore, createDateDisplayValue],
190190
);
191191

192+
const [withdrawalTypeOptions, withdrawalType] = useMemo(() => {
193+
const options = getWithdrawalTypeOptions(translate);
194+
const value = options.find((option) => option.value === filterFormValues.withdrawalType) ?? null;
195+
return [options, value];
196+
}, [translate, filterFormValues.withdrawalType]);
197+
192198
const updateFilterForm = useCallback(
193199
(values: Partial<SearchAdvancedFiltersForm>) => {
194200
const updatedFilterFormValues: Partial<SearchAdvancedFiltersForm> = {
@@ -296,6 +302,21 @@ function SearchFiltersBar({queryJSON, headerButtonsOptions, isMobileSelectionMod
296302
[createDatePickerComponent, withdrawn],
297303
);
298304

305+
const withdrawalTypeComponent = useCallback(
306+
({closeOverlay}: PopoverComponentProps) => {
307+
return (
308+
<SingleSelectPopup
309+
label={translate('search.withdrawalType')}
310+
items={withdrawalTypeOptions}
311+
value={withdrawalType}
312+
closeOverlay={closeOverlay}
313+
onChange={(item) => updateFilterForm({withdrawalType: item?.value})}
314+
/>
315+
);
316+
},
317+
[translate, withdrawalTypeOptions, withdrawalType, updateFilterForm],
318+
);
319+
299320
const statusComponent = useCallback(
300321
({closeOverlay}: PopoverComponentProps) => {
301322
const onChange = (selectedItems: Array<MultiSelectItem<SingularSearchStatus>>) => {
@@ -366,6 +387,8 @@ function SearchFiltersBar({queryJSON, headerButtonsOptions, isMobileSelectionMod
366387
const shouldDisplayGroupByFilter = isDevelopment;
367388
const shouldDisplayFeedFilter = feedOptions.length > 1 && !!filterFormValues.feed;
368389
const shouldDisplayPostedFilter = !!filterFormValues.feed && (!!filterFormValues.postedOn || !!filterFormValues.postedAfter || !!filterFormValues.postedBefore);
390+
// We'll refactor this to use a const in https://github.com/Expensify/App/issues/68227
391+
const shouldDisplayWithdrawalTypeFilter = groupBy?.value === ('withdrawalID' as SearchGroupBy) && !!filterFormValues.withdrawalType;
369392
const shouldDisplayWithdrawnFilter = !!filterFormValues.withdrawnOn || !!filterFormValues.withdrawnAfter || !!filterFormValues.withdrawnBefore;
370393

371394
const filterList = [
@@ -405,6 +428,16 @@ function SearchFiltersBar({queryJSON, headerButtonsOptions, isMobileSelectionMod
405428
},
406429
]
407430
: []),
431+
...(shouldDisplayWithdrawalTypeFilter
432+
? [
433+
{
434+
label: translate('search.withdrawalType'),
435+
PopoverComponent: withdrawalTypeComponent,
436+
value: withdrawalType?.text ?? null,
437+
filterKey: FILTER_KEYS.WITHDRAWAL_TYPE,
438+
},
439+
]
440+
: []),
408441
...(shouldDisplayWithdrawnFilter
409442
? [
410443
{
@@ -439,6 +472,7 @@ function SearchFiltersBar({queryJSON, headerButtonsOptions, isMobileSelectionMod
439472
}, [
440473
type,
441474
groupBy,
475+
withdrawalType,
442476
displayDate,
443477
displayPosted,
444478
displayWithdrawn,
@@ -447,6 +481,7 @@ function SearchFiltersBar({queryJSON, headerButtonsOptions, isMobileSelectionMod
447481
filterFormValues.postedOn,
448482
filterFormValues.postedAfter,
449483
filterFormValues.postedBefore,
484+
filterFormValues.withdrawalType,
450485
filterFormValues.withdrawnOn,
451486
filterFormValues.withdrawnAfter,
452487
filterFormValues.withdrawnBefore,
@@ -457,6 +492,7 @@ function SearchFiltersBar({queryJSON, headerButtonsOptions, isMobileSelectionMod
457492
datePickerComponent,
458493
userPickerComponent,
459494
postedPickerComponent,
495+
withdrawalTypeComponent,
460496
withdrawnPickerComponent,
461497
status,
462498
personalDetails,

src/components/Search/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ type SearchStatus = SingularSearchStatus | SingularSearchStatus[];
6767
type SearchGroupBy = ValueOf<typeof CONST.SEARCH.GROUP_BY>;
6868
type TableColumnSize = ValueOf<typeof CONST.SEARCH.TABLE_COLUMN_SIZES>;
6969
type SearchDatePreset = ValueOf<typeof CONST.SEARCH.DATE_PRESETS>;
70+
type SearchWithdrawalType = ValueOf<typeof CONST.SEARCH.WITHDRAWAL_TYPE>;
7071

7172
type SearchContextData = {
7273
currentSearchHash: number;
@@ -205,4 +206,5 @@ export type {
205206
SearchGroupBy,
206207
SingularSearchStatus,
207208
SearchDatePreset,
209+
SearchWithdrawalType,
208210
};

src/languages/de.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6040,6 +6040,10 @@ const translations = {
60406040
cards: 'Karte',
60416041
},
60426042
feed: 'Feed',
6043+
withdrawalType: {
6044+
[CONST.SEARCH.WITHDRAWAL_TYPE.EXPENSIFY_CARD]: 'Expensify Card',
6045+
[CONST.SEARCH.WITHDRAWAL_TYPE.REIMBURSEMENT]: 'Erstattung',
6046+
},
60436047
},
60446048
groupBy: 'Gruppe nach',
60456049
moneyRequestReport: {
@@ -6049,6 +6053,7 @@ const translations = {
60496053
noCategory: 'Keine Kategorie',
60506054
noTag: 'Kein Tag',
60516055
expenseType: 'Ausgabentyp',
6056+
withdrawalType: 'Auszahlungsart',
60526057
recentSearches: 'Letzte Suchanfragen',
60536058
recentChats: 'Letzte Chats',
60546059
searchIn: 'Suche in',

src/languages/en.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6016,6 +6016,10 @@ const translations = {
60166016
cards: 'Card', // s77rt use singular key name
60176017
},
60186018
feed: 'Feed',
6019+
withdrawalType: {
6020+
[CONST.SEARCH.WITHDRAWAL_TYPE.EXPENSIFY_CARD]: 'Expensify Card',
6021+
[CONST.SEARCH.WITHDRAWAL_TYPE.REIMBURSEMENT]: 'Reimbursement',
6022+
},
60196023
},
60206024
groupBy: 'Group by',
60216025
moneyRequestReport: {
@@ -6025,6 +6029,7 @@ const translations = {
60256029
noCategory: 'No category',
60266030
noTag: 'No tag',
60276031
expenseType: 'Expense type',
6032+
withdrawalType: 'Withdrawal type',
60286033
recentSearches: 'Recent searches',
60296034
recentChats: 'Recent chats',
60306035
searchIn: 'Search in',

src/languages/es.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6034,6 +6034,10 @@ const translations = {
60346034
cards: 'Tarjeta',
60356035
},
60366036
feed: 'Feed',
6037+
withdrawalType: {
6038+
[CONST.SEARCH.WITHDRAWAL_TYPE.EXPENSIFY_CARD]: 'Expensify Card',
6039+
[CONST.SEARCH.WITHDRAWAL_TYPE.REIMBURSEMENT]: 'Reembolso',
6040+
},
60376041
},
60386042
groupBy: 'Agrupar por',
60396043
moneyRequestReport: {
@@ -6043,6 +6047,7 @@ const translations = {
60436047
noCategory: 'Sin categoría',
60446048
noTag: 'Sin etiqueta',
60456049
expenseType: 'Tipo de gasto',
6050+
withdrawalType: 'Tipo de retiro',
60466051
recentSearches: 'Búsquedas recientes',
60476052
recentChats: 'Chats recientes',
60486053
searchIn: 'Buscar en',

src/languages/fr.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6053,6 +6053,10 @@ const translations = {
60536053
cards: 'Carte',
60546054
},
60556055
feed: 'Flux',
6056+
withdrawalType: {
6057+
[CONST.SEARCH.WITHDRAWAL_TYPE.EXPENSIFY_CARD]: 'Expensify Card',
6058+
[CONST.SEARCH.WITHDRAWAL_TYPE.REIMBURSEMENT]: 'Remboursement',
6059+
},
60566060
},
60576061
groupBy: 'Groupe par',
60586062
moneyRequestReport: {
@@ -6062,6 +6066,7 @@ const translations = {
60626066
noCategory: 'Aucune catégorie',
60636067
noTag: 'Aucun tag',
60646068
expenseType: 'Type de dépense',
6069+
withdrawalType: 'Type de retrait',
60656070
recentSearches: 'Recherches récentes',
60666071
recentChats: 'Discussions récentes',
60676072
searchIn: 'Rechercher dans',

0 commit comments

Comments
 (0)