@@ -27,7 +27,6 @@ function useSearchHighlightAndScroll({searchResults, transactions, previousTrans
27
27
// Ref to track if the search was triggered by this hook
28
28
const triggeredByHookRef = useRef ( false ) ;
29
29
const searchTriggeredRef = useRef ( false ) ;
30
- const hasItemBeenAddedRef = useRef ( false ) ;
31
30
const previousSearchResults = usePrevious ( searchResults ?. data ) ;
32
31
const [ newSearchResultKey , setNewSearchResultKey ] = useState < string | null > ( null ) ;
33
32
const highlightedIDs = useRef < Set < string > > ( new Set ( ) ) ;
@@ -52,11 +51,6 @@ function useSearchHighlightAndScroll({searchResults, transactions, previousTrans
52
51
const hasTransactionChange = ! isEqual ( transactionIDList , previousTransactionIDList ) ;
53
52
const hasReportActionChange = ! isEqual ( reportActionIDList , previousReportActionIDList ) ;
54
53
55
- // We only want to highlight new items only if addition of transactions or report actions triggered the search.
56
- // This is because on deletion of items sometimes the BE returns old items in place of the deleted ones
57
- // but we don't want to highlight these old items although they are new to the current search result.
58
- hasItemBeenAddedRef . current = isChat ? reportActionIDList . length > previousReportActionIDList . length : transactionIDList . length > previousTransactionIDList . length ;
59
-
60
54
// Check if there is a change in transaction or report action list
61
55
if ( ( ! isChat && hasTransactionChange ) || ( isChat && hasReportActionChange ) ) {
62
56
// Set the flag indicating the search is triggered by the hook
@@ -98,7 +92,7 @@ function useSearchHighlightAndScroll({searchResults, transactions, previousTrans
98
92
// Find new report action IDs that are not in the previousReportActionIDs and not already highlighted
99
93
const newReportActionIDs = currentReportActionIDs . filter ( ( id ) => ! previousReportActionIDs . includes ( id ) && ! highlightedIDs . current . has ( id ) ) ;
100
94
101
- if ( ! triggeredByHookRef . current || newReportActionIDs . length === 0 || ! hasItemBeenAddedRef . current ) {
95
+ if ( ! triggeredByHookRef . current || newReportActionIDs . length === 0 ) {
102
96
return ;
103
97
}
104
98
@@ -114,7 +108,7 @@ function useSearchHighlightAndScroll({searchResults, transactions, previousTrans
114
108
// Find new transaction IDs that are not in the previousTransactionIDs and not already highlighted
115
109
const newTransactionIDs = currentTransactionIDs . filter ( ( id ) => ! previousTransactionIDs . includes ( id ) && ! highlightedIDs . current . has ( id ) ) ;
116
110
117
- if ( ! triggeredByHookRef . current || newTransactionIDs . length === 0 || ! hasItemBeenAddedRef . current ) {
111
+ if ( ! triggeredByHookRef . current || newTransactionIDs . length === 0 ) {
118
112
return ;
119
113
}
120
114
0 commit comments