From 6f225ebc282dbf86b9c29c8b7ab66b69fa4e8722 Mon Sep 17 00:00:00 2001 From: Tristan Eisermann <19949441+Tristan2357@users.noreply.github.com> Date: Wed, 24 Jun 2020 16:50:24 +0200 Subject: [PATCH] TSK-1221: Fix for key not showing after copy of classification --- .../classification-details.component.ts | 50 ++++++++----------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/web/src/app/administration/components/classification-details/classification-details.component.ts b/web/src/app/administration/components/classification-details/classification-details.component.ts index 2b52688f4..fcb3a419d 100644 --- a/web/src/app/administration/components/classification-details/classification-details.component.ts +++ b/web/src/app/administration/components/classification-details/classification-details.component.ts @@ -1,6 +1,6 @@ import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'; import { Select, Store } from '@ngxs/store'; -import { Observable, Subject, zip } from 'rxjs'; +import { Observable, Subject, zip, combineLatest } from 'rxjs'; import { ClassificationDefinition, customFieldCount } from 'app/shared/models/classification-definition'; import { ACTION } from 'app/shared/models/action'; @@ -28,7 +28,7 @@ import { ClassificationCategoryImages, import { CreateClassification, RemoveSelectedClassification, RestoreSelectedClassification, - SaveClassification, + SaveClassification, SelectClassification, SetActiveAction } from '../../../shared/store/classification-store/classification.actions'; @Component({ @@ -73,9 +73,25 @@ export class ClassificationDetailsComponent implements OnInit, OnDestroy { map(customisation => customisation.information), getCustomFields(customFieldCount) ); - this.selectedClassification$.pipe(takeUntil(this.destroy$)).subscribe(data => { - this.fillClassificationInformation(data); - }); + + combineLatest(this.selectedClassification$, this.action$).pipe(takeUntil(this.destroy$)) + .subscribe(([classification, action]) => { + this.action = action; + if (this.action === ACTION.CREATE) { + this.selectedClassification$.pipe(take(1)).subscribe(initialClassification => { + this.classification = { ...initialClassification }; + }); + this.badgeMessage = 'Creating new classification'; + } else if (this.action === ACTION.COPY) { + this.badgeMessage = `Copying Classification: ${this.classification.name}`; + this.classification = { ...classification }; + this.classification.key = null; + } else { + this.badgeMessage = ''; + this.classification = { ...classification }; + } + }); + this.action$.pipe(takeUntil(this.destroy$)).subscribe(data => { this.action = data; if (this.action === ACTION.CREATE) { @@ -91,9 +107,7 @@ export class ClassificationDetailsComponent implements OnInit, OnDestroy { }); this.importExportService.getImportingFinished().pipe(takeUntil(this.destroy$)).subscribe(() => { - if (this.classification.classificationId) { - this.selectClassification(this.classification.classificationId); - } + this.store.dispatch(new SelectClassification(this.classification.classificationId)); }); } @@ -199,26 +213,6 @@ export class ClassificationDetailsComponent implements OnInit, OnDestroy { this.classificationsService.triggerClassificationSaved(); } - private async selectClassification(id: string) { - if (!this.classificationIsAlreadySelected()) { - this.requestInProgress = true; - const classification = await this.classificationsService.getClassification(id).toPromise(); - this.fillClassificationInformation(classification); - this.requestInProgress = false; - } - } - - private classificationIsAlreadySelected(): boolean { - return this.action === ACTION.CREATE && !!this.classification; - } - - private fillClassificationInformation(classificationSelected: ClassificationDefinition) { - this.classification = { ...classificationSelected }; - if (this.action === ACTION.COPY) { - this.classification.key = null; - } - } - private removeClassificationConfirmation() { if (!this.classification || !this.classification.classificationId) { this.notificationsService.triggerError(NOTIFICATION_TYPES.SELECT_ERR);