@@ -21,7 +21,7 @@ import {
21
21
TypedSimpleChanges ,
22
22
} from '@hypertrace/common' ;
23
23
import { combineLatest , Observable , Subject , timer } from 'rxjs' ;
24
- import { debounce , map } from 'rxjs/operators' ;
24
+ import { debounce , debounceTime , map } from 'rxjs/operators' ;
25
25
import { IconSize } from '../icon/icon-size' ;
26
26
import { PopoverService } from '../popover/popover.service' ;
27
27
import { PopoverRef } from '../popover/popover-ref' ;
@@ -111,7 +111,7 @@ export class SearchBoxComponent implements OnInit, OnChanges {
111
111
public searchMode : SearchBoxEmitMode = SearchBoxEmitMode . Incremental ;
112
112
113
113
@Input ( )
114
- public enableSearchHistory : boolean = false ; // Experimental
114
+ public enableSearchHistory : boolean = true ;
115
115
116
116
@Input ( )
117
117
public collapsable : boolean = false ;
@@ -137,6 +137,8 @@ export class SearchBoxComponent implements OnInit, OnChanges {
137
137
138
138
public popover ?: PopoverRef ;
139
139
140
+ public defaultSearchHistoryDebounceTime = 1000 ;
141
+
140
142
public constructor (
141
143
private readonly cdr : ChangeDetectorRef ,
142
144
private readonly host : ElementRef ,
@@ -222,7 +224,7 @@ export class SearchBoxComponent implements OnInit, OnChanges {
222
224
this . subscriptionLifecycle . unsubscribe ( ) ;
223
225
this . subscriptionLifecycle . add (
224
226
combineLatest ( [ this . debouncedValueSubject , this . getDebounceTime ( ) ] )
225
- . pipe ( debounce ( ( [ _ , debounceTime ] ) => timer ( debounceTime ) ) )
227
+ . pipe ( debounce ( ( [ _ , valueDebounceTime ] ) => timer ( valueDebounceTime ) ) )
226
228
. subscribe ( ( [ value , _ ] ) => this . valueChange . emit ( value ) ) ,
227
229
) ;
228
230
}
@@ -260,12 +262,27 @@ export class SearchBoxComponent implements OnInit, OnChanges {
260
262
} ) ,
261
263
) ;
262
264
265
+ // Use the default search history debounce time if the value debounce time is less than the default
266
+ const searchHistoryDebounce =
267
+ this . debounceTime && this . debounceTime > this . defaultSearchHistoryDebounceTime
268
+ ? 0
269
+ : this . defaultSearchHistoryDebounceTime ;
270
+
263
271
this . subscriptionLifecycle . add (
264
- this . valueChange . asObservable ( ) . subscribe ( emittedValue => {
265
- if ( ! isEmpty ( emittedValue ) ) {
266
- this . lastEmittedValues = [ emittedValue , ...this . lastEmittedValues ] ;
267
- }
268
- } ) ,
272
+ searchHistoryDebounce > 0
273
+ ? this . valueChange
274
+ . asObservable ( )
275
+ . pipe ( debounceTime ( searchHistoryDebounce ) )
276
+ . subscribe ( emittedValue => {
277
+ if ( ! isEmpty ( emittedValue ) ) {
278
+ this . lastEmittedValues = [ emittedValue , ...this . lastEmittedValues ] ;
279
+ }
280
+ } )
281
+ : this . valueChange . asObservable ( ) . subscribe ( emittedValue => {
282
+ if ( ! isEmpty ( emittedValue ) ) {
283
+ this . lastEmittedValues = [ emittedValue , ...this . lastEmittedValues ] ;
284
+ }
285
+ } ) ,
269
286
) ;
270
287
}
271
288
@@ -296,7 +313,7 @@ export class SearchBoxComponent implements OnInit, OnChanges {
296
313
}
297
314
298
315
private handleSearchHistoryOnInputBlur ( ) : void {
299
- this . searchHistory = [ ...uniq ( this . lastEmittedValues ) , ...this . searchHistory ] ;
316
+ this . searchHistory = uniq ( [ ...this . lastEmittedValues , ...this . searchHistory ] ) ;
300
317
this . filteredSearchHistory = [ ...this . searchHistory ] ;
301
318
this . lastEmittedValues = [ ] ;
302
319
}
0 commit comments