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

Avoid debouncing the initial request

Christophe Bliard9aa36e54dbc4
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 66be53b2375..af18ade7ed5 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
@@ -27,9 +27,11 @@ import {
NEVER,
Observable,
of,
+ timer,
Subject,
} from 'rxjs';
import {
+ debounce,
debounceTime,
distinctUntilChanged,
filter,
@@ -226,6 +228,8 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements OnI
@ContentChild(OpAutocompleterFooterTemplateDirective, { read: TemplateRef })
footerTemplate:TemplateRef<any>;
+ initialDebounce = true;
+
constructor(
readonly opAutocompleterService:OpAutocompleterService,
readonly cdRef:ChangeDetectorRef,
@@ -369,8 +373,8 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements OnI
return this.typeahead.pipe(
filter(() => !!(this.defaultData || this.getOptionsFn)),
distinctUntilChanged(),
- debounceTime(250),
tap(() => this.loading$.next(true)),
+ debounce(() => timer(this.getDebounceTimeout())),
switchMap((queryString:string) => {
if (this.defaultData) {
return this.opAutocompleterService.loadData(queryString, this.resource, this.filters, this.searchKey);
@@ -388,4 +392,12 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements OnI
),
);
}
+
+ private getDebounceTimeout():number {
+ if (this.initialDebounce) {
+ this.initialDebounce = false;
+ return 0;
+ }
+ return 250;
+ }
}