Skip to content

Commit 3a13cd7

Browse files
authored
fix(preprint-create-new-version): Fixed error with primary file (#545)
* fix(preprint-create-new-version): Fixed error with primary file * fix(preprint-create-new-version): Fixed PR comment
1 parent 20b6744 commit 3a13cd7

File tree

10 files changed

+84
-48
lines changed

10 files changed

+84
-48
lines changed

src/app/features/moderation/mappers/registry-moderation.mapper.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ export class RegistryModerationMapper {
3737
toState: response.attributes.to_state,
3838
dateModified: response.attributes.date_modified,
3939
comment: response.attributes.comment,
40-
creator: {
41-
id: response.embeds.creator.data.id,
42-
name: response.embeds.creator.data.attributes.full_name,
43-
},
40+
creator: response.embeds?.creator
41+
? {
42+
id: response.embeds.creator.data.id,
43+
name: response.embeds.creator.data.attributes.full_name,
44+
}
45+
: null,
4446
trigger: response.attributes.trigger,
4547
};
4648
}

src/app/features/moderation/models/review-action.model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ export interface ReviewAction {
66
fromState: string;
77
toState: string;
88
dateModified: string;
9-
creator: IdName;
9+
creator: IdName | null;
1010
comment: string;
1111
}

src/app/features/preprints/components/preprint-details/moderation-status-banner/moderation-status-banner.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ export class ModerationStatusBannerComponent {
106106
return recentActivityMessageByState[ReviewsState.PendingWithdrawal];
107107
});
108108

109-
actionCreatorName = computed(() => this.latestAction()?.creator.name);
109+
actionCreatorName = computed(() => this.latestAction()?.creator?.name);
110110
actionCreatorLink = computed(() => `${this.webUrl}/${this.actionCreatorId()}`);
111-
actionCreatorId = computed(() => this.latestAction()?.creator.id);
111+
actionCreatorId = computed(() => this.latestAction()?.creator?.id);
112112
withdrawalRequesterName = computed(() => this.latestWithdrawalRequest()?.creator.name);
113113
withdrawalRequesterId = computed(() => this.latestWithdrawalRequest()?.creator.id);
114114
}

src/app/features/preprints/components/preprint-details/status-banner/status-banner.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class StatusBannerComponent {
8787
if (this.isWithdrawalRejected()) {
8888
return this.latestRequestAction()?.creator.name;
8989
} else {
90-
return this.latestAction()?.creator.name;
90+
return this.latestAction()?.creator?.name;
9191
}
9292
});
9393

src/app/features/preprints/components/stepper/review-step/review-step.component.html

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,22 @@ <h3>{{ 'common.labels.contributors' | translate }}</h3>
6969
<osf-affiliated-institutions-view data-test-preprint-institution-list [institutions]="affiliatedInstitutions()" />
7070
}
7171

72-
<section class="license flex flex-column gap-2">
73-
<h3>{{ 'preprints.preprintStepper.review.sections.metadata.license' | translate }}</h3>
74-
75-
<p-accordion>
76-
<p-accordion-panel value="0">
77-
<p-accordion-header class="p-0 justify-content-start gap-2">
78-
<p class="font-normal">{{ license()?.name }}</p>
79-
</p-accordion-header>
80-
<p-accordion-content>
81-
<p>{{ license()!.text | interpolate: licenseOptionsRecord() }}</p>
82-
</p-accordion-content>
83-
</p-accordion-panel>
84-
</p-accordion>
85-
</section>
72+
@if (license()) {
73+
<section class="license flex flex-column gap-2">
74+
<h3>{{ 'preprints.preprintStepper.review.sections.metadata.license' | translate }}</h3>
75+
76+
<p-accordion>
77+
<p-accordion-panel value="0">
78+
<p-accordion-header class="p-0 justify-content-start gap-2">
79+
<p class="font-normal">{{ license()?.name }}</p>
80+
</p-accordion-header>
81+
<p-accordion-content>
82+
<p>{{ license()!.text | interpolate: licenseOptionsRecord() }}</p>
83+
</p-accordion-content>
84+
</p-accordion-panel>
85+
</p-accordion>
86+
</section>
87+
}
8688

8789
@if (preprint()?.articleDoiLink) {
8890
<section class="flex flex-column gap-2">

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

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { Button } from 'primeng/button';
77
import { Card } from 'primeng/card';
88
import { Tag } from 'primeng/tag';
99

10+
import { Observable, of, switchMap, tap } from 'rxjs';
11+
1012
import { DatePipe, TitleCasePipe } from '@angular/common';
1113
import { ChangeDetectionStrategy, Component, computed, inject, input, OnInit } from '@angular/core';
1214
import { Router } from '@angular/router';
@@ -18,6 +20,7 @@ import {
1820
FetchPreprintProject,
1921
PreprintStepperSelectors,
2022
SubmitPreprint,
23+
UpdatePrimaryFileRelationship,
2124
} from '@osf/features/preprints/store/preprint-stepper';
2225
import {
2326
AffiliatedInstitutionsViewComponent,
@@ -62,9 +65,11 @@ export class ReviewStepComponent implements OnInit {
6265
fetchPreprintProject: FetchPreprintProject,
6366
submitPreprint: SubmitPreprint,
6467
fetchResourceInstitutions: FetchResourceInstitutions,
68+
updatePrimaryFileRelationship: UpdatePrimaryFileRelationship,
6569
});
6670

6771
provider = input.required<PreprintProviderDetails | undefined>();
72+
isCreateNewVersionContext = input<boolean>(false);
6873

6974
preprint = select(PreprintStepperSelectors.getPreprint);
7075
isPreprintSubmitting = select(PreprintStepperSelectors.isPreprintSubmitting);
@@ -89,17 +94,27 @@ export class ReviewStepComponent implements OnInit {
8994
}
9095

9196
submitPreprint() {
92-
if (this.preprint()?.reviewsState !== ReviewsState.Accepted) {
93-
this.actions.submitPreprint().subscribe({
94-
complete: () => {
95-
this.toastService.showSuccess('preprints.preprintStepper.common.successMessages.preprintSubmitted');
96-
this.router.navigate(['/preprints', this.provider()!.id, this.preprint()!.id]);
97-
},
98-
});
99-
} else {
100-
this.toastService.showSuccess('preprints.preprintStepper.common.successMessages.preprintSubmitted');
101-
this.router.navigate(['/preprints', this.provider()!.id, this.preprint()!.id]);
97+
const preprint = this.preprint()!;
98+
let update$: Observable<void | null> = of(null);
99+
100+
if (this.isCreateNewVersionContext()) {
101+
update$ = this.actions.updatePrimaryFileRelationship(preprint.primaryFileId!);
102102
}
103+
104+
update$
105+
.pipe(
106+
switchMap(() => {
107+
if (preprint.reviewsState !== ReviewsState.Accepted) {
108+
return this.actions.submitPreprint();
109+
}
110+
return of(null);
111+
}),
112+
tap(() => {
113+
this.toastService.showSuccess('preprints.preprintStepper.common.successMessages.preprintSubmitted');
114+
this.router.navigate(['/preprints', this.provider()!.id, preprint.id]);
115+
})
116+
)
117+
.subscribe();
103118
}
104119

105120
cancelSubmission() {

src/app/features/preprints/pages/create-new-version/create-new-version.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ <h1 class="preprint-provider-name">
4040
/>
4141
}
4242
@case (PreprintSteps.Review) {
43-
<osf-review-step [provider]="preprintProvider()" />
43+
<osf-review-step [provider]="preprintProvider()" [isCreateNewVersionContext]="true" />
4444
}
4545
}
4646
</section>

src/app/features/preprints/services/preprints.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export class PreprintsService {
166166
}
167167

168168
getPreprintReviewActions(preprintId: string) {
169-
const baseUrl = `${this.apiUrl}/preprints/${preprintId}/review_actions/`;
169+
const baseUrl = `${this.apiUrl}/preprints/${preprintId}/review_actions/?embed=creator`;
170170

171171
return this.jsonApiService
172172
.get<ReviewActionsResponseJsonApi>(baseUrl)

src/app/features/preprints/store/preprint-stepper/preprint-stepper.actions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ export class UploadFile {
5050
constructor(public file: File) {}
5151
}
5252

53+
export class UpdatePrimaryFileRelationship {
54+
static readonly type = '[Preprint Stepper] Update Primary File Relationship';
55+
56+
constructor(public fileId: string) {}
57+
}
58+
5359
export class ReuploadFile {
5460
static readonly type = '[Preprint Stepper] Reupload File';
5561

src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {
4444
SetSelectedPreprintProviderId,
4545
SubmitPreprint,
4646
UpdatePreprint,
47+
UpdatePrimaryFileRelationship,
4748
UploadFile,
4849
} from './';
4950

@@ -175,24 +176,34 @@ export class PreprintStepperState {
175176
const file = event.body!.data;
176177
const createdFileId = file.id.split('/')[1];
177178

178-
return this.preprintFilesService.updateFileRelationship(state.preprint.data!.id, createdFileId).pipe(
179-
tap((preprint: Preprint) => {
180-
ctx.patchState({
181-
preprint: {
182-
...ctx.getState().preprint,
183-
data: {
184-
...ctx.getState().preprint.data!,
185-
primaryFileId: preprint.primaryFileId,
186-
},
187-
},
188-
});
189-
}),
190-
catchError((error) => handleSectionError(ctx, 'preprint', error))
191-
);
179+
return ctx.dispatch(new UpdatePrimaryFileRelationship(createdFileId));
192180
})
193181
);
194182
}
195183

184+
@Action(UpdatePrimaryFileRelationship)
185+
updatePrimaryFileRelationship(ctx: StateContext<PreprintStepperStateModel>, action: UpdatePrimaryFileRelationship) {
186+
const state = ctx.getState();
187+
188+
ctx.setState(patch({ preprint: patch({ isSubmitting: true }) }));
189+
190+
return this.preprintFilesService.updateFileRelationship(state.preprint.data!.id, action.fileId).pipe(
191+
tap((preprint: Preprint) => {
192+
ctx.patchState({
193+
preprint: {
194+
...ctx.getState().preprint,
195+
data: {
196+
...ctx.getState().preprint.data!,
197+
primaryFileId: preprint.primaryFileId,
198+
},
199+
isSubmitting: false,
200+
},
201+
});
202+
}),
203+
catchError((error) => handleSectionError(ctx, 'preprint', error))
204+
);
205+
}
206+
196207
@Action(ReuploadFile)
197208
reuploadFile(ctx: StateContext<PreprintStepperStateModel>, action: ReuploadFile) {
198209
const state = ctx.getState();

0 commit comments

Comments
 (0)