@@ -13,6 +13,7 @@ import UserListItem from '@components/SelectionList/UserListItem';
13
13
import useActiveWorkspace from '@hooks/useActiveWorkspace' ;
14
14
import useFastSearchFromOptions from '@hooks/useFastSearchFromOptions' ;
15
15
import useLocalize from '@hooks/useLocalize' ;
16
+ import usePermissions from '@hooks/usePermissions' ;
16
17
import usePolicy from '@hooks/usePolicy' ;
17
18
import useResponsiveLayout from '@hooks/useResponsiveLayout' ;
18
19
import useThemeStyles from '@hooks/useThemeStyles' ;
@@ -23,7 +24,7 @@ import memoize from '@libs/memoize';
23
24
import { combineOrderingOfReportsAndPersonalDetails , getSearchOptions , getValidPersonalDetailOptions } from '@libs/OptionsListUtils' ;
24
25
import type { Options , SearchOption } from '@libs/OptionsListUtils' ;
25
26
import Performance from '@libs/Performance' ;
26
- import { getAllTaxRates , getCleanedTagName } from '@libs/PolicyUtils' ;
27
+ import { getAllTaxRates , getCleanedTagName , shouldShowPolicy } from '@libs/PolicyUtils' ;
27
28
import type { OptionData } from '@libs/ReportUtils' ;
28
29
import {
29
30
getAutocompleteCategories ,
@@ -145,11 +146,12 @@ function SearchAutocompleteList(
145
146
146
147
const { activeWorkspaceID} = useActiveWorkspace ( ) ;
147
148
const policy = usePolicy ( activeWorkspaceID ) ;
148
- const [ betas ] = useOnyx ( ONYXKEYS . BETAS ) ;
149
- const [ recentSearches ] = useOnyx ( ONYXKEYS . RECENT_SEARCHES ) ;
149
+ const [ betas ] = useOnyx ( ONYXKEYS . BETAS , { canBeMissing : true } ) ;
150
+ const [ recentSearches ] = useOnyx ( ONYXKEYS . RECENT_SEARCHES , { canBeMissing : true } ) ;
150
151
const personalDetails = usePersonalDetails ( ) ;
151
- const [ reports = { } ] = useOnyx ( ONYXKEYS . COLLECTION . REPORT ) ;
152
+ const [ reports = { } ] = useOnyx ( ONYXKEYS . COLLECTION . REPORT , { canBeMissing : true } ) ;
152
153
const taxRates = getAllTaxRates ( ) ;
154
+ const { canUseLeftHandBar} = usePermissions ( ) ;
153
155
154
156
const { options, areOptionsInitialized} = useOptionsList ( ) ;
155
157
const searchOptions = useMemo ( ( ) => {
@@ -167,8 +169,8 @@ function SearchAutocompleteList(
167
169
const expenseTypes = Object . values ( CONST . SEARCH . TRANSACTION_TYPE ) ;
168
170
const booleanTypes = Object . values ( CONST . SEARCH . BOOLEAN ) ;
169
171
170
- const [ userCardList ] = useOnyx ( ONYXKEYS . CARD_LIST ) ;
171
- const [ workspaceCardFeeds ] = useOnyx ( ONYXKEYS . COLLECTION . WORKSPACE_CARDS_LIST ) ;
172
+ const [ userCardList ] = useOnyx ( ONYXKEYS . CARD_LIST , { canBeMissing : true } ) ;
173
+ const [ workspaceCardFeeds ] = useOnyx ( ONYXKEYS . COLLECTION . WORKSPACE_CARDS_LIST , { canBeMissing : true } ) ;
172
174
const allCards = useMemo ( ( ) => mergeCardListWithWorkspaceFeeds ( workspaceCardFeeds ?? CONST . EMPTY_OBJECT , userCardList ) , [ userCardList , workspaceCardFeeds ] ) ;
173
175
const cardAutocompleteList = Object . values ( allCards ) ;
174
176
const cardFeedNamesWithType = useMemo ( ( ) => {
@@ -210,20 +212,31 @@ function SearchAutocompleteList(
210
212
211
213
const taxAutocompleteList = useMemo ( ( ) => getAutocompleteTaxList ( taxRates , policy ) , [ policy , taxRates ] ) ;
212
214
213
- const [ allPolicyCategories ] = useOnyx ( ONYXKEYS . COLLECTION . POLICY_CATEGORIES ) ;
214
- const [ allRecentCategories ] = useOnyx ( ONYXKEYS . COLLECTION . POLICY_RECENTLY_USED_CATEGORIES ) ;
215
+ const [ allPolicyCategories ] = useOnyx ( ONYXKEYS . COLLECTION . POLICY_CATEGORIES , { canBeMissing : false } ) ;
216
+ const [ allRecentCategories ] = useOnyx ( ONYXKEYS . COLLECTION . POLICY_RECENTLY_USED_CATEGORIES , { canBeMissing : true } ) ;
215
217
const categoryAutocompleteList = useMemo ( ( ) => {
216
218
return getAutocompleteCategories ( allPolicyCategories , activeWorkspaceID ) ;
217
219
} , [ activeWorkspaceID , allPolicyCategories ] ) ;
218
220
const recentCategoriesAutocompleteList = useMemo ( ( ) => {
219
221
return getAutocompleteRecentCategories ( allRecentCategories , activeWorkspaceID ) ;
220
222
} , [ activeWorkspaceID , allRecentCategories ] ) ;
221
223
222
- const [ currencyList ] = useOnyx ( ONYXKEYS . CURRENCY_LIST ) ;
224
+ const [ policies = { } ] = useOnyx ( ONYXKEYS . COLLECTION . POLICY , { canBeMissing : false } ) ;
225
+ const [ currentUserLogin ] = useOnyx ( ONYXKEYS . SESSION , { selector : ( session ) => session ?. email , canBeMissing : false } ) ;
226
+
227
+ const workspaceList = useMemo (
228
+ ( ) =>
229
+ Object . values ( policies )
230
+ . filter ( ( singlePolicy ) => ! ! singlePolicy && shouldShowPolicy ( singlePolicy , false , currentUserLogin ) && ! singlePolicy ?. isJoinRequestPending )
231
+ . map ( ( singlePolicy ) => ( { id : singlePolicy ?. id , name : singlePolicy ?. name ?? '' } ) ) ,
232
+ [ policies , currentUserLogin ] ,
233
+ ) ;
234
+
235
+ const [ currencyList ] = useOnyx ( ONYXKEYS . CURRENCY_LIST , { canBeMissing : false } ) ;
223
236
const currencyAutocompleteList = Object . keys ( currencyList ?? { } ) . filter ( ( currency ) => ! currencyList ?. [ currency ] ?. retired ) ;
224
- const [ recentCurrencyAutocompleteList ] = useOnyx ( ONYXKEYS . RECENTLY_USED_CURRENCIES ) ;
225
- const [ allPoliciesTags ] = useOnyx ( ONYXKEYS . COLLECTION . POLICY_TAGS ) ;
226
- const [ allRecentTags ] = useOnyx ( ONYXKEYS . COLLECTION . POLICY_RECENTLY_USED_TAGS ) ;
237
+ const [ recentCurrencyAutocompleteList ] = useOnyx ( ONYXKEYS . RECENTLY_USED_CURRENCIES , { canBeMissing : true } ) ;
238
+ const [ allPoliciesTags ] = useOnyx ( ONYXKEYS . COLLECTION . POLICY_TAGS , { canBeMissing : false } ) ;
239
+ const [ allRecentTags ] = useOnyx ( ONYXKEYS . COLLECTION . POLICY_RECENTLY_USED_TAGS , { canBeMissing : true } ) ;
227
240
const tagAutocompleteList = useMemo ( ( ) => {
228
241
return getAutocompleteTags ( allPoliciesTags , activeWorkspaceID ) ;
229
242
} , [ activeWorkspaceID , allPoliciesTags ] ) ;
@@ -403,6 +416,22 @@ function SearchAutocompleteList(
403
416
text : value ,
404
417
} ) ) ;
405
418
}
419
+ case CONST . SEARCH . SYNTAX_FILTER_KEYS . POLICY_ID : {
420
+ if ( ! canUseLeftHandBar ) {
421
+ return [ ] ;
422
+ }
423
+ const filteredPolicies = workspaceList
424
+ . filter ( ( workspace ) => workspace . name . toLowerCase ( ) . includes ( autocompleteValue . toLowerCase ( ) ) && ! alreadyAutocompletedKeys . includes ( workspace . name . toLowerCase ( ) ) )
425
+ . sort ( )
426
+ . slice ( 0 , 10 ) ;
427
+
428
+ return filteredPolicies . map ( ( workspace ) => ( {
429
+ filterKey : CONST . SEARCH . SEARCH_USER_FRIENDLY_KEYS . POLICY_ID ,
430
+ text : workspace . name ,
431
+ autocompleteID : workspace . id ,
432
+ mapKey : CONST . SEARCH . SYNTAX_FILTER_KEYS . POLICY_ID ,
433
+ } ) ) ;
434
+ }
406
435
default : {
407
436
return [ ] ;
408
437
}
@@ -419,14 +448,16 @@ function SearchAutocompleteList(
419
448
getParticipantsAutocompleteList ,
420
449
searchOptions . recentReports ,
421
450
typeAutocompleteList ,
451
+ groupByAutocompleteList ,
422
452
statusAutocompleteList ,
423
453
expenseTypes ,
424
454
feedAutoCompleteList ,
425
455
workspaceCardFeeds ,
426
456
cardAutocompleteList ,
427
457
allCards ,
428
- groupByAutocompleteList ,
429
458
booleanTypes ,
459
+ workspaceList ,
460
+ canUseLeftHandBar ,
430
461
] ) ;
431
462
432
463
const sortedRecentSearches = useMemo ( ( ) => {
0 commit comments