Skip to content

Commit a50d2ed

Browse files
committed
added missing susbcription and clean up #449
1 parent b72d157 commit a50d2ed

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/app/modules/data-query/data-query/data-selection/action-bar/data-selection-action-bar.component.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { CCDLUploadService } from 'src/app/service/Upload/CCDLUpload.service';
22
import { Component, ElementRef, OnDestroy, OnInit } from '@angular/core';
3+
import { DataSelectionFactoryService } from 'src/app/service/DataSelection/DataSelection.factory.service';
34
import { DataSelectionProviderService } from 'src/app/modules/data-selection/services/DataSelectionProvider.service';
45
import { DownloadCRDTLService } from 'src/app/service/Download/DownloadCRDTL.service';
56
import { DownloadDataSelectionComponent } from '../download-data-selection/download-data-selection.component';
@@ -9,8 +10,6 @@ import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
910
import { NavigationHelperService } from 'src/app/service/NavigationHelper.service';
1011
import { Observable, Subscription } from 'rxjs';
1112
import { SnackbarService } from 'src/app/shared/service/Snackbar/Snackbar.service';
12-
import { DataSelectionFactoryService } from 'src/app/service/DataSelection/DataSelection.factory.service';
13-
import { is } from 'cypress/types/bluebird';
1413

1514
@Component({
1615
selector: 'num-data-selection-action-bar',
@@ -25,6 +24,8 @@ export class DataSelectionActionBarComponent implements OnDestroy, OnInit {
2524

2625
downloadSubscription: Subscription;
2726

27+
mainProfileSubscription: Subscription;
28+
2829
constructor(
2930
public elementRef: ElementRef,
3031
private dataSelectionProviderService: DataSelectionProviderService,
@@ -45,17 +46,17 @@ export class DataSelectionActionBarComponent implements OnDestroy, OnInit {
4546
}
4647

4748
ngOnDestroy(): void {
48-
if (this.subscription) {
49-
this.subscription?.unsubscribe();
50-
}
49+
this.mainProfileSubscription?.unsubscribe();
50+
this.subscription?.unsubscribe();
5151
}
5252

5353
public editDataSelection() {
5454
this.navigationHelperService.navigateToDataSelectionEditor();
5555
}
5656

5757
public createNewDataSelection() {
58-
this.dataSelectionFactoryService.instantiate();
58+
this.mainProfileSubscription?.unsubscribe();
59+
this.dataSelectionFactoryService.instantiate().subscribe();
5960
this.navigationHelperService.navigateToDataSelectionSearch();
6061
}
6162

src/app/service/DataSelection/DataSelection.factory.service.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { DataSelection } from 'src/app/model/DataSelection/DataSelection';
22
import { DataSelectionMainProfileInitializerService } from '../DataSelectionMainProfileInitializerService';
3+
import { DataSelectionProfile } from 'src/app/model/DataSelection/Profile/DataSelectionProfile';
34
import { DataSelectionProviderService } from 'src/app/modules/data-selection/services/DataSelectionProvider.service';
45
import { Injectable } from '@angular/core';
56
import { map, Observable, take } from 'rxjs';
@@ -19,18 +20,15 @@ export class DataSelectionFactoryService {
1920
) {}
2021

2122
public instantiate(): Observable<DataSelection> {
22-
const dataSelection = this.createEmptyDataSelection();
23-
this.setDataSelectionProvider(dataSelection);
24-
2523
return this.loadMainProfile().pipe(
26-
map((mainProfile) => this.setProfileInDataSelection(dataSelection, mainProfile))
24+
map((mainProfile: DataSelectionProfile) => {
25+
const dataSelection = this.setProfileInDataSelection(mainProfile);
26+
this.setDataSelectionProvider(dataSelection);
27+
return dataSelection;
28+
})
2729
);
2830
}
2931

30-
private createEmptyDataSelection(): DataSelection {
31-
return new DataSelection([], uuidv4());
32-
}
33-
3432
private setDataSelectionProvider(dataSelection: DataSelection): void {
3533
this.dataSelectionProviderService.setDataSelectionByUID(
3634
dataSelection.getId(),
@@ -40,10 +38,11 @@ export class DataSelectionFactoryService {
4038
}
4139

4240
private loadMainProfile() {
43-
return this.dataSelectionMainProfileInitializerService.initializePatientProfile().pipe(take(1));
41+
return this.dataSelectionMainProfileInitializerService.initializePatientProfile();
4442
}
4543

46-
private setProfileInDataSelection(dataSelection: DataSelection, mainProfile: any): DataSelection {
44+
private setProfileInDataSelection(mainProfile: DataSelectionProfile): DataSelection {
45+
const dataSelection = new DataSelection([], uuidv4());
4746
dataSelection.setProfiles([mainProfile]);
4847
return dataSelection;
4948
}

0 commit comments

Comments
 (0)