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

Add loading indicator correctly to op-autocompleter

Oliver Günthereb5e70013251
diff --git a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.html b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.html
index d175c281aaa..ff473aa67f5 100644
--- a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.html
+++ b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.html
@@ -10,7 +10,7 @@
[hideSelected]="hideSelected"
[appendTo]="appendTo"
[multiple]="multiple"
- [loading]="isLoading"
+ [loading]="loading$ | async"
[addTag]="addTag"
[virtualScroll]="virtualScroll"
[required]="required"
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 3da2c576169..a8d9ff5b6e6 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
@@ -107,15 +107,15 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aft
@Input() public markFirst ? = true;
- @Input() public placeholder?:string = this.I18n.t('js.autocompleter.placeholder');
+ @Input() public placeholder:string = this.I18n.t('js.autocompleter.placeholder');
- @Input() public notFoundText?:string = this.I18n.t('js.autocompleter.notFoundText');
+ @Input() public notFoundText:string = this.I18n.t('js.autocompleter.notFoundText');
- @Input() public typeToSearchText?:string = this.I18n.t('js.autocompleter.typeToSearchText');
+ @Input() public typeToSearchText:string = this.I18n.t('js.autocompleter.typeToSearchText');
@Input() public addTagText?:string;
- @Input() public loadingText?:string;
+ @Input() public loadingText:string = this.I18n.t('js.ajax.loading');
@Input() public clearAllText?:string;
@@ -204,9 +204,9 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aft
public active:Set<string>;
- public results$:any;
+ public results$:Observable<unknown>;
- public isLoading = false;
+ public loading$ = new Subject<boolean>();
@ViewChild('ngSelectInstance') ngSelectInstance:NgSelectComponent;
@@ -242,6 +242,8 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aft
return;
}
+ this.loading$.subscribe(console.log);
+
this.ngZone.runOutsideAngular(() => {
setTimeout(() => {
this.results$ = merge(
@@ -249,12 +251,14 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aft
this.typeahead.pipe(
distinctUntilChanged(),
debounceTime(250),
+ tap(() => this.loading$.next(true)),
(this.defaultData
? switchMap((queryString) => this.opAutocompleterService.loadData(queryString, this.resource, this.filters, this.searchKey))
: this.getOptionsFn
? switchMap((queryString) => this.getOptionsFn(queryString))
: switchMap(() => NEVER)
),
+ tap(() => this.loading$.next(false)),
),
);