@@ -21,7 +21,7 @@ import {
2121 TypedSimpleChanges ,
2222} from '@hypertrace/common' ;
2323import { combineLatest , Observable , Subject , timer } from 'rxjs' ;
24- import { debounce , map } from 'rxjs/operators' ;
24+ import { debounce , debounceTime , map } from 'rxjs/operators' ;
2525import { IconSize } from '../icon/icon-size' ;
2626import { PopoverService } from '../popover/popover.service' ;
2727import { PopoverRef } from '../popover/popover-ref' ;
@@ -111,7 +111,7 @@ export class SearchBoxComponent implements OnInit, OnChanges {
111111 public searchMode : SearchBoxEmitMode = SearchBoxEmitMode . Incremental ;
112112
113113 @Input ( )
114- public enableSearchHistory : boolean = false ; // Experimental
114+ public enableSearchHistory : boolean = true ;
115115
116116 @Input ( )
117117 public collapsable : boolean = false ;
@@ -137,6 +137,8 @@ export class SearchBoxComponent implements OnInit, OnChanges {
137137
138138 public popover ?: PopoverRef ;
139139
140+ public defaultSearchHistoryDebounceTime = 1000 ;
141+
140142 public constructor (
141143 private readonly cdr : ChangeDetectorRef ,
142144 private readonly host : ElementRef ,
@@ -222,7 +224,7 @@ export class SearchBoxComponent implements OnInit, OnChanges {
222224 this . subscriptionLifecycle . unsubscribe ( ) ;
223225 this . subscriptionLifecycle . add (
224226 combineLatest ( [ this . debouncedValueSubject , this . getDebounceTime ( ) ] )
225- . pipe ( debounce ( ( [ _ , debounceTime ] ) => timer ( debounceTime ) ) )
227+ . pipe ( debounce ( ( [ _ , valueDebounceTime ] ) => timer ( valueDebounceTime ) ) )
226228 . subscribe ( ( [ value , _ ] ) => this . valueChange . emit ( value ) ) ,
227229 ) ;
228230 }
@@ -260,12 +262,27 @@ export class SearchBoxComponent implements OnInit, OnChanges {
260262 } ) ,
261263 ) ;
262264
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+
263271 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+ } ) ,
269286 ) ;
270287 }
271288
@@ -296,7 +313,7 @@ export class SearchBoxComponent implements OnInit, OnChanges {
296313 }
297314
298315 private handleSearchHistoryOnInputBlur ( ) : void {
299- this . searchHistory = [ ...uniq ( this . lastEmittedValues ) , ...this . searchHistory ] ;
316+ this . searchHistory = uniq ( [ ...this . lastEmittedValues , ...this . searchHistory ] ) ;
300317 this . filteredSearchHistory = [ ...this . searchHistory ] ;
301318 this . lastEmittedValues = [ ] ;
302319 }
0 commit comments