Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions modules/ui/src/app/mocks/profile.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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)?',
Expand Down
1 change: 1 addition & 0 deletions modules/ui/src/app/model/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export enum ProfileStatus {
VALID = 'Valid',
DRAFT = 'Draft',
EXPIRED = 'Expired',
COPY = 'Copy',
}

export interface RiskResultClassName {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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 => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@
check_circle
</mat-icon>
<mat-icon
*ngIf="profile.status === ProfileStatus.DRAFT"
*ngIf="
profile.status === ProfileStatus.DRAFT ||
profile.status === ProfileStatus.COPY
"
svgIcon="draft"
class="profile-draft-icon"></mat-icon>
<mat-icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
<app-profile-form
#profileFormComponent
*ngIf="isOpenProfileForm"
[isCopyProfile]="isCopyProfile"
[selectedProfile]="vm.selectedProfile"
[profiles]="vm.profiles"
[profileFormat]="vm.profileFormat"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,6 @@ describe('RiskAssessmentComponent', () => {
<ProfileFormComponent>component.form(),
'openCloseDialog'
).and.returnValue(of(true));
component.isCopyProfile = true;
component.discard(DRAFT_COPY_PROFILE_MOCK, [DRAFT_COPY_PROFILE_MOCK]);
tick(100);
}));
Expand Down Expand Up @@ -481,7 +480,6 @@ class FakeProfileItemComponent {
})
class FakeProfileFormComponent {
@Input() profiles!: Profile[];
@Input() isCopyProfile!: boolean;
@Input() selectedProfile!: Profile;
@Input() profileFormat!: ProfileFormat[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export class RiskAssessmentComponent

viewModel$ = this.store.viewModel$;
isOpenProfileForm = false;
isCopyProfile = false;

canDeactivate(): Observable<boolean> {
const form = this.form();
Expand Down Expand Up @@ -153,7 +152,6 @@ export class RiskAssessmentComponent
}

async copyProfileAndOpenForm(profile: Profile) {
this.isCopyProfile = true;
const copyOfProfile = this.getCopyOfProfile(profile);
await this.openForm(copyOfProfile);
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -276,7 +273,6 @@ export class RiskAssessmentComponent
}

deleteCopy(copyOfProfile: Profile, profiles: Profile[]) {
this.isCopyProfile = false;
this.store.removeProfile(copyOfProfile.name, profiles);
this.cd.markForCheck();
}
Expand All @@ -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
Expand Down Expand Up @@ -387,7 +383,6 @@ export class RiskAssessmentComponent
this.store.updateSelectedProfile(profile);
},
});
this.isCopyProfile = false;
}

private setFocus(index: number): void {
Expand Down