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 @@ -39,7 +39,7 @@ <h3>{{ 'collections.addToCollection.projectContributors' | translate }}</h3>
<div class="pt-4 w-full">
<osf-contributors-table
class="w-full"
[contributors]="projectContributors()"
[(contributors)]="projectContributors"
[isLoading]="isContributorsLoading()"
(remove)="handleRemoveContributor($event)"
></osf-contributors-table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Button } from 'primeng/button';
import { Step, StepItem, StepPanel } from 'primeng/stepper';
import { Tooltip } from 'primeng/tooltip';

import { forkJoin } from 'rxjs';
import { filter } from 'rxjs/operators';

import { ChangeDetectionStrategy, Component, DestroyRef, effect, inject, input, output, signal } from '@angular/core';
Expand All @@ -24,10 +23,11 @@ import { ContributorDialogAddModel, ContributorModel } from '@osf/shared/models'
import { CustomConfirmationService, CustomDialogService, ToastService } from '@osf/shared/services';
import {
AddContributor,
BulkAddContributors,
BulkUpdateContributors,
ContributorsSelectors,
DeleteContributor,
ProjectsSelectors,
UpdateContributor,
} from '@osf/shared/stores';

@Component({
Expand All @@ -43,11 +43,11 @@ export class ProjectContributorsStepComponent {
private readonly toastService = inject(ToastService);
private readonly customConfirmationService = inject(CustomConfirmationService);

readonly projectContributors = select(ContributorsSelectors.getContributors);
readonly isContributorsLoading = select(ContributorsSelectors.isContributorsLoading);
readonly selectedProject = select(ProjectsSelectors.getSelectedProject);

private initialContributors = signal<ContributorModel[]>([]);
private initialContributors = select(ContributorsSelectors.getContributors);
readonly projectContributors = signal<ContributorModel[]>([]);

stepperActiveValue = input.required<number>();
targetStepValue = input.required<number>();
Expand All @@ -59,7 +59,8 @@ export class ProjectContributorsStepComponent {

actions = createDispatchMap({
addContributor: AddContributor,
updateContributor: UpdateContributor,
bulkAddContributors: BulkAddContributors,
bulkUpdateContributors: BulkUpdateContributors,
deleteContributor: DeleteContributor,
});

Expand Down Expand Up @@ -100,17 +101,16 @@ export class ProjectContributorsStepComponent {
const updatedContributors = findChangedItems(this.initialContributors(), this.projectContributors(), 'id');

if (!updatedContributors.length) {
this.initialContributors.set(JSON.parse(JSON.stringify(this.projectContributors())));
this.projectContributors.set(JSON.parse(JSON.stringify(this.initialContributors())));
this.contributorsSaved.emit();
} else {
const updateRequests = updatedContributors.map((payload) =>
this.actions.updateContributor(this.selectedProject()?.id, ResourceType.Project, payload)
);
forkJoin(updateRequests).subscribe(() => {
this.toastService.showSuccess('project.contributors.toastMessages.multipleUpdateSuccessMessage');
this.initialContributors.set(JSON.parse(JSON.stringify(this.projectContributors())));
this.contributorsSaved.emit();
});
this.actions
.bulkUpdateContributors(this.selectedProject()?.id, ResourceType.Project, updatedContributors)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => {
this.toastService.showSuccess('project.contributors.toastMessages.multipleUpdateSuccessMessage');
this.contributorsSaved.emit();
});
}
} else {
this.contributorsSaved.emit();
Expand Down Expand Up @@ -138,13 +138,12 @@ export class ProjectContributorsStepComponent {
if (res.type === AddContributorType.Unregistered) {
this.openAddUnregisteredContributorDialog();
} else {
const addRequests = res.data.map((payload) =>
this.actions.addContributor(this.selectedProject()?.id, ResourceType.Project, payload)
);

forkJoin(addRequests).subscribe(() => {
this.toastService.showSuccess('project.contributors.toastMessages.multipleAddSuccessMessage');
});
this.actions
.bulkAddContributors(this.selectedProject()?.id, ResourceType.Project, res.data)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() =>
this.toastService.showSuccess('project.contributors.toastMessages.multipleAddSuccessMessage')
);
}
});
}
Expand Down Expand Up @@ -175,10 +174,10 @@ export class ProjectContributorsStepComponent {
private setupEffects(): void {
effect(() => {
const isMetadataSaved = this.isProjectMetadataSaved();
const contributors = this.projectContributors();
const contributors = this.initialContributors();

if (isMetadataSaved && contributors.length && !this.initialContributors().length) {
this.initialContributors.set(JSON.parse(JSON.stringify(contributors)));
if (isMetadataSaved && contributors.length) {
this.projectContributors.set(JSON.parse(JSON.stringify(contributors)));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<osf-contributors-table
class="w-full"
[contributors]="contributors()"
[(contributors)]="contributors"
[showEducation]="false"
[showEmployment]="false"
[isLoading]="isLoading()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { TranslatePipe } from '@ngx-translate/core';
import { Button } from 'primeng/button';
import { DynamicDialogConfig, DynamicDialogRef } from 'primeng/dynamicdialog';

import { filter, forkJoin } from 'rxjs';
import { filter } from 'rxjs';

import {
ChangeDetectionStrategy,
Expand Down Expand Up @@ -33,10 +33,11 @@ import { ContributorDialogAddModel, ContributorModel } from '@osf/shared/models'
import { CustomConfirmationService, CustomDialogService, ToastService } from '@osf/shared/services';
import {
AddContributor,
BulkAddContributors,
BulkUpdateContributors,
ContributorsSelectors,
DeleteContributor,
UpdateBibliographyFilter,
UpdateContributor,
UpdateContributorsSearchValue,
UpdatePermissionFilter,
} from '@osf/shared/stores';
Expand Down Expand Up @@ -69,7 +70,8 @@ export class ContributorsDialogComponent implements OnInit {
updateBibliographyFilter: UpdateBibliographyFilter,
deleteContributor: DeleteContributor,
addContributor: AddContributor,
updateContributor: UpdateContributor,
bulkAddContributors: BulkAddContributors,
bulkUpdateContributors: BulkUpdateContributors,
});

private readonly resourceType: ResourceType;
Expand Down Expand Up @@ -133,13 +135,12 @@ export class ContributorsDialogComponent implements OnInit {
this.openAddUnregisteredContributorDialog();
} else {
if (res?.type === AddContributorType.Registered) {
const addRequests = res.data.map((payload) =>
this.actions.addContributor(this.resourceId, this.resourceType, payload)
);

forkJoin(addRequests).subscribe(() =>
this.toastService.showSuccess('project.contributors.toastMessages.multipleAddSuccessMessage')
);
this.actions
.bulkAddContributors(this.resourceId, this.resourceType, res.data)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() =>
this.toastService.showSuccess('project.contributors.toastMessages.multipleAddSuccessMessage')
);
}
}
});
Expand Down Expand Up @@ -199,12 +200,11 @@ export class ContributorsDialogComponent implements OnInit {
onSave(): void {
const updatedContributors = findChangedItems(this.initialContributors(), this.contributors(), 'id');

const updateRequests = updatedContributors.map((payload) =>
this.actions.updateContributor(this.resourceId, this.resourceType, payload)
);

forkJoin(updateRequests).subscribe(() => {
this.toastService.showSuccess('project.contributors.toastMessages.multipleUpdateSuccessMessage');
});
this.actions
.bulkUpdateContributors(this.resourceId, this.resourceType, updatedContributors)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() =>
this.toastService.showSuccess('project.contributors.toastMessages.multipleUpdateSuccessMessage')
);
}
}
2 changes: 1 addition & 1 deletion src/app/features/preprints/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export { PreprintProviderHeroComponent } from './preprint-provider-hero/preprint
export { PreprintServicesComponent } from './preprint-services/preprint-services.component';
export { PreprintsHelpDialogComponent } from './preprints-help-dialog/preprints-help-dialog.component';
export { AuthorAssertionsStepComponent } from './stepper/author-assertion-step/author-assertions-step.component';
export { PreprintsMetadataStepComponent } from './stepper/preprints-metadata-step/preprints-metadata-step.component';
export { SupplementsStepComponent } from './stepper/supplements-step/supplements-step.component';
export { MakeDecisionComponent } from '@osf/features/preprints/components/preprint-details/make-decision/make-decision.component';
export { PreprintTombstoneComponent } from '@osf/features/preprints/components/preprint-details/preprint-tombstone/preprint-tombstone.component';
export { WithdrawDialogComponent } from '@osf/features/preprints/components/preprint-details/withdraw-dialog/withdraw-dialog.component';
export { FileStepComponent } from '@osf/features/preprints/components/stepper/file-step/file-step.component';
export { MetadataStepComponent } from '@osf/features/preprints/components/stepper/metadata-step/metadata-step.component';
export { ReviewStepComponent } from '@osf/features/preprints/components/stepper/review-step/review-step.component';
export { TitleAndAbstractStepComponent } from '@osf/features/preprints/components/stepper/title-and-abstract-step/title-and-abstract-step.component';
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import { Card } from 'primeng/card';
import { ChangeDetectionStrategy, Component, effect, input, OnInit, signal } from '@angular/core';

import { PreprintProviderDetails } from '@osf/features/preprints/models';
import { AffiliatedInstitutionSelectComponent } from '@shared/components';
import { ResourceType } from '@shared/enums';
import { Institution } from '@shared/models';
import { AffiliatedInstitutionSelectComponent } from '@osf/shared/components';
import { ResourceType } from '@osf/shared/enums';
import { Institution } from '@osf/shared/models';
import {
FetchResourceInstitutions,
FetchUserInstitutions,
InstitutionsSelectors,
UpdateResourceInstitutions,
} from '@shared/stores/institutions';
} from '@osf/shared/stores/institutions';

@Component({
selector: 'osf-preprints-affiliated-institutions',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h2>{{ 'project.overview.metadata.contributors' | translate }}</h2>

<osf-contributors-table
class="w-full"
[contributors]="contributors()"
[(contributors)]="contributors"
[currentUserId]="currentUser()?.id"
[isCurrentUserAdminContributor]="isCurrentUserAdminContributor()"
[isLoading]="isContributorsLoading()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ import { MockComponent, MockProvider } from 'ng-mocks';
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { UserSelectors } from '@core/store/user';
import { ContributorsTableComponent } from '@shared/components/contributors';
import { ContributorsTableComponent } from '@osf/shared/components/contributors';
import { MOCK_CONTRIBUTOR, MOCK_USER } from '@shared/mocks';
import { ContributorModel } from '@shared/models';
import { CustomConfirmationService, CustomDialogService, ToastService } from '@shared/services';
import { ContributorsSelectors } from '@shared/stores';

import { ContributorsComponent } from './contributors.component';
import { PreprintsContributorsComponent } from './preprints-contributors.component';

import { OSFTestingModule } from '@testing/osf.testing.module';
import { CustomConfirmationServiceMockBuilder } from '@testing/providers/custom-confirmation-provider.mock';
import { CustomDialogServiceMockBuilder } from '@testing/providers/custom-dialog-provider.mock';
import { provideMockStore } from '@testing/providers/store-provider.mock';
import { ToastServiceMockBuilder } from '@testing/providers/toast-provider.mock';

describe('ContributorsComponent', () => {
let component: ContributorsComponent;
let fixture: ComponentFixture<ContributorsComponent>;
describe('PreprintsContributorsComponent', () => {
let component: PreprintsContributorsComponent;
let fixture: ComponentFixture<PreprintsContributorsComponent>;
let toastServiceMock: ReturnType<ToastServiceMockBuilder['build']>;
let confirmationServiceMock: ReturnType<CustomConfirmationServiceMockBuilder['build']>;
let mockCustomDialogService: ReturnType<CustomDialogServiceMockBuilder['build']>;
Expand All @@ -33,7 +33,7 @@ describe('ContributorsComponent', () => {
mockCustomDialogService = CustomDialogServiceMockBuilder.create().build();

await TestBed.configureTestingModule({
imports: [ContributorsComponent, OSFTestingModule, MockComponent(ContributorsTableComponent)],
imports: [PreprintsContributorsComponent, OSFTestingModule, MockComponent(ContributorsTableComponent)],
providers: [
MockProvider(ToastService, toastServiceMock),
MockProvider(CustomConfirmationService, confirmationServiceMock),
Expand All @@ -57,7 +57,7 @@ describe('ContributorsComponent', () => {
],
}).compileComponents();

fixture = TestBed.createComponent(ContributorsComponent);
fixture = TestBed.createComponent(PreprintsContributorsComponent);
component = fixture.componentInstance;
fixture.componentRef.setInput('preprintId', 'preprint-1');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Card } from 'primeng/card';
import { Message } from 'primeng/message';
import { TableModule } from 'primeng/table';

import { filter, forkJoin } from 'rxjs';
import { filter } from 'rxjs';

import {
ChangeDetectionStrategy,
Expand Down Expand Up @@ -35,20 +35,21 @@ import { ContributorDialogAddModel, ContributorModel } from '@osf/shared/models'
import { CustomConfirmationService, CustomDialogService, ToastService } from '@osf/shared/services';
import {
AddContributor,
BulkAddContributors,
BulkUpdateContributors,
ContributorsSelectors,
DeleteContributor,
GetAllContributors,
UpdateContributor,
} from '@osf/shared/stores';

@Component({
selector: 'osf-preprint-contributors',
selector: 'osf-preprints-contributors',
imports: [FormsModule, TableModule, ContributorsTableComponent, TranslatePipe, Card, Button, Message],
templateUrl: './contributors.component.html',
styleUrl: './contributors.component.scss',
templateUrl: './preprints-contributors.component.html',
styleUrl: './preprints-contributors.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ContributorsComponent implements OnInit {
export class PreprintsContributorsComponent implements OnInit {
preprintId = input<string | undefined>('');

readonly destroyRef = inject(DestroyRef);
Expand All @@ -66,15 +67,17 @@ export class ContributorsComponent implements OnInit {
const initialContributors = this.initialContributors();
if (!currentUserId) return false;

return initialContributors.some((contributor: ContributorModel) => {
return contributor.userId === currentUserId && contributor.permission === ContributorPermission.Admin;
});
return initialContributors.some(
(contributor: ContributorModel) =>
contributor.userId === currentUserId && contributor.permission === ContributorPermission.Admin
);
});

actions = createDispatchMap({
getContributors: GetAllContributors,
deleteContributor: DeleteContributor,
updateContributor: UpdateContributor,
bulkUpdateContributors: BulkUpdateContributors,
bulkAddContributors: BulkAddContributors,
addContributor: AddContributor,
});

Expand All @@ -99,13 +102,12 @@ export class ContributorsComponent implements OnInit {
save() {
const updatedContributors = findChangedItems(this.initialContributors(), this.contributors(), 'id');

const updateRequests = updatedContributors.map((payload) =>
this.actions.updateContributor(this.preprintId(), ResourceType.Preprint, payload)
);

forkJoin(updateRequests).subscribe(() => {
this.toastService.showSuccess('project.contributors.toastMessages.multipleUpdateSuccessMessage');
});
this.actions
.bulkUpdateContributors(this.preprintId(), ResourceType.Preprint, updatedContributors)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() =>
this.toastService.showSuccess('project.contributors.toastMessages.multipleUpdateSuccessMessage')
);
}

openAddContributorDialog() {
Expand All @@ -125,13 +127,12 @@ export class ContributorsComponent implements OnInit {
if (res.type === AddContributorType.Unregistered) {
this.openAddUnregisteredContributorDialog();
} else {
const addRequests = res.data.map((payload) =>
this.actions.addContributor(this.preprintId(), ResourceType.Preprint, payload)
);

forkJoin(addRequests).subscribe(() => {
this.toastService.showSuccess('project.contributors.toastMessages.multipleAddSuccessMessage');
});
this.actions
.bulkAddContributors(this.preprintId(), ResourceType.Preprint, res.data)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() =>
this.toastService.showSuccess('project.contributors.toastMessages.multipleAddSuccessMessage')
);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h2>{{ 'preprints.preprintStepper.metadata.title' | translate }}</h2>

<div class="mt-4">
<osf-preprint-contributors [preprintId]="createdPreprint()?.id" />
<osf-preprints-contributors [preprintId]="createdPreprint()?.id" />
</div>

<p-card class="w-full card" styleClass="mt-4">
Expand Down
Loading
Loading