Skip to content

Commit 571ea01

Browse files
authored
[ENG-9157] [AOI] Add atomic ability to remove contributors from children projects in API (#884)
- Ticket: [ENG-9157] - Feature flag: n/a ## Summary of Changes 1. Updated delete contributors param. 2. Added logic to get components before open delete contributors dialog. 3. Fixed delete message.
1 parent ae6fc32 commit 571ea01

3 files changed

Lines changed: 44 additions & 34 deletions

File tree

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

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -395,37 +395,49 @@ export class ContributorsComponent implements OnInit, OnDestroy {
395395

396396
removeContributor(contributor: ContributorModel) {
397397
const isDeletingSelf = contributor.userId === this.currentUser()?.id;
398+
const resourceDetails = this.resourceDetails();
399+
const resourceId = this.resourceId();
400+
const rootParentId = resourceDetails.rootParentId ?? resourceId;
398401

399-
this.customDialogService
400-
.open(RemoveContributorDialogComponent, {
401-
header: 'project.contributors.removeDialog.title',
402-
width: '448px',
403-
data: {
404-
name: contributor.fullName,
405-
hasChildren: !!this.resourceChildren()?.length,
406-
},
407-
})
408-
.onClose.pipe(
409-
filter((res) => res !== undefined),
410-
switchMap((removeFromChildren: boolean) =>
411-
this.actions.deleteContributor(
412-
this.resourceId(),
413-
this.resourceType(),
414-
contributor.userId,
415-
isDeletingSelf,
416-
removeFromChildren
417-
)
418-
),
419-
takeUntilDestroyed(this.destroyRef)
420-
)
402+
this.loaderService.show();
403+
404+
this.actions
405+
.getResourceWithChildren(rootParentId, resourceId, this.resourceType())
406+
.pipe(takeUntilDestroyed(this.destroyRef))
421407
.subscribe(() => {
422-
this.toastService.showSuccess('project.contributors.removeDialog.successMessage', {
423-
name: contributor.fullName,
424-
});
408+
this.loaderService.hide();
425409

426-
if (isDeletingSelf) {
427-
this.router.navigate(['/']);
428-
}
410+
this.customDialogService
411+
.open(RemoveContributorDialogComponent, {
412+
header: 'project.contributors.removeDialog.title',
413+
width: '448px',
414+
data: {
415+
name: contributor.fullName,
416+
hasChildren: !!this.resourceChildren()?.length,
417+
},
418+
})
419+
.onClose.pipe(
420+
filter((res) => res !== undefined),
421+
switchMap((removeFromChildren: boolean) =>
422+
this.actions.deleteContributor(
423+
this.resourceId(),
424+
this.resourceType(),
425+
contributor.userId,
426+
isDeletingSelf,
427+
removeFromChildren
428+
)
429+
),
430+
takeUntilDestroyed(this.destroyRef)
431+
)
432+
.subscribe(() => {
433+
this.toastService.showSuccess('project.contributors.removeDialog.successMessage', {
434+
name: contributor.fullName,
435+
});
436+
437+
if (isDeletingSelf) {
438+
this.router.navigate(['/']);
439+
}
440+
});
429441
});
430442
}
431443

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="flex flex-column">
2-
<p>{{ 'project.contributors.removeDialog.message' | translate: { name: name } }}</p>
2+
<p [innerHTML]="'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">

src/app/shared/services/contributors.service.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,9 @@ export class ContributorsService {
248248
userId: string,
249249
removeFromChildren = false
250250
): Observable<void> {
251-
let baseUrl = `${this.getBaseUrl(resourceType, resourceId)}/${userId}/`;
252-
if (removeFromChildren) {
253-
baseUrl = baseUrl.concat('?propagate_to_children=true');
254-
}
251+
const baseUrl = `${this.getBaseUrl(resourceType, resourceId)}/${userId}/`;
252+
const url = removeFromChildren ? `${baseUrl}?include_children=true` : baseUrl;
255253

256-
return this.jsonApiService.delete(baseUrl);
254+
return this.jsonApiService.delete(url);
257255
}
258256
}

0 commit comments

Comments
 (0)