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
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<div class="list-item" [class.disabled]="disabled">
<div
class="list-item"
[class.disabled]="disabled"
[class.no-actions-menu]="!actions().length">
<ng-content></ng-content>
<button
*ngIf="actions().length"
[disabled]="disabled"
fontSet="material-symbols-outlined"
mat-icon-button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<button
mat-flat-button
class="discard-button"
[disabled]="profileHasNoChanges() || profileForm.pristine"
[disabled]="isDiscardDisabled"
(click)="onDiscardClick()">
Discard
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ export class ProfileFormComponent implements OnInit, AfterViewInit {
);
}

get isDiscardDisabled(): boolean {
return (
(this.profileHasNoChanges() || this.profileForm.pristine) &&
!this.copyProfile
);
}

profileHasNoChanges() {
const oldProfile = this.profile;
const newProfile = oldProfile
Expand Down Expand Up @@ -384,6 +391,11 @@ export class ProfileFormComponent implements OnInit, AfterViewInit {
}
this.changeProfile = true;
this.store.updateSelectedProfile(profile);
} else {
if (this.copyProfile?.name !== this.profile?.name) {
this.copyProfile = null;
this.cd.detectChanges();
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ $profile-item-container-gap: 8px;
color: colors.$grey-800;
}

:host-context(.no-actions-menu) {
.profile-item-info .profile-item-name {
max-width: 260px;
}
}

.profile-item-info {
cursor: pointer;
display: grid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,25 +255,6 @@ describe('RiskAssessmentComponent', () => {
).toHaveBeenCalledWith(null);
expect(component.isOpenProfileForm).toBeFalse();
}));

it('should remove copy and close form when unsaved copy is deleted', fakeAsync(() => {
spyOn(component.dialog, 'open').and.returnValue({
afterClosed: () => of(true),
} as MatDialogRef<typeof SimpleDialogComponent>);
component.isCopyProfile = true;
component.deleteProfile(
DRAFT_COPY_PROFILE_MOCK,
[DRAFT_COPY_PROFILE_MOCK, PROFILE_MOCK],
DRAFT_COPY_PROFILE_MOCK
);
tick();

expect(mockRiskAssessmentStore.removeProfile).toHaveBeenCalled();
expect(
mockRiskAssessmentStore.updateSelectedProfile
).toHaveBeenCalledWith(null);
expect(component.isOpenProfileForm).toBeFalse();
}));
});

describe('#openForm', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,26 +189,15 @@ export class RiskAssessmentComponent
.pipe(takeUntil(this.destroy$))
.subscribe(deleteProfile => {
if (deleteProfile) {
if (
profile &&
profile.status === ProfileStatus.DRAFT &&
!profile.created
) {
this.deleteCopy(profile, profiles);
this.closeFormAfterDelete(profile.name, selectedProfile);
this.focusAddButton();
return;
} else {
this.store.deleteProfile({
name: profileName,
onDelete: (idx = 0) => {
this.closeFormAfterDelete(profileName, selectedProfile);
timer(100).subscribe(() => {
this.setFocus(idx);
});
},
});
}
this.store.deleteProfile({
name: profileName,
onDelete: (idx = 0) => {
this.closeFormAfterDelete(profileName, selectedProfile);
timer(100).subscribe(() => {
this.setFocus(idx);
});
},
});
} else {
this.store.setFocusOnSelectedProfile();
}
Expand Down Expand Up @@ -298,11 +287,12 @@ export class RiskAssessmentComponent

actions(actions: EntityAction[]) {
return (profile: Profile) => {
// expired profiles or unsaved copy of profile can only be removed
if (
profile.status === ProfileStatus.EXPIRED ||
(profile.status === ProfileStatus.DRAFT && !profile.created)
) {
// unsaved copy of profile can't have any action
if (profile.status === ProfileStatus.DRAFT && !profile.created) {
return [];
}
// expired profiles can only be removed
if (profile.status === ProfileStatus.EXPIRED) {
return [{ action: ProfileAction.Delete, icon: 'delete' }];
}
return actions;
Expand Down