@@ -8,6 +8,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
8
8
import * as SearchActions from '@libs/actions/Search' ;
9
9
import * as DeviceCapabilities from '@libs/DeviceCapabilities' ;
10
10
import Log from '@libs/Log' ;
11
+ import * as ReportUtils from '@libs/ReportUtils' ;
11
12
import * as SearchUtils from '@libs/SearchUtils' ;
12
13
import type { SearchColumnType , SortOrder } from '@libs/SearchUtils' ;
13
14
import Navigation from '@navigation/Navigation' ;
@@ -34,9 +35,9 @@ type SearchProps = {
34
35
35
36
const sortableSearchTabs : SearchQuery [ ] = [ CONST . TAB_SEARCH . ALL ] ;
36
37
37
- function isReportListItemType ( item : TransactionListItemType | ReportListItemType ) : item is ReportListItemType {
38
- const reportListItem = item as ReportListItemType ;
39
- return reportListItem . transactions !== undefined ;
38
+ function isTransactionListItemType ( item : TransactionListItemType | ReportListItemType ) : item is TransactionListItemType {
39
+ const transactionListItem = item as TransactionListItemType ;
40
+ return transactionListItem . transactionID !== undefined ;
40
41
}
41
42
42
43
function Search ( { query, policyIDs, sortBy, sortOrder} : SearchProps ) {
@@ -76,11 +77,19 @@ function Search({query, policyIDs, sortBy, sortOrder}: SearchProps) {
76
77
return < EmptySearchView /> ;
77
78
}
78
79
79
- const openReport = ( reportID ?: string ) => {
80
+ const openReport = ( item : TransactionListItemType | ReportListItemType ) => {
81
+ let reportID = isTransactionListItemType ( item ) ? item . transactionThreadReportID : item . reportID ;
82
+
80
83
if ( ! reportID ) {
81
84
return ;
82
85
}
83
86
87
+ // If we're trying to open a legacy transaction without a transaction thread, let's create the thread and navigate the user
88
+ if ( isTransactionListItemType ( item ) && reportID === '0' && item . moneyRequestReportActionID ) {
89
+ reportID = ReportUtils . generateReportID ( ) ;
90
+ SearchActions . createTransactionThread ( hash , item . transactionID , reportID , item . moneyRequestReportActionID ) ;
91
+ }
92
+
84
93
Navigation . navigate ( ROUTES . SEARCH_REPORT . getRoute ( query , reportID ) ) ;
85
94
} ;
86
95
@@ -137,10 +146,7 @@ function Search({query, policyIDs, sortBy, sortOrder}: SearchProps) {
137
146
updateCellsBatchingPeriod = { 200 }
138
147
ListItem = { ListItem }
139
148
sections = { [ { data : sortedData , isDisabled : false } ] }
140
- onSelectRow = { ( item ) => {
141
- const reportID = isReportListItemType ( item ) ? item . reportID : item . transactionThreadReportID ;
142
- openReport ( reportID ) ;
143
- } }
149
+ onSelectRow = { ( item ) => openReport ( item ) }
144
150
shouldDebounceRowSelect
145
151
shouldPreventDefaultFocusOnSelectRow = { ! DeviceCapabilities . canUseTouchScreen ( ) }
146
152
listHeaderWrapperStyle = { [ styles . ph9 , styles . pv3 , styles . pb5 ] }
0 commit comments