diff --git a/src/app/shared/components/project-selector/project-selector.component.ts b/src/app/shared/components/project-selector/project-selector.component.ts index b9a4ddf78..74465a8a3 100644 --- a/src/app/shared/components/project-selector/project-selector.component.ts +++ b/src/app/shared/components/project-selector/project-selector.component.ts @@ -84,21 +84,30 @@ export class ProjectSelectorComponent { effect(() => { const currentUser = this.currentUser(); if (currentUser) { - this.actions.getProjects(currentUser.id); + this.fetchProjects(); } }); effect(() => { const isProjectsLoading = this.isProjectsLoading(); const projects = this.projects(); - const excludeIds = this.excludeProjectIds(); if (isProjectsLoading || !projects.length) { - this.projectsOptions.set([]); return; } this.projectsLoaded.emit(projects); + }); + + effect(() => { + const isProjectsLoading = this.isProjectsLoading(); + const projects = this.projects(); + const excludeIds = this.excludeProjectIds(); + + if (isProjectsLoading || !projects.length) { + this.projectsOptions.set([]); + return; + } const excludeSet = new Set(excludeIds); const availableProjects = projects.filter((project) => !excludeSet.has(project.id)); @@ -116,15 +125,22 @@ export class ProjectSelectorComponent { this.filterSubject .pipe(debounceTime(300), distinctUntilChanged(), takeUntilDestroyed(this.destroyRef)) .subscribe((filterValue) => { - const currentUser = this.currentUser(); - if (!currentUser) return; + this.fetchProjects(filterValue); + }); + } - const params: Record = { - 'filter[current_user_permissions]': 'admin', - 'filter[title]': filterValue, - }; + private fetchProjects(filterTitle?: string): void { + const currentUser = this.currentUser(); + if (!currentUser) return; - this.actions.getProjects(currentUser.id, params); - }); + const params: Record = { + 'filter[current_user_permissions]': 'admin', + }; + + if (filterTitle && filterTitle.trim()) { + params['filter[title]'] = filterTitle; + } + + this.actions.getProjects(currentUser.id, params); } }