Skip to content

Commit 13d8aa5

Browse files
committed
fix(contributors): updated selected contributors in add dialog
1 parent 5a5ef02 commit 13d8aa5

File tree

10 files changed

+45
-25
lines changed

10 files changed

+45
-25
lines changed

src/app/features/collections/components/add-to-collection/project-contributors-step/project-contributors-step.component.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,10 @@ export class ProjectContributorsStepComponent {
163163
}
164164

165165
private openAddContributorDialog() {
166-
const addedContributorIds = this.projectContributors().map((x) => x.userId);
167-
168166
this.customDialogService
169167
.open(AddContributorDialogComponent, {
170168
header: 'project.contributors.addDialog.addRegisteredContributor',
171169
width: '448px',
172-
data: addedContributorIds,
173170
})
174171
.onClose.pipe(
175172
filter((res: ContributorDialogAddModel) => !!res),

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ export class ContributorsComponent implements OnInit, OnDestroy {
255255
}
256256

257257
openAddContributorDialog() {
258-
const addedContributorIds = this.initialContributors().map((x) => x.userId);
259258
const rootParentId = this.resourceDetails().rootParentId ?? this.resourceId();
260259

261260
this.loaderService.show();
@@ -273,7 +272,6 @@ export class ContributorsComponent implements OnInit, OnDestroy {
273272
header: 'project.contributors.addDialog.addRegisteredContributor',
274273
width: '448px',
275274
data: {
276-
addedContributorIds,
277275
components,
278276
resourceName: this.resourceDetails().title,
279277
},

src/app/features/metadata/dialogs/contributors-dialog/contributors-dialog.component.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,10 @@ export class ContributorsDialogComponent implements OnInit {
131131
}
132132

133133
openAddContributorDialog(): void {
134-
const addedContributorIds = this.initialContributors().map((x) => x.userId);
135-
136134
this.customDialogService
137135
.open(AddContributorDialogComponent, {
138136
header: 'project.contributors.addDialog.addRegisteredContributor',
139137
width: '448px',
140-
data: addedContributorIds,
141138
})
142139
.onClose.pipe(
143140
filter((res: ContributorDialogAddModel) => !!res),

src/app/features/moderation/components/preprint-submission-item/preprint-submission-item.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
</p-accordion-header>
4040

4141
<p-accordion-content>
42-
<div class="flex align-items-center gap-1 p-3 pt-0 ml-3">
42+
<div class="flex align-items-baseline gap-1 p-3 pt-0 ml-3">
4343
<p>{{ 'common.labels.contributors' | translate }}:</p>
4444

4545
@if (submission().contributorsLoading) {

src/app/features/preprints/components/stepper/preprints-metadata-step/preprints-contributors/preprints-contributors.component.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,10 @@ export class PreprintsContributorsComponent implements OnInit {
115115
}
116116

117117
openAddContributorDialog() {
118-
const addedContributorIds = this.initialContributors().map((x) => x.userId);
119-
120118
this.customDialogService
121119
.open(AddContributorDialogComponent, {
122120
header: 'project.contributors.addDialog.addRegisteredContributor',
123121
width: '448px',
124-
data: addedContributorIds,
125122
})
126123
.onClose.pipe(
127124
filter((res: ContributorDialogAddModel) => !!res),

src/app/features/registries/components/registries-metadata-step/registries-contributors/registries-contributors.component.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,10 @@ export class RegistriesContributorsComponent implements OnInit, OnDestroy {
132132
}
133133

134134
openAddContributorDialog() {
135-
const addedContributorIds = this.initialContributors().map((x) => x.userId);
136-
137135
this.customDialogService
138136
.open(AddContributorDialogComponent, {
139137
header: 'project.contributors.addDialog.addRegisteredContributor',
140138
width: '448px',
141-
data: addedContributorIds,
142139
})
143140
.onClose.pipe(
144141
filter((res: ContributorDialogAddModel) => !!res),

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
} @else {
1212
@for (item of users(); track $index) {
1313
<div class="border-divider flex pb-3">
14-
<p-checkbox variant="filled" [value]="item" [(ngModel)]="selectedUsers"></p-checkbox>
14+
<p-checkbox
15+
variant="filled"
16+
[value]="item"
17+
[(ngModel)]="selectedUsers"
18+
[disabled]="!!item.disabled"
19+
></p-checkbox>
1520
<a class="ml-2 font-bold" [href]="item.id" target="_blank">{{ item.fullName }}</a>
1621
</div>
1722
}

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
Component,
1515
computed,
1616
DestroyRef,
17+
effect,
1718
inject,
1819
OnDestroy,
1920
OnInit,
@@ -82,6 +83,10 @@ export class AddContributorDialogComponent implements OnInit, OnDestroy {
8283
readonly hasComponents = computed(() => this.components().length > 0);
8384
readonly buttonLabel = computed(() => (this.isComponentsState() ? 'common.buttons.done' : 'common.buttons.next'));
8485

86+
constructor() {
87+
this.setupEffects();
88+
}
89+
8590
ngOnInit(): void {
8691
this.initializeDialogData();
8792
this.setSearchSubscription();
@@ -145,8 +150,10 @@ export class AddContributorDialogComponent implements OnInit, OnDestroy {
145150
.filter((c) => c.checked && !c.isCurrent)
146151
.map((c) => c.id);
147152

153+
const filteredUsers = this.selectedUsers().filter((user) => !user.disabled);
154+
148155
this.dialogRef.close({
149-
data: this.selectedUsers(),
156+
data: filteredUsers,
150157
type: AddContributorType.Registered,
151158
childNodeIds: childNodeIds.length > 0 ? childNodeIds : undefined,
152159
} as ContributorDialogAddModel);
@@ -174,4 +181,18 @@ export class AddContributorDialogComponent implements OnInit, OnDestroy {
174181
this.currentPage.set(1);
175182
this.first.set(0);
176183
}
184+
185+
private setupEffects(): void {
186+
effect(() => {
187+
const usersList = this.users();
188+
189+
if (usersList.length > 0) {
190+
const checkedUsers = usersList.filter((user) => user.checked);
191+
192+
if (checkedUsers.length > 0) {
193+
this.selectedUsers.set(checkedUsers);
194+
}
195+
}
196+
});
197+
}
177198
}

src/app/shared/models/contributors/contributor-add.model.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ export interface ContributorAddModel {
55
fullName?: string;
66
email?: string;
77
index?: number;
8+
checked?: boolean;
9+
disabled?: boolean;
810
}

src/app/shared/stores/contributors/contributors.state.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,17 +266,21 @@ export class ContributorsState {
266266
users: { ...state.users, isLoading: true, error: null },
267267
});
268268

269-
const addedContributorsIds = state.contributorsList.data.map((contributor) => contributor.userId);
270-
271269
if (!action.searchValue) {
272270
return of([]);
273271
}
274272

275273
return this.contributorsService.searchUsers(action.searchValue, action.page).pipe(
276274
tap((users) => {
275+
const addedContributorsIds = state.contributorsList.data.map((contributor) => contributor.userId);
276+
277277
ctx.patchState({
278278
users: {
279-
data: users.data.filter((user) => !addedContributorsIds.includes(user.id!)),
279+
data: users.data.map((user) => ({
280+
...user,
281+
checked: addedContributorsIds.includes(user.id!),
282+
disabled: addedContributorsIds.includes(user.id!),
283+
})),
280284
isLoading: false,
281285
error: '',
282286
totalCount: users.totalCount,
@@ -321,7 +325,7 @@ export class ContributorsState {
321325
isLoading: false,
322326
error: null,
323327
page: action.page,
324-
pageSize: 10,
328+
pageSize: res.pageSize,
325329
totalCount: res.totalCount,
326330
},
327331
});
@@ -337,18 +341,20 @@ export class ContributorsState {
337341
) {
338342
const state = ctx.getState();
339343
const nextPage = state.bibliographicContributorsList.page + 1;
344+
const nextPageSize = state.bibliographicContributorsList.pageSize;
340345

341-
return ctx.dispatch(new GetBibliographicContributors(action.resourceId, action.resourceType, nextPage, 10));
346+
return ctx.dispatch(
347+
new GetBibliographicContributors(action.resourceId, action.resourceType, nextPage, nextPageSize)
348+
);
342349
}
343350

344351
@Action(LoadMoreContributors)
345352
loadMoreContributors(ctx: StateContext<ContributorsStateModel>, action: LoadMoreContributors) {
346353
const state = ctx.getState();
347354
const nextPage = state.contributorsList.page + 1;
355+
const nextPageSize = state.contributorsList.pageSize;
348356

349-
return ctx.dispatch(
350-
new GetAllContributors(action.resourceId, action.resourceType, nextPage, state.contributorsList.pageSize)
351-
);
357+
return ctx.dispatch(new GetAllContributors(action.resourceId, action.resourceType, nextPage, nextPageSize));
352358
}
353359

354360
@Action(ResetContributorsState)

0 commit comments

Comments
 (0)