Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Make debounce time configurable

Alexander Brandon Coles1e54f2f7f380
diff --git a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts
index 240dd5facbf..87b2c56212a 100644
--- a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts
+++ b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts
@@ -23,8 +23,8 @@ import {
ViewContainerRef,
} from '@angular/core';
import { DropdownPosition, NgSelectComponent } from '@ng-select/ng-select';
-import { BehaviorSubject, merge, NEVER, Observable, of, Subject, timer } from 'rxjs';
-import { debounce, distinctUntilChanged, filter, switchMap, tap, map } from 'rxjs/operators';
+import { BehaviorSubject, merge, NEVER, Observable, of, Subject } from 'rxjs';
+import { debounceTime, distinctUntilChanged, filter, switchMap, tap, map } from 'rxjs/operators';
import { AddTagFn, GroupValueFn } from '@ng-select/ng-select/lib/ng-select.component';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
@@ -228,6 +228,8 @@ export class OpAutocompleterComponent<T extends IAutocompleteItem = IAutocomplet
@Input() public relations?:boolean = false;
+ @Input() public debounceTimeMs:number = 250;
+
@Output() public open = new EventEmitter<unknown>();
@Output() public close = new EventEmitter<unknown>();
@@ -284,8 +286,6 @@ export class OpAutocompleterComponent<T extends IAutocompleteItem = IAutocomplet
footerTemplate:TemplateRef<Element>;
- initialDebounce = true;
-
private opAutocompleterService = new OpAutocompleterService(this.apiV3Service);
constructor(
@@ -466,7 +466,7 @@ export class OpAutocompleterComponent<T extends IAutocompleteItem = IAutocomplet
filter(() => !!(this.defaultData || this.getOptionsFn)),
distinctUntilChanged(),
tap(() => this.loading$.next(true)),
- debounce(() => timer(this.getDebounceTimeout())),
+ debounceTime(this.debounceTimeMs),
switchMap((queryString:string) => {
if (this.relations && this.url) {
return this.fetchFromUrl(queryString);
@@ -522,14 +522,6 @@ export class OpAutocompleterComponent<T extends IAutocompleteItem = IAutocomplet
);
}
- private getDebounceTimeout():number {
- if (this.initialDebounce) {
- this.initialDebounce = false;
- return 0;
- }
- return 250;
- }
-
writeValue(value:T|T[]|null):void {
this.model = value;
}