Skip to content
Closed
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
50 changes: 31 additions & 19 deletions src/app/features/contributors/contributors.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
AddContributorDialogComponent,
AddUnregisteredContributorDialogComponent,
ContributorsTableComponent,
RemoveContributorDialogComponent,
RequestAccessTableComponent,
} from '@osf/shared/components/contributors';
import { SearchInputComponent } from '@osf/shared/components/search-input/search-input.component';
Expand Down Expand Up @@ -397,26 +398,37 @@ export class ContributorsComponent implements OnInit, OnDestroy {
removeContributor(contributor: ContributorModel) {
const isDeletingSelf = contributor.userId === this.currentUser()?.id;

this.customConfirmationService.confirmDelete({
headerKey: 'project.contributors.removeDialog.title',
messageKey: 'project.contributors.removeDialog.message',
messageParams: { name: contributor.fullName },
acceptLabelKey: 'common.buttons.remove',
onConfirm: () => {
this.actions
.deleteContributor(this.resourceId(), this.resourceType(), contributor.userId, isDeletingSelf)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => {
this.toastService.showSuccess('project.contributors.removeDialog.successMessage', {
name: contributor.fullName,
});
this.customDialogService
.open(RemoveContributorDialogComponent, {
header: 'project.contributors.removeDialog.title',
width: '448px',
data: {
Comment on lines +401 to +405
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen if project doesn't have any component?

messageKey: 'project.contributors.removeDialog.message',
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you pass it? Will it be different for each remove dialog? I think it better to use directly in RemoveContributorDialog.

messageParams: { name: contributor.fullName },
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass it as name.

Suggested change
messageParams: { name: contributor.fullName },
name: contributor.fullName,

},
})
.onClose.pipe(
filter((res) => res !== undefined),
switchMap((removeFromChildren: boolean) =>
this.actions.deleteContributor(
this.resourceId(),
this.resourceType(),
contributor.userId,
isDeletingSelf,
removeFromChildren
)
),
takeUntilDestroyed(this.destroyRef)
)
.subscribe(() => {
this.toastService.showSuccess('project.contributors.removeDialog.successMessage', {
name: contributor.fullName,
});

if (isDeletingSelf) {
this.router.navigate(['/']);
}
});
},
});
if (isDeletingSelf) {
this.router.navigate(['/']);
}
});
}

loadMoreContributors(): void {
Expand Down
1 change: 1 addition & 0 deletions src/app/shared/components/contributors/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './add-contributor-dialog/add-contributor-dialog.component';
export * from './add-unregistered-contributor-dialog/add-unregistered-contributor-dialog.component';
export * from './contributors-table/contributors-table.component';
export * from './remove-contributor-dialog/remove-contributor-dialog.component';
export * from './request-access-table/request-access-table.component';
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div class="flex flex-column">
<p [innerHTML]="messageKey ? (messageKey | translate: messageParams) : ''"></p>

<div class="p-field-radiobutton flex align-items-center mt-3 mb-2">
<p-radioButton name="removeMode" [value]="false" [(ngModel)]="selectedOption" inputId="projectOnly">
</p-radioButton>
<label for="projectOnly" class="ml-2">{{ 'project.contributors.removeDialog.thisProjectOnly' | translate }}</label>
</div>
<div class="p-field-radiobutton flex align-items-center mb-3">
<p-radioButton name="removeMode" [value]="true" [(ngModel)]="selectedOption" inputId="projectAll"> </p-radioButton>
<label for="projectAll" class="ml-2">{{
'project.contributors.removeDialog.thisProjectAndComponents' | translate
}}</label>
</div>

<div class="flex gap-2 mt-3">
<p-button
class="w-full"
styleClass="w-full"
(click)="cancel()"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use onClick

Suggested change
(click)="cancel()"
(onClick)="cancel()"

severity="info"
[label]="'common.buttons.cancel' | translate"
></p-button>
<p-button
class="w-full"
styleClass="w-full"
(click)="confirm()"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(click)="confirm()"
(onClick)="confirm()"

severity="danger"
[label]="'common.buttons.remove' | translate"
></p-button>
</div>
</div>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add unit tests.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

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

describe('RemoveContributorDialogComponent', () => {
let component: RemoveContributorDialogComponent;
let fixture: ComponentFixture<RemoveContributorDialogComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [RemoveContributorDialogComponent],
}).compileComponents();

fixture = TestBed.createComponent(RemoveContributorDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { TranslatePipe } from '@ngx-translate/core';

import { Button } from 'primeng/button';
import { DynamicDialogConfig, DynamicDialogRef } from 'primeng/dynamicdialog';
import { RadioButton } from 'primeng/radiobutton';

import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { FormsModule } from '@angular/forms';

@Component({
selector: 'osf-remove-contributor-dialog',
imports: [RadioButton, FormsModule, Button, TranslatePipe],
templateUrl: './remove-contributor-dialog.component.html',
styleUrl: './remove-contributor-dialog.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RemoveContributorDialogComponent {
readonly dialogRef = inject(DynamicDialogRef);
readonly config = inject(DynamicDialogConfig);
selectedOption = false;

get messageKey(): string | undefined {
return this.config?.data?.messageKey as string | undefined;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
get messageParams(): any {
return this.config?.data?.messageParams;
}

confirm(): void {
this.dialogRef.close(this.selectedOption);
}

cancel(): void {
this.dialogRef.close();
}
}
12 changes: 10 additions & 2 deletions src/app/shared/services/contributors.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,16 @@ export class ContributorsService {
return this.jsonApiService.patch(baseUrl, contributorData);
}

deleteContributor(resourceType: ResourceType, resourceId: string, userId: string): Observable<void> {
const baseUrl = `${this.getBaseUrl(resourceType, resourceId)}/${userId}/`;
deleteContributor(
resourceType: ResourceType,
resourceId: string,
userId: string,
removeFromChildren = false
): Observable<void> {
let baseUrl = `${this.getBaseUrl(resourceType, resourceId)}/${userId}/`;
if (removeFromChildren) {
baseUrl = baseUrl.concat('?propagate_to_children=true');
}

return this.jsonApiService.delete(baseUrl);
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/shared/stores/contributors/contributors.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ export class DeleteContributor {
public resourceId: string | undefined | null,
public resourceType: ResourceType | undefined,
public contributorId: string,
public skipRefresh = false
public skipRefresh = false,
public removeFromChildren = false
) {}
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/stores/contributors/contributors.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export class ContributorsState {
});

return this.contributorsService
.deleteContributor(action.resourceType, action.resourceId, action.contributorId)
.deleteContributor(action.resourceType, action.resourceId, action.contributorId, action.removeFromChildren)
.pipe(
tap(() => {
if (!action.skipRefresh) {
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,8 @@
},
"removeDialog": {
"title": "Remove contributor",
"thisProjectOnly": "This project only",
"thisProjectAndComponents": "This project and all it's components",
"message": "Are you sure you want to remove <b>{{name}}</b> contributor?",
"successMessage": "Contributor {{name}} successfully removed."
},
Expand Down
Loading