Skip to content

Commit b7938e3

Browse files
committed
feat(contributors): delete contributors from all components
1 parent a5f1ed2 commit b7938e3

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed

src/app/features/contributors/contributors.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,8 @@ export class ContributorsComponent implements OnInit, OnDestroy {
403403
header: 'project.contributors.removeDialog.title',
404404
width: '448px',
405405
data: {
406-
messageKey: 'project.contributors.removeDialog.message',
407-
messageParams: { name: contributor.fullName },
406+
name: contributor.fullName,
407+
hasChildren: !!this.resourceChildren()?.length,
408408
},
409409
})
410410
.onClose.pipe(

src/app/shared/components/contributors/remove-contributor-dialog/remove-contributor-dialog.component.html

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
<div class="flex flex-column">
2-
<p [innerHTML]="messageKey ? (messageKey | translate: messageParams) : ''"></p>
2+
<p>{{ 'project.contributors.removeDialog.message' | translate: { name: name } }}</p>
33

44
<div class="p-field-radiobutton flex align-items-center mt-3 mb-2">
55
<p-radioButton name="removeMode" [value]="false" [(ngModel)]="selectedOption" inputId="projectOnly">
66
</p-radioButton>
77
<label for="projectOnly" class="ml-2">{{ 'project.contributors.removeDialog.thisProjectOnly' | translate }}</label>
88
</div>
99
<div class="p-field-radiobutton flex align-items-center mb-3">
10-
<p-radioButton name="removeMode" [value]="true" [(ngModel)]="selectedOption" inputId="projectAll"> </p-radioButton>
10+
<p-radioButton
11+
name="removeMode"
12+
[value]="true"
13+
[(ngModel)]="selectedOption"
14+
[disabled]="!hasChildren"
15+
inputId="projectAll">
16+
</p-radioButton>
1117
<label for="projectAll" class="ml-2">{{
1218
'project.contributors.removeDialog.thisProjectAndComponents' | translate
1319
}}</label>
@@ -17,14 +23,14 @@
1723
<p-button
1824
class="w-full"
1925
styleClass="w-full"
20-
(click)="cancel()"
26+
(onClick)="cancel()"
2127
severity="info"
2228
[label]="'common.buttons.cancel' | translate"
2329
></p-button>
2430
<p-button
2531
class="w-full"
2632
styleClass="w-full"
27-
(click)="confirm()"
33+
(onClick)="confirm()"
2834
severity="danger"
2935
[label]="'common.buttons.remove' | translate"
3036
></p-button>

src/app/shared/components/contributors/remove-contributor-dialog/remove-contributor-dialog.component.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1+
import { DynamicDialogConfig, DynamicDialogRef } from 'primeng/dynamicdialog';
2+
13
import { ComponentFixture, TestBed } from '@angular/core/testing';
24

35
import { RemoveContributorDialogComponent } from './remove-contributor-dialog.component';
46

57
describe('RemoveContributorDialogComponent', () => {
68
let component: RemoveContributorDialogComponent;
79
let fixture: ComponentFixture<RemoveContributorDialogComponent>;
10+
let dialogRef: DynamicDialogRef;
811

912
beforeEach(async () => {
13+
dialogRef = { close: jasmine.createSpy('close') } as any;
14+
1015
await TestBed.configureTestingModule({
1116
imports: [RemoveContributorDialogComponent],
17+
providers: [
18+
{ provide: DynamicDialogRef, useValue: dialogRef },
19+
{ provide: DynamicDialogConfig, useValue: { data: { name: 'John Doe', hasChildren: true } } },
20+
],
1221
}).compileComponents();
1322

1423
fixture = TestBed.createComponent(RemoveContributorDialogComponent);
@@ -19,4 +28,19 @@ describe('RemoveContributorDialogComponent', () => {
1928
it('should create', () => {
2029
expect(component).toBeTruthy();
2130
});
31+
32+
it('should pass name from config', () => {
33+
expect(component.name).toBe('John Doe');
34+
});
35+
36+
it('should close dialog with selected option on confirm', () => {
37+
component.selectedOption = true;
38+
component.confirm();
39+
expect(dialogRef.close).toHaveBeenCalledWith(true);
40+
});
41+
42+
it('should close dialog without value on cancel', () => {
43+
component.cancel();
44+
expect(dialogRef.close).toHaveBeenCalledWith();
45+
});
2246
});

src/app/shared/components/contributors/remove-contributor-dialog/remove-contributor-dialog.component.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ export class RemoveContributorDialogComponent {
1919
readonly config = inject(DynamicDialogConfig);
2020
selectedOption = false;
2121

22-
get messageKey(): string | undefined {
23-
return this.config?.data?.messageKey as string | undefined;
22+
get name(): string | undefined {
23+
return this.config?.data?.name;
2424
}
2525

26-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
27-
get messageParams(): any {
28-
return this.config?.data?.messageParams;
26+
get hasChildren(): boolean {
27+
return this.config?.data?.hasChildren ?? false;
2928
}
3029

3130
confirm(): void {

0 commit comments

Comments
 (0)