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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
correctly bind typeahead even if no getOptionsFn
Oliver Günther21d9d5858ed7
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.htmlindex 63219386322..3cbf8a5ac3d 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@@ -4,7 +4,7 @@[(ngModel)]="model"[items]="results$ | async"[ngClass]="classes"- [typeahead]="boundTypeahead"+ [typeahead]="typeahead"[clearOnBackspace]="clearOnBackspace"[clearSearchOnAdd]="clearSearchOnAdd"[hideSelected]="hideSelected"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.tsindex b61e8520780..59c6fb187fe 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@@ -176,10 +176,7 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements OnI@Input() public keyDownFn ? = ():boolean => true;- @Input() public typeahead:BehaviorSubject<string|null> = new BehaviorSubject(null);-- // We only bind the typeahead to ng-select if we filter values from the backend- public boundTypeahead:Subject<string|null>;+ @Input() public typeahead:BehaviorSubject<string|null>|null;// a function for setting the options of ng-select@Input() public getOptionsFn:(searchTerm:string) => Observable<unknown>;@@ -241,7 +238,7 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements OnIngOnInit() {if (!!this.getOptionsFn || this.defaultData) {- this.boundTypeahead = this.typeahead;+ this.typeahead = new BehaviorSubject<string|null>(null);}}@@ -260,32 +257,11 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements OnIsetTimeout(() => {this.results$ = merge(this.items$,- this.typeahead.pipe(- filter(() => !!(this.defaultData || this.getOptionsFn)),- filter((val) => val !== null),- distinctUntilChanged(),- debounceTime(250),- tap(() => this.loading$.next(true)),- switchMap((queryString:string) => {- if (this.defaultData) {- return this.opAutocompleterService.loadData(queryString, this.resource, this.filters, this.searchKey);- }-- if (this.getOptionsFn) {- return this.getOptionsFn(queryString);- }-- return NEVER;- }),- tap(- () => this.loading$.next(false),- () => this.loading$.next(false),- ),- ),+ this.autocompleteInputStream(),);if (this.fetchDataDirectly) {- this.typeahead.next('');+ this.typeahead?.next('');}if (this.openDirectly) {@@ -312,7 +288,7 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements OnIpublic opened(_:unknown) { // eslint-disable-line no-unused-vars// Re-search for empty value as search value gets removed- this.typeahead.next('');+ this.typeahead?.next('');this.repositionDropdown();this.open.emit();}@@ -384,4 +360,33 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements OnIpublic highlighting(property:string, id:string) {return Highlighting.inlineClass(property, id);}++ private autocompleteInputStream():Observable<unknown> {+ if (!this.typeahead) {+ return NEVER;+ }++ return this.typeahead.pipe(+ filter(() => !!(this.defaultData || this.getOptionsFn)),+ filter((val) => val !== null),+ distinctUntilChanged(),+ debounceTime(250),+ tap(() => this.loading$.next(true)),+ switchMap((queryString:string) => {+ if (this.defaultData) {+ return this.opAutocompleterService.loadData(queryString, this.resource, this.filters, this.searchKey);+ }++ if (this.getOptionsFn) {+ return this.getOptionsFn(queryString);+ }++ return NEVER;+ }),+ tap(+ () => this.loading$.next(false),+ () => this.loading$.next(false),+ ),+ );+ }}