diff --git a/modules/ui/src/app/mocks/profile.mock.ts b/modules/ui/src/app/mocks/profile.mock.ts index 749db8fb7..a380d49ee 100644 --- a/modules/ui/src/app/mocks/profile.mock.ts +++ b/modules/ui/src/app/mocks/profile.mock.ts @@ -157,7 +157,7 @@ export const RENAME_PROFILE_MOCK = { export const COPY_PROFILE_MOCK: Profile = { name: 'Copy of Primary profile', - status: ProfileStatus.VALID, + status: ProfileStatus.COPY, created: '2025-05-23 12:38:26', questions: [ { @@ -185,7 +185,7 @@ export const COPY_PROFILE_MOCK: Profile = { export const DRAFT_COPY_PROFILE_MOCK: Profile = { name: 'Copy of Primary profile', - status: ProfileStatus.DRAFT, + status: ProfileStatus.COPY, questions: [ { question: 'What is the email of the device owner(s)?', diff --git a/modules/ui/src/app/model/profile.ts b/modules/ui/src/app/model/profile.ts index fcf2f8207..94b9f81ee 100644 --- a/modules/ui/src/app/model/profile.ts +++ b/modules/ui/src/app/model/profile.ts @@ -41,6 +41,7 @@ export enum ProfileStatus { VALID = 'Valid', DRAFT = 'Draft', EXPIRED = 'Expired', + COPY = 'Copy', } export interface RiskResultClassName { diff --git a/modules/ui/src/app/pages/risk-assessment/profile-form/profile-form.component.spec.ts b/modules/ui/src/app/pages/risk-assessment/profile-form/profile-form.component.spec.ts index c10d8b903..413b238c2 100644 --- a/modules/ui/src/app/pages/risk-assessment/profile-form/profile-form.component.spec.ts +++ b/modules/ui/src/app/pages/risk-assessment/profile-form/profile-form.component.spec.ts @@ -441,10 +441,9 @@ describe('ProfileFormComponent', () => { }); }); - it('should open dialog if isCopyProfile is true, dialog confirms, and emit deleteCopy', done => { + it('should open dialog if status is COPY, dialog confirms, and emit deleteCopy', done => { spyOn(component, 'profileHasNoChanges').and.returnValue(false); component.profileForm.markAsDirty(); - component.isCopyProfile = true; component.selectedProfile = { ...COPY_PROFILE_MOCK }; openDialogSpy.and.returnValue(of(true)); @@ -459,11 +458,10 @@ describe('ProfileFormComponent', () => { }); }); - it('should open dialog if isCopyProfile is true, and dialog cancels', done => { + it('should open dialog if status is COPY, and dialog cancels', done => { spyOn(component, 'profileHasNoChanges').and.returnValue(false); component.profileForm.markAsDirty(); - component.isCopyProfile = true; - component.selectedProfile = { ...PROFILE_MOCK }; + component.selectedProfile = { ...COPY_PROFILE_MOCK }; openDialogSpy.and.returnValue(of(false)); component.close().subscribe(result => { diff --git a/modules/ui/src/app/pages/risk-assessment/profile-form/profile-form.component.ts b/modules/ui/src/app/pages/risk-assessment/profile-form/profile-form.component.ts index 32eaf0407..0b9730b41 100644 --- a/modules/ui/src/app/pages/risk-assessment/profile-form/profile-form.component.ts +++ b/modules/ui/src/app/pages/risk-assessment/profile-form/profile-form.component.ts @@ -93,7 +93,6 @@ export class ProfileFormComponent implements OnInit, AfterViewInit { dialog = inject(MatDialog); readonly autosize = viewChildren(CdkTextareaAutosize); @Input() profileFormat!: ProfileFormat[]; - @Input() isCopyProfile!: boolean; @Input() set profiles(profiles: Profile[]) { this.profileList = profiles; @@ -106,29 +105,27 @@ export class ProfileFormComponent implements OnInit, AfterViewInit { } @Input() set selectedProfile(profile: Profile | null) { - if (profile?.name.trim().startsWith('Copy')) { - this.copyProfile = profile; - } if (this.changeProfile || this.profileHasNoChanges()) { this.changeProfile = false; this.profile = profile; if (profile && this.nameControl) { this.updateNameValidator(profile); this.fillProfileForm(this.profileFormat, profile); - if (this.isCopyProfile && this.copyProfile) { - this.setCopy.emit(this.copyProfile); - } } else { this.profileForm.reset(); - if (this.copyProfile) { - this.setCopy.emit(this.copyProfile); - } } } else if (this.profile != profile) { // prevent select profile before user confirmation this.store.updateSelectedProfile(this.profile); this.openCloseDialogToChangeProfile(profile); } + if ( + profile?.status === ProfileStatus.COPY && + this.copyProfile !== profile // check if copy already set + ) { + this.copyProfile = profile; + this.setCopy.emit(this.copyProfile); + } } get selectedProfile() { @@ -408,7 +405,7 @@ export class ProfileFormComponent implements OnInit, AfterViewInit { const request: any = { questions: [], }; - if (profile && !this.isCopyProfile) { + if (profile && profile.status !== ProfileStatus.COPY) { request.name = profile.name; request.rename = this.nameControl?.value?.trim(); } else { diff --git a/modules/ui/src/app/pages/risk-assessment/profile-item/profile-item.component.html b/modules/ui/src/app/pages/risk-assessment/profile-item/profile-item.component.html index 90d66d06a..032bc986b 100644 --- a/modules/ui/src/app/pages/risk-assessment/profile-item/profile-item.component.html +++ b/modules/ui/src/app/pages/risk-assessment/profile-item/profile-item.component.html @@ -46,7 +46,10 @@ check_circle { component.form(), 'openCloseDialog' ).and.returnValue(of(true)); - component.isCopyProfile = true; component.discard(DRAFT_COPY_PROFILE_MOCK, [DRAFT_COPY_PROFILE_MOCK]); tick(100); })); @@ -481,7 +480,6 @@ class FakeProfileItemComponent { }) class FakeProfileFormComponent { @Input() profiles!: Profile[]; - @Input() isCopyProfile!: boolean; @Input() selectedProfile!: Profile; @Input() profileFormat!: ProfileFormat[]; } diff --git a/modules/ui/src/app/pages/risk-assessment/risk-assessment.component.ts b/modules/ui/src/app/pages/risk-assessment/risk-assessment.component.ts index 125066609..7c583c511 100644 --- a/modules/ui/src/app/pages/risk-assessment/risk-assessment.component.ts +++ b/modules/ui/src/app/pages/risk-assessment/risk-assessment.component.ts @@ -107,7 +107,6 @@ export class RiskAssessmentComponent viewModel$ = this.store.viewModel$; isOpenProfileForm = false; - isCopyProfile = false; canDeactivate(): Observable { const form = this.form(); @@ -153,7 +152,6 @@ export class RiskAssessmentComponent } async copyProfileAndOpenForm(profile: Profile) { - this.isCopyProfile = true; const copyOfProfile = this.getCopyOfProfile(profile); await this.openForm(copyOfProfile); } @@ -163,7 +161,7 @@ export class RiskAssessmentComponent copyOfProfile.name = this.getCopiedProfileName(profile.name); delete copyOfProfile.created; // new profile is not create yet delete copyOfProfile.risk; - copyOfProfile.status = ProfileStatus.DRAFT; + copyOfProfile.status = ProfileStatus.COPY; return copyOfProfile; } @@ -213,7 +211,7 @@ export class RiskAssessmentComponent }); } else if ( this.compareProfiles(profile, selectedProfile) || - this.isCopyProfile + selectedProfile.status === ProfileStatus.COPY ) { this.saveProfile(profile, this.store.setFocusOnSelectedProfile); } else { @@ -244,10 +242,9 @@ export class RiskAssessmentComponent .pipe(takeUntil(this.destroy$)) .subscribe(close => { if (close) { - if (selectedProfile && this.isCopyProfile) { + if (selectedProfile?.status === ProfileStatus.COPY) { this.deleteCopy(selectedProfile, profiles); } - this.isCopyProfile = false; this.isOpenProfileForm = false; this.store.updateSelectedProfile(null); this.cd.markForCheck(); @@ -276,7 +273,6 @@ export class RiskAssessmentComponent } deleteCopy(copyOfProfile: Profile, profiles: Profile[]) { - this.isCopyProfile = false; this.store.removeProfile(copyOfProfile.name, profiles); this.cd.markForCheck(); } @@ -288,7 +284,7 @@ export class RiskAssessmentComponent actions(actions: EntityAction[]) { return (profile: Profile) => { // unsaved copy of profile can't have any action - if (profile.status === ProfileStatus.DRAFT && !profile.created) { + if (profile.status === ProfileStatus.COPY) { return []; } // expired profiles can only be removed @@ -387,7 +383,6 @@ export class RiskAssessmentComponent this.store.updateSelectedProfile(profile); }, }); - this.isCopyProfile = false; } private setFocus(index: number): void {