From 43fcbfa55efdfd85746d00eec5e1793d0c0c20f7 Mon Sep 17 00:00:00 2001 From: mdelez <60604010+mdelez@users.noreply.github.com> Date: Fri, 12 Nov 2021 11:10:17 +0100 Subject: [PATCH] fix(fulltext-search): updates the projects list when a new project is created (#586) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: André Kilchenmann --- .../component-communication-event.service.ts | 3 ++- .../projects-list/projects-list.component.ts | 8 +++++++- .../fulltext-search.component.ts | 19 +++++++++++++------ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/app/main/services/component-communication-event.service.ts b/src/app/main/services/component-communication-event.service.ts index c4bc44962a..75bdddc05a 100644 --- a/src/app/main/services/component-communication-event.service.ts +++ b/src/app/main/services/component-communication-event.service.ts @@ -37,5 +37,6 @@ export class EmitEvent { // possible events that can be emitted. export enum Events { loginSuccess, - gravSearchExecuted + gravSearchExecuted, + projectCreated } diff --git a/src/app/system/projects/projects-list/projects-list.component.ts b/src/app/system/projects/projects-list/projects-list.component.ts index f61a69654e..5afb83475b 100644 --- a/src/app/system/projects/projects-list/projects-list.component.ts +++ b/src/app/system/projects/projects-list/projects-list.component.ts @@ -14,6 +14,7 @@ import { CacheService } from 'src/app/main/cache/cache.service'; import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens'; import { DialogComponent } from 'src/app/main/dialog/dialog.component'; import { ErrorHandlerService } from 'src/app/main/error/error-handler.service'; +import { ComponentCommunicationEventService, EmitEvent, Events } from 'src/app/main/services/component-communication-event.service'; import { Session, SessionService } from 'src/app/main/services/session.service'; import { SortingService } from 'src/app/main/services/sorting.service'; @@ -84,7 +85,8 @@ export class ProjectsListComponent implements OnInit { private _dialog: MatDialog, private _router: Router, private _session: SessionService, - private _sortingService: SortingService + private _sortingService: SortingService, + private _componentCommsService: ComponentCommunicationEventService ) { } ngOnInit() { @@ -165,6 +167,10 @@ export class ProjectsListComponent implements OnInit { } else { // update the view this.refreshParent.emit(); + + if (mode === 'createProject') { + this._componentCommsService.emit(new EmitEvent(Events.projectCreated, true)); + } } }); } diff --git a/src/app/workspace/search/fulltext-search/fulltext-search.component.ts b/src/app/workspace/search/fulltext-search/fulltext-search.component.ts index d5452f5b5f..dc64047215 100644 --- a/src/app/workspace/search/fulltext-search/fulltext-search.component.ts +++ b/src/app/workspace/search/fulltext-search/fulltext-search.component.ts @@ -108,7 +108,7 @@ export class FulltextSearchComponent implements OnInit, OnChanges, OnDestroy { projectIri: string; - componentCommsSubscription: Subscription; + componentCommsSubscriptions: Subscription[]= []; // in case of an (api) error error: any; @@ -169,10 +169,17 @@ export class FulltextSearchComponent implements OnInit, OnChanges, OnDestroy { } // in the event of a grav search (advanced or expert search), clear the input field - this.componentCommsSubscription = this._componentCommsService.on( + this.componentCommsSubscriptions.push(this._componentCommsService.on( Events.gravSearchExecuted, () => { this.searchQuery = null; - }); + }) + ); + + this.componentCommsSubscriptions.push(this._componentCommsService.on( + Events.projectCreated, () => { + this.getAllProjects(); + } + )); } ngOnChanges() { @@ -190,9 +197,9 @@ export class FulltextSearchComponent implements OnInit, OnChanges, OnDestroy { } ngOnDestroy() { - // unsubscribe from the componentCommsSubscription when component is destroyed - if (this.componentCommsSubscription !== undefined) { - this.componentCommsSubscription.unsubscribe(); + // unsubscribe from all subscriptions incomponentCommsSubscriptions when component is destroyed + if (this.componentCommsSubscriptions !== undefined) { + this.componentCommsSubscriptions.forEach(sub => sub.unsubscribe()); } }