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
Observe changes in the localstorage for recently viewed
Benjamin Bädorf35d8c4709664
diff --git a/frontend/src/app/core/global_search/input/global-search-input.component.ts b/frontend/src/app/core/global_search/input/global-search-input.component.tsindex 967ee7c3799..c6e76ada203 100644--- a/frontend/src/app/core/global_search/input/global-search-input.component.ts+++ b/frontend/src/app/core/global_search/input/global-search-input.component.ts@@ -39,7 +39,7 @@ import {ViewEncapsulation,} from '@angular/core';import { BehaviorSubject, Observable, of } from 'rxjs';-import { first, map, tap } from 'rxjs/operators';+import { first, map, mergeMap, switchMap, tap } from 'rxjs/operators';import { GlobalSearchService } from 'core-app/core/global_search/services/global-search.service';import { isClickedWithModifier } from 'core-app/shared/helpers/link-handling/link-handling';import { Highlighting } from 'core-app/features/work-packages/components/wp-fast-table/builders/highlighting/highlighting.functions';@@ -229,8 +229,6 @@ export class GlobalSearchInputComponent implements AfterViewInit, OnDestroy {public onFocus():void {this.expanded = true;this.toggleTopMenuClass();- this.ngSelectComponent.typeahead?.next(' ');- this.ngSelectComponent.typeahead?.next('');this.ngSelectComponent.openSelect();}@@ -295,14 +293,18 @@ export class GlobalSearchInputComponent implements AfterViewInit, OnDestroy {private autocompleteWorkPackages(query:string):Observable<(WorkPackageResource|SearchOptionItem)[]> {if (!query) {- const wpIds = this.recentItemsService.getAll();- // It is needed, because otherwise we get infinite spin running- // in the searchbar with no recent workpackages IDs inside localStorage- if(wpIds.length === 0) {- return of([]);- }- void this.apiV3Service.work_packages.requireAll(wpIds);- return this.apiV3Service.work_packages.cache.observeSome(wpIds);+ return this.recentItemsService.recentItems$.pipe(+ switchMap((wpIds) => {+ // It is needed, because otherwise we get infinite spin running+ // in the searchbar with no recent workpackages IDs inside localStorage+ if(wpIds.length === 0) {+ return of([]);+ }++ void this.apiV3Service.work_packages.requireAll(wpIds);+ return this.apiV3Service.work_packages.cache.observeSome(wpIds);+ })+ );}// Reset the currently selected item.diff --git a/frontend/src/app/core/recent-items.service.ts b/frontend/src/app/core/recent-items.service.tsindex 9eff6fc322b..a6c5de44538 100644--- a/frontend/src/app/core/recent-items.service.ts+++ b/frontend/src/app/core/recent-items.service.ts@@ -27,9 +27,12 @@//++import { Injectable } from '@angular/core';+import { BehaviorSubject } from 'rxjs';@Injectable()export class RecentItemsService {+ recentItems$ = new BehaviorSubject(this.getAll());+add(id: string): void {let wps = JSON.parse(window.OpenProject.guardedLocalStorage('recent') || '[]')@@ -39,6 +42,7 @@ export class RecentItemsService {wps = wps.slice(0, 5);}window.localStorage.setItem('recent', JSON.stringify(wps));+ this.recentItems$.next(wps);}getAll(): string[] {