@@ -19,7 +19,7 @@ import type {SingleSelectItem} from '@components/Search/FilterDropdowns/SingleSe
1919import SingleSelectPopup from '@components/Search/FilterDropdowns/SingleSelectPopup' ;
2020import UserSelectPopup from '@components/Search/FilterDropdowns/UserSelectPopup' ;
2121import { useSearchContext } from '@components/Search/SearchContext' ;
22- import type { SearchGroupBy , SearchQueryJSON , SingularSearchStatus } from '@components/Search/types' ;
22+ import type { SearchQueryJSON , SingularSearchStatus } from '@components/Search/types' ;
2323import SearchFiltersSkeleton from '@components/Skeletons/SearchFiltersSkeleton' ;
2424import useLocalize from '@hooks/useLocalize' ;
2525import useNetwork from '@hooks/useNetwork' ;
@@ -30,9 +30,9 @@ import {updateAdvancedFilters} from '@libs/actions/Search';
3030import { mergeCardListWithWorkspaceFeeds } from '@libs/CardUtils' ;
3131import DateUtils from '@libs/DateUtils' ;
3232import Navigation from '@libs/Navigation/Navigation' ;
33- import { canSendInvoice , getAllTaxRates } from '@libs/PolicyUtils' ;
34- import { hasInvoiceReports } from '@libs/ReportUtils' ;
33+ import { getAllTaxRates } from '@libs/PolicyUtils' ;
3534import { buildFilterFormValuesFromQuery , buildQueryStringFromFilterFormValues , buildSearchQueryJSON , buildSearchQueryString } from '@libs/SearchQueryUtils' ;
35+ import { getStatusOptions , getTypeOptions } from '@libs/SearchUIUtils' ;
3636import CONST from '@src/CONST' ;
3737import ONYXKEYS from '@src/ONYXKEYS' ;
3838import ROUTES from '@src/ROUTES' ;
@@ -44,70 +44,6 @@ type SearchFiltersBarProps = {
4444 headerButtonsOptions : Array < DropdownOption < SearchHeaderOptionValue > > ;
4545} ;
4646
47- const typeOptions : Array < SingleSelectItem < SearchDataTypes > > = [
48- { translation : 'common.expense' , value : CONST . SEARCH . DATA_TYPES . EXPENSE } ,
49- { translation : 'common.chat' , value : CONST . SEARCH . DATA_TYPES . CHAT } ,
50- { translation : 'common.invoice' , value : CONST . SEARCH . DATA_TYPES . INVOICE } ,
51- { translation : 'common.trip' , value : CONST . SEARCH . DATA_TYPES . TRIP } ,
52- { translation : 'common.task' , value : CONST . SEARCH . DATA_TYPES . TASK } ,
53- ] ;
54-
55- const expenseStatusOptions : Array < MultiSelectItem < SingularSearchStatus > > = [
56- { translation : 'common.unreported' , value : CONST . SEARCH . STATUS . EXPENSE . UNREPORTED } ,
57- { translation : 'common.drafts' , value : CONST . SEARCH . STATUS . EXPENSE . DRAFTS } ,
58- { translation : 'common.outstanding' , value : CONST . SEARCH . STATUS . EXPENSE . OUTSTANDING } ,
59- { translation : 'iou.approved' , value : CONST . SEARCH . STATUS . EXPENSE . APPROVED } ,
60- { translation : 'iou.settledExpensify' , value : CONST . SEARCH . STATUS . EXPENSE . PAID } ,
61- { translation : 'iou.done' , value : CONST . SEARCH . STATUS . EXPENSE . DONE } ,
62- ] ;
63-
64- const expenseReportStatusOptions : Array < MultiSelectItem < SingularSearchStatus > > = [
65- { translation : 'common.drafts' , value : CONST . SEARCH . STATUS . EXPENSE . DRAFTS } ,
66- { translation : 'common.outstanding' , value : CONST . SEARCH . STATUS . EXPENSE . OUTSTANDING } ,
67- { translation : 'iou.approved' , value : CONST . SEARCH . STATUS . EXPENSE . APPROVED } ,
68- { translation : 'iou.settledExpensify' , value : CONST . SEARCH . STATUS . EXPENSE . PAID } ,
69- { translation : 'iou.done' , value : CONST . SEARCH . STATUS . EXPENSE . DONE } ,
70- ] ;
71-
72- const chatStatusOptions : Array < MultiSelectItem < SingularSearchStatus > > = [
73- { translation : 'common.unread' , value : CONST . SEARCH . STATUS . CHAT . UNREAD } ,
74- { translation : 'common.sent' , value : CONST . SEARCH . STATUS . CHAT . SENT } ,
75- { translation : 'common.attachments' , value : CONST . SEARCH . STATUS . CHAT . ATTACHMENTS } ,
76- { translation : 'common.links' , value : CONST . SEARCH . STATUS . CHAT . LINKS } ,
77- { translation : 'search.filters.pinned' , value : CONST . SEARCH . STATUS . CHAT . PINNED } ,
78- ] ;
79-
80- const invoiceStatusOptions : Array < MultiSelectItem < SingularSearchStatus > > = [
81- { translation : 'common.outstanding' , value : CONST . SEARCH . STATUS . INVOICE . OUTSTANDING } ,
82- { translation : 'iou.settledExpensify' , value : CONST . SEARCH . STATUS . INVOICE . PAID } ,
83- ] ;
84-
85- const tripStatusOptions : Array < MultiSelectItem < SingularSearchStatus > > = [
86- { translation : 'search.filters.current' , value : CONST . SEARCH . STATUS . TRIP . CURRENT } ,
87- { translation : 'search.filters.past' , value : CONST . SEARCH . STATUS . TRIP . PAST } ,
88- ] ;
89-
90- const taskStatusOptions : Array < MultiSelectItem < SingularSearchStatus > > = [
91- { translation : 'common.outstanding' , value : CONST . SEARCH . STATUS . TASK . OUTSTANDING } ,
92- { translation : 'search.filters.completed' , value : CONST . SEARCH . STATUS . TASK . COMPLETED } ,
93- ] ;
94-
95- function getStatusOptions ( type : SearchDataTypes , groupBy : SearchGroupBy | undefined ) {
96- switch ( type ) {
97- case CONST . SEARCH . DATA_TYPES . CHAT :
98- return chatStatusOptions ;
99- case CONST . SEARCH . DATA_TYPES . INVOICE :
100- return invoiceStatusOptions ;
101- case CONST . SEARCH . DATA_TYPES . TRIP :
102- return tripStatusOptions ;
103- case CONST . SEARCH . DATA_TYPES . TASK :
104- return taskStatusOptions ;
105- case CONST . SEARCH . DATA_TYPES . EXPENSE :
106- default :
107- return groupBy === CONST . SEARCH . GROUP_BY . REPORTS ? expenseReportStatusOptions : expenseStatusOptions ;
108- }
109- }
110-
11147function SearchFiltersBar ( { queryJSON, headerButtonsOptions} : SearchFiltersBarProps ) {
11248 const { hash, type, groupBy, status} = queryJSON ;
11349 const scrollRef = useRef < RNScrollView > ( null ) ;
@@ -139,6 +75,8 @@ function SearchFiltersBar({queryJSON, headerButtonsOptions}: SearchFiltersBarPro
13975 const hasErrors = Object . keys ( currentSearchResults ?. errors ?? { } ) . length > 0 && ! isOffline ;
14076 const shouldShowSelectedDropdown = headerButtonsOptions . length > 0 && ( ! shouldUseNarrowLayout || ( ! ! selectionMode && selectionMode . isEnabled ) ) ;
14177
78+ const typeOptions = useMemo ( ( ) => getTypeOptions ( allPolicies , session ?. email ) , [ allPolicies , session ?. email ] ) ;
79+
14280 const filterFormValues = useMemo ( ( ) => {
14381 return buildFilterFormValuesFromQuery ( queryJSON , policyCategories , policyTagsLists , currencyList , personalDetails , allCards , reports , taxRates ) ;
14482 } , [ allCards , currencyList , personalDetails , policyCategories , policyTagsLists , queryJSON , reports , taxRates ] ) ;
@@ -171,23 +109,17 @@ function SearchFiltersBar({queryJSON, headerButtonsOptions}: SearchFiltersBarPro
171109 Navigation . setParams ( { q : query } ) ;
172110 } ;
173111
174- // Remove the invoice option if the user is not allowed to send invoices
175- let visibleOptions = typeOptions ;
176- if ( ! canSendInvoice ( allPolicies , session ?. email ) && ! hasInvoiceReports ( ) ) {
177- visibleOptions = visibleOptions . filter ( ( typeOption ) => typeOption . value !== CONST . SEARCH . DATA_TYPES . INVOICE ) ;
178- }
179-
180112 return (
181113 < SingleSelectPopup
182114 label = { translate ( 'common.type' ) }
183115 value = { value }
184- items = { visibleOptions }
116+ items = { typeOptions }
185117 closeOverlay = { closeOverlay }
186118 onChange = { onChange }
187119 />
188120 ) ;
189121 } ,
190- [ allPolicies , groupBy , queryJSON , session ?. email , status , translate , type ] ,
122+ [ groupBy , queryJSON , status , translate , type , typeOptions ] ,
191123 ) ;
192124
193125 const statusComponent = useCallback (
@@ -280,7 +212,6 @@ function SearchFiltersBar({queryJSON, headerButtonsOptions}: SearchFiltersBarPro
280212 * filter bar
281213 */
282214 const filters = useMemo ( ( ) => {
283- const typeValue = typeOptions . find ( ( option ) => option . value === type ) ?? null ;
284215 const statusValue = getStatusOptions ( type , groupBy ) . filter ( ( option ) => status . includes ( option . value ) ) ;
285216 const dateValue = [
286217 filterFormValues . dateAfter ? `${ translate ( 'common.after' ) } ${ DateUtils . formatToReadableString ( filterFormValues . dateAfter ) } ` : null ,
@@ -293,7 +224,7 @@ function SearchFiltersBar({queryJSON, headerButtonsOptions}: SearchFiltersBarPro
293224 {
294225 label : translate ( 'common.type' ) ,
295226 PopoverComponent : typeComponent ,
296- value : typeValue ?. translation ? translate ( typeValue . translation ) : null ,
227+ value : translate ( `common. ${ type } ` ) ,
297228 } ,
298229 {
299230 label : translate ( 'common.status' ) ,
@@ -316,10 +247,10 @@ function SearchFiltersBar({queryJSON, headerButtonsOptions}: SearchFiltersBarPro
316247 } , [
317248 type ,
318249 groupBy ,
319- filterFormValues . from ,
320250 filterFormValues . dateAfter ,
321251 filterFormValues . dateBefore ,
322252 filterFormValues . dateOn ,
253+ filterFormValues . from ,
323254 translate ,
324255 typeComponent ,
325256 statusComponent ,
0 commit comments