@@ -1977,11 +1977,6 @@ function getOptions(
1977
1977
}
1978
1978
}
1979
1979
}
1980
-
1981
- // Add this login to the exclude list so it won't appear when we process the personal details
1982
- if ( reportOption . login ) {
1983
- optionsToExclude . push ( { login : reportOption . login } ) ;
1984
- }
1985
1980
}
1986
1981
}
1987
1982
@@ -2114,34 +2109,75 @@ function getIOUConfirmationOptionsFromPayeePersonalDetail(personalDetail: OnyxEn
2114
2109
/**
2115
2110
* Build the options for the New Group view
2116
2111
*/
2117
- function getFilteredOptions (
2118
- reports : Array < SearchOption < Report > > = [ ] ,
2119
- personalDetails : Array < SearchOption < PersonalDetails > > = [ ] ,
2120
- betas : OnyxEntry < Beta [ ] > = [ ] ,
2121
- searchValue = '' ,
2122
- selectedOptions : Array < Partial < ReportUtils . OptionData > > = [ ] ,
2123
- excludeLogins : string [ ] = [ ] ,
2124
- includeOwnedWorkspaceChats = false ,
2125
- includeP2P = true ,
2126
- includeCategories = false ,
2127
- categories : PolicyCategories = { } ,
2128
- recentlyUsedCategories : string [ ] = [ ] ,
2129
- includeTags = false ,
2130
- tags : PolicyTags | Array < PolicyTag | SelectedTagOption > = { } ,
2131
- recentlyUsedTags : string [ ] = [ ] ,
2132
- canInviteUser = true ,
2133
- includeSelectedOptions = false ,
2134
- includeTaxRates = false ,
2135
- maxRecentReportsToShow : number = CONST . IOU . MAX_RECENT_REPORTS_TO_SHOW ,
2136
- taxRates : TaxRatesWithDefault = { } as TaxRatesWithDefault ,
2137
- includeSelfDM = false ,
2138
- includePolicyReportFieldOptions = false ,
2139
- policyReportFieldOptions : string [ ] = [ ] ,
2140
- recentlyUsedPolicyReportFieldOptions : string [ ] = [ ] ,
2141
- includeInvoiceRooms = false ,
2142
- action : IOUAction | undefined = undefined ,
2143
- sortByReportTypeInSearch = false ,
2144
- ) {
2112
+ type FilteredOptionsParams = {
2113
+ reports ?: Array < SearchOption < Report > > ;
2114
+ personalDetails ?: Array < SearchOption < PersonalDetails > > ;
2115
+ betas ?: OnyxEntry < Beta [ ] > ;
2116
+ searchValue ?: string ;
2117
+ selectedOptions ?: Array < Partial < ReportUtils . OptionData > > ;
2118
+ excludeLogins ?: string [ ] ;
2119
+ includeOwnedWorkspaceChats ?: boolean ;
2120
+ includeP2P ?: boolean ;
2121
+ includeCategories ?: boolean ;
2122
+ categories ?: PolicyCategories ;
2123
+ recentlyUsedCategories ?: string [ ] ;
2124
+ includeTags ?: boolean ;
2125
+ tags ?: PolicyTags | Array < PolicyTag | SelectedTagOption > ;
2126
+ recentlyUsedTags ?: string [ ] ;
2127
+ canInviteUser ?: boolean ;
2128
+ includeSelectedOptions ?: boolean ;
2129
+ includeTaxRates ?: boolean ;
2130
+ taxRates ?: TaxRatesWithDefault ;
2131
+ maxRecentReportsToShow ?: number ;
2132
+ includeSelfDM ?: boolean ;
2133
+ includePolicyReportFieldOptions ?: boolean ;
2134
+ policyReportFieldOptions ?: string [ ] ;
2135
+ recentlyUsedPolicyReportFieldOptions ?: string [ ] ;
2136
+ includeInvoiceRooms ?: boolean ;
2137
+ action ?: IOUAction ;
2138
+ sortByReportTypeInSearch ?: boolean ;
2139
+ } ;
2140
+
2141
+ // It is not recommended to pass a search value to getFilteredOptions when passing reports and personalDetails.
2142
+ // If a search value is passed, the search value should be passed to filterOptions.
2143
+ // When it is necessary to pass a search value when passing reports and personalDetails, follow these steps:
2144
+ // 1. Use getFilteredOptions with reports and personalDetails only, without the search value.
2145
+ // 2. Pass the returned options from getFilteredOptions to filterOptions along with the search value.
2146
+ // The above constraints are enforced with TypeScript.
2147
+
2148
+ type FilteredOptionsParamsWithDefaultSearchValue = Omit < FilteredOptionsParams , 'searchValue' > & { searchValue ?: '' } ;
2149
+
2150
+ type FilteredOptionsParamsWithoutOptions = Omit < FilteredOptionsParams , 'reports' | 'personalDetails' > & { reports ?: [ ] ; personalDetails ?: [ ] } ;
2151
+
2152
+ function getFilteredOptions ( params : FilteredOptionsParamsWithDefaultSearchValue | FilteredOptionsParamsWithoutOptions ) {
2153
+ const {
2154
+ reports = [ ] ,
2155
+ personalDetails = [ ] ,
2156
+ betas = [ ] ,
2157
+ searchValue = '' ,
2158
+ selectedOptions = [ ] ,
2159
+ excludeLogins = [ ] ,
2160
+ includeOwnedWorkspaceChats = false ,
2161
+ includeP2P = true ,
2162
+ includeCategories = false ,
2163
+ categories = { } ,
2164
+ recentlyUsedCategories = [ ] ,
2165
+ includeTags = false ,
2166
+ tags = { } ,
2167
+ recentlyUsedTags = [ ] ,
2168
+ canInviteUser = true ,
2169
+ includeSelectedOptions = false ,
2170
+ includeTaxRates = false ,
2171
+ maxRecentReportsToShow = CONST . IOU . MAX_RECENT_REPORTS_TO_SHOW ,
2172
+ taxRates = { } as TaxRatesWithDefault ,
2173
+ includeSelfDM = false ,
2174
+ includePolicyReportFieldOptions = false ,
2175
+ policyReportFieldOptions = [ ] ,
2176
+ recentlyUsedPolicyReportFieldOptions = [ ] ,
2177
+ includeInvoiceRooms = false ,
2178
+ action,
2179
+ sortByReportTypeInSearch = false ,
2180
+ } = params ;
2145
2181
return getOptions (
2146
2182
{ reports, personalDetails} ,
2147
2183
{
@@ -2421,8 +2457,19 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt
2421
2457
preferPolicyExpenseChat = false ,
2422
2458
preferRecentExpenseReports = false ,
2423
2459
} = config ?? { } ;
2460
+ // Remove the personal details for the DMs that are already in the recent reports so that we don't show duplicates
2461
+ function filteredPersonalDetailsOfRecentReports ( recentReports : ReportUtils . OptionData [ ] , personalDetails : ReportUtils . OptionData [ ] ) {
2462
+ const excludedLogins = new Set ( recentReports . map ( ( report ) => report . login ) ) ;
2463
+ return personalDetails . filter ( ( personalDetail ) => ! excludedLogins . has ( personalDetail . login ) ) ;
2464
+ }
2424
2465
if ( searchInputValue . trim ( ) === '' && maxRecentReportsToShow > 0 ) {
2425
- return { ...options , recentReports : options . recentReports . slice ( 0 , maxRecentReportsToShow ) } ;
2466
+ const recentReports = options . recentReports . slice ( 0 , maxRecentReportsToShow ) ;
2467
+ const personalDetails = filteredPersonalDetailsOfRecentReports ( recentReports , options . personalDetails ) ;
2468
+ return {
2469
+ ...options ,
2470
+ recentReports,
2471
+ personalDetails,
2472
+ } ;
2426
2473
}
2427
2474
2428
2475
const parsedPhoneNumber = PhoneNumber . parsePhoneNumber ( LoginUtils . appendCountryCode ( Str . removeSMSDomain ( searchInputValue ) ) ) ;
@@ -2464,7 +2511,6 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt
2464
2511
const currentUserOptionSearchText = items . currentUserOption ? uniqFast ( getCurrentUserSearchTerms ( items . currentUserOption ) ) . join ( ' ' ) : '' ;
2465
2512
2466
2513
const currentUserOption = isSearchStringMatch ( term , currentUserOptionSearchText ) ? items . currentUserOption : null ;
2467
-
2468
2514
return {
2469
2515
recentReports : recentReports ?? [ ] ,
2470
2516
personalDetails : personalDetails ?? [ ] ,
@@ -2479,6 +2525,7 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt
2479
2525
let { recentReports, personalDetails} = matchResults ;
2480
2526
2481
2527
if ( sortByReportTypeInSearch ) {
2528
+ personalDetails = filteredPersonalDetailsOfRecentReports ( recentReports , personalDetails ) ;
2482
2529
recentReports = recentReports . concat ( personalDetails ) ;
2483
2530
personalDetails = [ ] ;
2484
2531
recentReports = orderOptions ( recentReports , searchValue ) ;
@@ -2489,9 +2536,10 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt
2489
2536
if ( maxRecentReportsToShow > 0 && recentReports . length > maxRecentReportsToShow ) {
2490
2537
recentReports . splice ( maxRecentReportsToShow ) ;
2491
2538
}
2539
+ const filteredPersonalDetails = filteredPersonalDetailsOfRecentReports ( recentReports , personalDetails ) ;
2492
2540
2493
2541
return {
2494
- personalDetails,
2542
+ personalDetails : filteredPersonalDetails ,
2495
2543
recentReports : orderOptions ( recentReports , searchValue , { preferChatroomsOverThreads, preferPolicyExpenseChat, preferRecentExpenseReports} ) ,
2496
2544
userToInvite,
2497
2545
currentUserOption : matchResults . currentUserOption ,
0 commit comments