@@ -16,6 +16,7 @@ import usePermissions from '@hooks/usePermissions';
16
16
import useSingleExecution from '@hooks/useSingleExecution' ;
17
17
import useThemeStyles from '@hooks/useThemeStyles' ;
18
18
import useWaitForNavigation from '@hooks/useWaitForNavigation' ;
19
+ import type { WorkspaceListItem } from '@hooks/useWorkspaceList' ;
19
20
import useWorkspaceList from '@hooks/useWorkspaceList' ;
20
21
import { clearAllFilters , saveSearch } from '@libs/actions/Search' ;
21
22
import { createCardFeedKey , getCardFeedKey , getCardFeedNamesWithType , getWorkspaceCardFeedKey } from '@libs/CardFeedUtils' ;
@@ -220,9 +221,8 @@ const typeFiltersKeys: Record<string, Array<Array<ValueOf<typeof CONST.SEARCH.SY
220
221
] ,
221
222
} ;
222
223
223
- function getFilterWorkspaceDisplayTitle ( filters : Partial < SearchAdvancedFiltersForm > , policies : OnyxCollection < Policy > ) {
224
- const workspaceFilter = filters [ CONST . SEARCH . SYNTAX_FILTER_KEYS . POLICY_ID ] ;
225
- return policies ?. [ `${ ONYXKEYS . COLLECTION . POLICY } ${ workspaceFilter } ` ] ?. name ?? workspaceFilter ;
224
+ function getFilterWorkspaceDisplayTitle ( filters : SearchAdvancedFiltersForm , policies : WorkspaceListItem [ ] ) {
225
+ return policies . filter ( ( value ) => value . policyID === filters . policyID ) . at ( 0 ) ?. text ;
226
226
}
227
227
228
228
function getFilterCardDisplayTitle ( filters : Partial < SearchAdvancedFiltersForm > , cards : CardList , translate : LocaleContextProps [ 'translate' ] ) {
@@ -443,9 +443,6 @@ function AdvancedSearchFilters() {
443
443
selectedPolicyID : undefined ,
444
444
searchTerm : '' ,
445
445
} ) ;
446
- // We check if the previously selected workspace (which might have been deleted)
447
- // still exists — only then can we set it as the active one again.
448
- const isWorkspaceNameStillPresent = ( filterTitle : string | undefined ) => workspaces . some ( ( section ) => section . data ?. some ( ( item ) => item . text === filterTitle ) ) ;
449
446
450
447
// When looking if a user has any categories to display, we want to ignore the policies that are of type PERSONAL
451
448
const nonPersonalPolicyCategoryIds = Object . values ( policies )
@@ -560,10 +557,8 @@ function AdvancedSearchFilters() {
560
557
if ( ! shouldDisplayWorkspaceFilter ) {
561
558
return ;
562
559
}
563
- const selectedWorkspaceName = baseFilterConfig [ key ] . getTitle ( searchAdvancedFilters , policies ) ;
564
- if ( isWorkspaceNameStillPresent ( selectedWorkspaceName ) ) {
565
- filterTitle = selectedWorkspaceName ;
566
- }
560
+ const workspacesData = workspaces . flatMap ( ( value ) => value . data ) ;
561
+ filterTitle = baseFilterConfig [ key ] . getTitle ( searchAdvancedFilters , workspacesData ) ;
567
562
}
568
563
return {
569
564
key,
0 commit comments