@@ -939,11 +939,11 @@ function orderReportOptionsWithSearch(
939
939
searchValue : string ,
940
940
{ preferChatroomsOverThreads = false , preferPolicyExpenseChat = false , preferRecentExpenseReports = false } : OrderOptionsConfig = { } ,
941
941
) {
942
+ const orderedByDate = orderReportOptions ( options ) ;
943
+
942
944
return lodashOrderBy (
943
- options ,
945
+ orderedByDate ,
944
946
[
945
- // Archived reports should always be at the bottom:
946
- sortComparatorReportOptionByArchivedStatus ,
947
947
// Sorting by kind:
948
948
( option ) => {
949
949
if ( option . isPolicyExpenseChat && preferPolicyExpenseChat && option . policyID === activePolicyID ) {
@@ -962,7 +962,7 @@ function orderReportOptionsWithSearch(
962
962
if ( preferChatroomsOverThreads && option . isThread ) {
963
963
return 4 ;
964
964
}
965
- if ( option . isChatRoom ) {
965
+ if ( ! ! option . isChatRoom || option . private_isArchived ) {
966
966
return 3 ;
967
967
}
968
968
if ( ! option . login ) {
@@ -975,13 +975,11 @@ function orderReportOptionsWithSearch(
975
975
// When option.login is an exact match with the search value, returning 0 puts it at the top of the option list
976
976
return 0 ;
977
977
} ,
978
- // Within the same kind, sort by the last visible action created date
979
- sortComparatorReportOptionByDate ,
980
978
// For Submit Expense flow, prioritize the most recent expense reports and then policy expense chats (without expense requests)
981
979
preferRecentExpenseReports ? ( option ) => option ?. lastIOUCreationDate ?? '' : '' ,
982
980
preferRecentExpenseReports ? ( option ) => option ?. isPolicyExpenseChat : 0 ,
983
981
] ,
984
- [ 'asc' , 'asc' , 'desc' , ' desc', 'desc' ] ,
982
+ [ 'asc' , 'desc' , 'desc' ] ,
985
983
) ;
986
984
}
987
985
@@ -995,7 +993,11 @@ function sortComparatorReportOptionByDate(options: ReportUtils.OptionData) {
995
993
return options . lastVisibleActionCreated ?? '' ;
996
994
}
997
995
998
- function orderOptions ( options : Pick < Options , 'recentReports' | 'personalDetails' > , searchValue ?: string , config ?: OrderOptionsConfig ) {
996
+ type ReportAndPersonalDetailOptions = Pick < Options , 'recentReports' | 'personalDetails' > ;
997
+
998
+ function orderOptions ( options : ReportAndPersonalDetailOptions ) : ReportAndPersonalDetailOptions ;
999
+ function orderOptions ( options : ReportAndPersonalDetailOptions , searchValue : string , config ?: OrderOptionsConfig ) : ReportAndPersonalDetailOptions ;
1000
+ function orderOptions ( options : ReportAndPersonalDetailOptions , searchValue ?: string , config ?: OrderOptionsConfig ) {
999
1001
let orderedReportOptions : ReportUtils . OptionData [ ] ;
1000
1002
if ( searchValue ) {
1001
1003
orderedReportOptions = orderReportOptionsWithSearch ( options . recentReports , searchValue , config ) ;
@@ -1750,26 +1752,21 @@ function filterAndOrderOptions(options: Options, searchInputValue: string, confi
1750
1752
}
1751
1753
1752
1754
const personalDetailsWithoutDMs = filteredPersonalDetailsOfRecentReports ( filteredReports , filteredPersonalDetails ) ;
1755
+ const orderedPersonalDetails = orderPersonalDetailsOptions ( personalDetailsWithoutDMs ) ;
1753
1756
1754
1757
// sortByReportTypeInSearch option will show the personal details as part of the recent reports
1755
1758
if ( sortByReportTypeInSearch ) {
1756
- filteredReports = filteredReports . concat ( personalDetailsWithoutDMs ) ;
1759
+ filteredReports = filteredReports . concat ( orderedPersonalDetails ) ;
1757
1760
filteredPersonalDetails = [ ] ;
1758
1761
} else {
1759
- filteredPersonalDetails = personalDetailsWithoutDMs ;
1762
+ filteredPersonalDetails = orderedPersonalDetails ;
1760
1763
}
1761
1764
1762
- const orderedOptions = orderOptions (
1763
- {
1764
- recentReports : filteredReports ,
1765
- personalDetails : filteredPersonalDetails ,
1766
- } ,
1767
- searchInputValue ,
1768
- config ,
1769
- ) ;
1765
+ const orderedReports = orderReportOptionsWithSearch ( filteredReports , searchInputValue , config ) ;
1770
1766
1771
1767
return {
1772
- ...orderedOptions ,
1768
+ recentReports : orderedReports ,
1769
+ personalDetails : filteredPersonalDetails ,
1773
1770
userToInvite : filterResult . userToInvite ,
1774
1771
currentUserOption : filterResult . currentUserOption ,
1775
1772
} ;
0 commit comments