From 8fa07de74c55c73c1f69943f544ab410b351c650 Mon Sep 17 00:00:00 2001 From: Roma Date: Fri, 11 Jul 2025 14:22:35 +0300 Subject: [PATCH 1/4] refactor(preprint-stepper): Renamed createdPreprint -> preprint --- .../author-assertions-step.component.ts | 2 +- .../file-step/file-step.component.html | 2 +- .../stepper/file-step/file-step.component.ts | 4 +- .../metadata-step/metadata-step.component.ts | 2 +- .../review-step/review-step.component.html | 36 +++---- .../review-step/review-step.component.ts | 8 +- .../supplements-step.component.ts | 2 +- .../title-and-abstract-step.component.ts | 2 +- .../preprint-stepper.model.ts | 2 +- .../preprint-stepper.selectors.ts | 8 +- .../preprint-stepper.state.ts | 94 +++++++++---------- 11 files changed, 81 insertions(+), 81 deletions(-) diff --git a/src/app/features/preprints/components/stepper/author-assertion-step/author-assertions-step.component.ts b/src/app/features/preprints/components/stepper/author-assertion-step/author-assertions-step.component.ts index 3cd6165c6..1f5fb0ca9 100644 --- a/src/app/features/preprints/components/stepper/author-assertion-step/author-assertions-step.component.ts +++ b/src/app/features/preprints/components/stepper/author-assertion-step/author-assertions-step.component.ts @@ -68,7 +68,7 @@ export class AuthorAssertionsStepComponent { readonly preregLinkOptions = preregLinksOptions; readonly linkValidators = [CustomValidators.linkValidator(), CustomValidators.requiredTrimmed()]; - createdPreprint = select(PreprintStepperSelectors.getCreatedPreprint); + createdPreprint = select(PreprintStepperSelectors.getPreprint); isUpdatingPreprint = select(PreprintStepperSelectors.isPreprintSubmitting); readonly authorAssertionsForm = new FormGroup({ diff --git a/src/app/features/preprints/components/stepper/file-step/file-step.component.html b/src/app/features/preprints/components/stepper/file-step/file-step.component.html index c3ab6ee12..a7f000c1d 100644 --- a/src/app/features/preprints/components/stepper/file-step/file-step.component.html +++ b/src/app/features/preprints/components/stepper/file-step/file-step.component.html @@ -129,6 +129,6 @@

{{ 'preprints.preprintStepper.file.title' | translate }}

styleClass="w-full" [label]="'common.buttons.next' | translate" (click)="nextButtonClicked()" - [disabled]="!createdPreprint()?.primaryFileId || versionFileMode()" + [disabled]="!preprint()?.primaryFileId || versionFileMode()" /> diff --git a/src/app/features/preprints/components/stepper/file-step/file-step.component.ts b/src/app/features/preprints/components/stepper/file-step/file-step.component.ts index e423e6d01..b08f0d9f9 100644 --- a/src/app/features/preprints/components/stepper/file-step/file-step.component.ts +++ b/src/app/features/preprints/components/stepper/file-step/file-step.component.ts @@ -83,7 +83,7 @@ export class FileStepComponent implements OnInit { readonly PreprintFileSource = PreprintFileSource; provider = input.required(); - createdPreprint = select(PreprintStepperSelectors.getCreatedPreprint); + preprint = select(PreprintStepperSelectors.getPreprint); providerId = select(PreprintStepperSelectors.getSelectedProviderId); selectedFileSource = select(PreprintStepperSelectors.getSelectedFileSource); fileUploadLink = select(PreprintStepperSelectors.getUploadLink); @@ -147,7 +147,7 @@ export class FileStepComponent implements OnInit { } nextButtonClicked() { - if (!this.createdPreprint()?.primaryFileId) { + if (!this.preprint()?.primaryFileId) { return; } diff --git a/src/app/features/preprints/components/stepper/metadata-step/metadata-step.component.ts b/src/app/features/preprints/components/stepper/metadata-step/metadata-step.component.ts index 8905948e6..1d441bc56 100644 --- a/src/app/features/preprints/components/stepper/metadata-step/metadata-step.component.ts +++ b/src/app/features/preprints/components/stepper/metadata-step/metadata-step.component.ts @@ -68,7 +68,7 @@ export class MetadataStepComponent implements OnInit { protected today = new Date(); licenses = select(PreprintStepperSelectors.getLicenses); - createdPreprint = select(PreprintStepperSelectors.getCreatedPreprint); + createdPreprint = select(PreprintStepperSelectors.getPreprint); isUpdatingPreprint = select(PreprintStepperSelectors.isPreprintSubmitting); nextClicked = output(); diff --git a/src/app/features/preprints/components/stepper/review-step/review-step.component.html b/src/app/features/preprints/components/stepper/review-step/review-step.component.html index a9de3b694..3f81f20b7 100644 --- a/src/app/features/preprints/components/stepper/review-step/review-step.component.html +++ b/src/app/features/preprints/components/stepper/review-step/review-step.component.html @@ -35,12 +35,12 @@

{{ 'preprints.preprintStepper.common.labels.title' | translate }}

-

{{ createdPreprint()!.title }}

+

{{ preprint()!.title }}

{{ 'preprints.preprintStepper.common.labels.abstract' | translate }}

- +
@@ -92,8 +92,8 @@

{{ 'preprints.preprintStepper.review.sections.metadata.license' | translate

{{ 'preprints.preprintStepper.review.sections.metadata.publicationDoi' | translate }}

- - {{ 'https://doi.org/' + createdPreprint()?.doi }} + + {{ 'https://doi.org/' + preprint()?.doi }}
@@ -111,7 +111,7 @@

{{ 'preprints.preprintStepper.review.sections.metadata.subjects' | translate

{{ 'preprints.preprintStepper.review.sections.metadata.tags' | translate }}

- @for (tag of createdPreprint()?.tags; track tag) { + @for (tag of preprint()?.tags; track tag) { } @empty {

{{ 'common.labels.none' | translate }}

@@ -122,8 +122,8 @@

{{ 'preprints.preprintStepper.review.sections.metadata.tags' | translate }}<

{{ 'preprints.preprintStepper.review.sections.metadata.publicationDate' | translate }}

- @if (createdPreprint()?.originalPublicationDate) { - {{ createdPreprint()?.originalPublicationDate | date: 'MMM d, y, h:mm a' }} + @if (preprint()?.originalPublicationDate) { + {{ preprint()?.originalPublicationDate | date: 'MMM d, y, h:mm a' }} } @else {

{{ 'common.labels.notApplicable' | translate }}

} @@ -132,8 +132,8 @@

{{ 'preprints.preprintStepper.review.sections.metadata.publicationDate' | tr

{{ 'preprints.preprintStepper.review.sections.metadata.publicationCitation' | translate }}

- @if (createdPreprint()?.customPublicationCitation) { - {{ createdPreprint()?.customPublicationCitation }} + @if (preprint()?.customPublicationCitation) { + {{ preprint()?.customPublicationCitation }} } @else {

{{ 'common.labels.notApplicable' | translate }}

} @@ -149,25 +149,25 @@

{{ 'preprints.preprintStepper.review.sections.authorAssertions.title' | tran

{{ 'preprints.preprintStepper.review.sections.authorAssertions.conflictOfInterest' | translate }}

- @if (!createdPreprint()?.hasCoi) { + @if (!preprint()?.hasCoi) {

{{ 'preprints.preprintStepper.review.sections.authorAssertions.noCoi' | translate }}

} @else { - {{ createdPreprint()?.coiStatement }} + {{ preprint()?.coiStatement }} }

{{ 'preprints.preprintStepper.review.sections.authorAssertions.publicData' | translate }}

- @switch (createdPreprint()?.hasDataLinks) { + @switch (preprint()?.hasDataLinks) { @case (ApplicabilityStatus.NotApplicable) {

{{ 'preprints.preprintStepper.review.sections.authorAssertions.noData' | translate }}

} @case (ApplicabilityStatus.Unavailable) { - {{ createdPreprint()?.whyNoData }} + {{ preprint()?.whyNoData }} } @case (ApplicabilityStatus.Applicable) { - @for (link of createdPreprint()?.dataLinks; track $index) { + @for (link of preprint()?.dataLinks; track $index) {

{{ link }}

} } @@ -179,17 +179,17 @@

{{ 'preprints.preprintStepper.review.sections.authorAssertions.publicPreregistration' | translate }}

- @switch (createdPreprint()?.hasPreregLinks) { + @switch (preprint()?.hasPreregLinks) { @case (ApplicabilityStatus.NotApplicable) {

{{ 'preprints.preprintStepper.review.sections.authorAssertions.noPrereg' | translate }}

} @case (ApplicabilityStatus.Unavailable) { - {{ createdPreprint()?.whyNoPrereg }} + {{ preprint()?.whyNoPrereg }} } @case (ApplicabilityStatus.Applicable) { - @switch (createdPreprint()?.preregLinkInfo) { + @switch (preprint()?.preregLinkInfo) { @case (PreregLinkInfo.Analysis) {

{{ 'preprints.preprintStepper.common.labels.preregTypes.analysis' | translate }} @@ -206,7 +206,7 @@

} } - @for (link of createdPreprint()?.preregLinks; track $index) { + @for (link of preprint()?.preregLinks; track $index) {

{{ link }}

} } diff --git a/src/app/features/preprints/components/stepper/review-step/review-step.component.ts b/src/app/features/preprints/components/stepper/review-step/review-step.component.ts index c623bc6f1..8636fbd88 100644 --- a/src/app/features/preprints/components/stepper/review-step/review-step.component.ts +++ b/src/app/features/preprints/components/stepper/review-step/review-step.component.ts @@ -57,7 +57,7 @@ export class ReviewStepComponent implements OnInit { submitPreprint: SubmitPreprint, }); provider = input.required(); - createdPreprint = select(PreprintStepperSelectors.getCreatedPreprint); + preprint = select(PreprintStepperSelectors.getPreprint); contributors = select(ContributorsSelectors.getContributors); bibliographicContributors = computed(() => { @@ -68,15 +68,15 @@ export class ReviewStepComponent implements OnInit { license = select(PreprintStepperSelectors.getPreprintLicense); preprintProject = select(PreprintStepperSelectors.getPreprintProject); licenseOptionsRecord = computed(() => { - return (this.createdPreprint()?.licenseOptions ?? {}) as Record; + return (this.preprint()?.licenseOptions ?? {}) as Record; }); readonly ApplicabilityStatus = ApplicabilityStatus; readonly PreregLinkInfo = PreregLinkInfo; ngOnInit(): void { - this.actions.getContributors(this.createdPreprint()!.id, ResourceType.Preprint); - this.actions.fetchSubjects(this.createdPreprint()!.id, ResourceType.Preprint); + this.actions.getContributors(this.preprint()!.id, ResourceType.Preprint); + this.actions.fetchSubjects(this.preprint()!.id, ResourceType.Preprint); this.actions.fetchLicenses(); this.actions.fetchPreprintProject(); } diff --git a/src/app/features/preprints/components/stepper/supplements-step/supplements-step.component.ts b/src/app/features/preprints/components/stepper/supplements-step/supplements-step.component.ts index 2ab55edfc..2d0b670df 100644 --- a/src/app/features/preprints/components/stepper/supplements-step/supplements-step.component.ts +++ b/src/app/features/preprints/components/stepper/supplements-step/supplements-step.component.ts @@ -72,7 +72,7 @@ export class SupplementsStepComponent implements OnInit { readonly SupplementOptions = SupplementOptions; - createdPreprint = select(PreprintStepperSelectors.getCreatedPreprint); + createdPreprint = select(PreprintStepperSelectors.getPreprint); isPreprintSubmitting = select(PreprintStepperSelectors.isPreprintSubmitting); availableProjects = select(PreprintStepperSelectors.getAvailableProjects); areAvailableProjectsLoading = select(PreprintStepperSelectors.areAvailableProjectsLoading); diff --git a/src/app/features/preprints/components/stepper/title-and-abstract-step/title-and-abstract-step.component.ts b/src/app/features/preprints/components/stepper/title-and-abstract-step/title-and-abstract-step.component.ts index b36fae05a..5f7bbe3c8 100644 --- a/src/app/features/preprints/components/stepper/title-and-abstract-step/title-and-abstract-step.component.ts +++ b/src/app/features/preprints/components/stepper/title-and-abstract-step/title-and-abstract-step.component.ts @@ -68,7 +68,7 @@ export class TitleAndAbstractStepComponent { }), }); - createdPreprint = select(PreprintStepperSelectors.getCreatedPreprint); + createdPreprint = select(PreprintStepperSelectors.getPreprint); providerId = select(PreprintStepperSelectors.getSelectedProviderId); isUpdatingPreprint = select(PreprintStepperSelectors.isPreprintSubmitting); diff --git a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.model.ts b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.model.ts index dd1cf8b2a..808444593 100644 --- a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.model.ts +++ b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.model.ts @@ -6,7 +6,7 @@ import { License } from '@shared/models/license.model'; export interface PreprintStepperStateModel { selectedProviderId: StringOrNull; - createdPreprint: AsyncStateModel; + preprint: AsyncStateModel; fileSource: PreprintFileSource; preprintFilesLinks: AsyncStateModel; preprintFiles: AsyncStateModel; diff --git a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.selectors.ts b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.selectors.ts index 8369c36a1..128b0584b 100644 --- a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.selectors.ts +++ b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.selectors.ts @@ -9,13 +9,13 @@ export class PreprintStepperSelectors { } @Selector([PreprintStepperState]) - static getCreatedPreprint(state: PreprintStepperStateModel) { - return state.createdPreprint.data; + static getPreprint(state: PreprintStepperStateModel) { + return state.preprint.data; } @Selector([PreprintStepperState]) static isPreprintSubmitting(state: PreprintStepperStateModel) { - return state.createdPreprint.isSubmitting; + return state.preprint.isSubmitting; } @Selector([PreprintStepperState]) @@ -65,7 +65,7 @@ export class PreprintStepperSelectors { @Selector([PreprintStepperState]) static getPreprintLicense(state: PreprintStepperStateModel) { - return state.licenses.data.find((l) => l.id === state.createdPreprint.data?.licenseId) || null; + return state.licenses.data.find((l) => l.id === state.preprint.data?.licenseId) || null; } @Selector([PreprintStepperState]) diff --git a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts index ba7e256cd..bf9655592 100644 --- a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts +++ b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts @@ -47,7 +47,7 @@ import { const DefaultState: PreprintStepperStateModel = { selectedProviderId: null, - createdPreprint: { + preprint: { data: null, isLoading: false, error: null, @@ -108,49 +108,49 @@ export class PreprintStepperState { @Action(CreatePreprint) createPreprint(ctx: StateContext, action: CreatePreprint) { - ctx.setState(patch({ createdPreprint: patch({ isSubmitting: true }) })); + ctx.setState(patch({ preprint: patch({ isSubmitting: true }) })); return this.preprintsService.createPreprint(action.title, action.abstract, action.providerId).pipe( tap((preprint) => { - ctx.setState(patch({ createdPreprint: patch({ isSubmitting: false, data: preprint }) })); + ctx.setState(patch({ preprint: patch({ isSubmitting: false, data: preprint }) })); }), - catchError((error) => this.handleError(ctx, 'createdPreprint', error)) + catchError((error) => this.handleError(ctx, 'preprint', error)) ); } @Action(UpdatePreprint) updatePreprint(ctx: StateContext, action: UpdatePreprint) { - ctx.setState(patch({ createdPreprint: patch({ isSubmitting: true }) })); + ctx.setState(patch({ preprint: patch({ isSubmitting: true }) })); return this.preprintsService.updatePreprint(action.id, action.payload).pipe( tap((preprint) => { - ctx.setState(patch({ createdPreprint: patch({ isSubmitting: false, data: preprint }) })); + ctx.setState(patch({ preprint: patch({ isSubmitting: false, data: preprint }) })); }), - catchError((error) => this.handleError(ctx, 'createdPreprint', error)) + catchError((error) => this.handleError(ctx, 'preprint', error)) ); } @Action(FetchPreprintById) getPreprintById(ctx: StateContext, action: FetchPreprintById) { - ctx.setState(patch({ createdPreprint: patch({ isLoading: true }) })); + ctx.setState(patch({ preprint: patch({ isLoading: true }) })); return this.preprintsService.getById(action.id).pipe( tap((preprint) => { - ctx.setState(patch({ createdPreprint: patch({ isLoading: false, data: preprint }) })); + ctx.setState(patch({ preprint: patch({ isLoading: false, data: preprint }) })); }), - catchError((error) => this.handleError(ctx, 'createdPreprint', error)) + catchError((error) => this.handleError(ctx, 'preprint', error)) ); } @Action(FetchPreprintFilesLinks) getPreprintFilesLinks(ctx: StateContext) { const state = ctx.getState(); - if (!state.createdPreprint.data) { + if (!state.preprint.data) { return EMPTY; } ctx.setState(patch({ preprintFilesLinks: patch({ isLoading: true }) })); - return this.preprintFilesService.getPreprintFilesLinks(state.createdPreprint.data.id).pipe( + return this.preprintFilesService.getPreprintFilesLinks(state.preprint.data.id).pipe( tap((preprintStorage) => { ctx.setState(patch({ preprintFilesLinks: patch({ isLoading: false, data: preprintStorage }) })); }) @@ -173,19 +173,19 @@ export class PreprintStepperState { const createdFileId = file.id.split('/')[1]; ctx.dispatch(new FetchPreprintFiles()); - return this.preprintFilesService.updateFileRelationship(state.createdPreprint.data!.id, createdFileId).pipe( + return this.preprintFilesService.updateFileRelationship(state.preprint.data!.id, createdFileId).pipe( tap((preprint: Preprint) => { ctx.patchState({ - createdPreprint: { - ...ctx.getState().createdPreprint, + preprint: { + ...ctx.getState().preprint, data: { - ...ctx.getState().createdPreprint.data!, + ...ctx.getState().preprint.data!, primaryFileId: preprint.primaryFileId, }, }, }); }), - catchError((error) => this.handleError(ctx, 'createdPreprint', error)) + catchError((error) => this.handleError(ctx, 'preprint', error)) ); }) ); @@ -305,7 +305,7 @@ export class PreprintStepperState { @Action(CopyFileFromProject) copyFileFromProject(ctx: StateContext, action: CopyFileFromProject) { - const createdPreprintId = ctx.getState().createdPreprint.data?.id; + const createdPreprintId = ctx.getState().preprint.data?.id; if (!createdPreprintId) { return; } @@ -322,16 +322,16 @@ export class PreprintStepperState { return this.preprintFilesService.updateFileRelationship(createdPreprintId, fileIdAfterCopy).pipe( tap((preprint: Preprint) => { ctx.patchState({ - createdPreprint: { - ...ctx.getState().createdPreprint, + preprint: { + ...ctx.getState().preprint, data: { - ...ctx.getState().createdPreprint.data!, + ...ctx.getState().preprint.data!, primaryFileId: preprint.primaryFileId, }, }, }); }), - catchError((error) => this.handleError(ctx, 'createdPreprint', error)) + catchError((error) => this.handleError(ctx, 'preprint', error)) ); }), catchError((error) => this.handleError(ctx, 'preprintFiles', error)) @@ -354,31 +354,31 @@ export class PreprintStepperState { @Action(SaveLicense) saveLicense(ctx: StateContext, action: SaveLicense) { - const createdPreprintId = ctx.getState().createdPreprint.data!.id; - ctx.setState(patch({ createdPreprint: patch({ isSubmitting: true }) })); + const createdPreprintId = ctx.getState().preprint.data!.id; + ctx.setState(patch({ preprint: patch({ isSubmitting: true }) })); return this.licensesService.updatePreprintLicense(createdPreprintId, action.licenseId, action.licenseOptions).pipe( tap((preprint) => { - ctx.setState(patch({ createdPreprint: patch({ isSubmitting: false, data: preprint }) })); + ctx.setState(patch({ preprint: patch({ isSubmitting: false, data: preprint }) })); }), - catchError((error) => this.handleError(ctx, 'createdPreprint', error)) + catchError((error) => this.handleError(ctx, 'preprint', error)) ); } @Action(DisconnectProject) disconnectProject(ctx: StateContext) { - const createdPreprintId = ctx.getState().createdPreprint.data?.id; + const createdPreprintId = ctx.getState().preprint.data?.id; if (!createdPreprintId) return EMPTY; - ctx.setState(patch({ createdPreprint: patch({ isSubmitting: true }) })); + ctx.setState(patch({ preprint: patch({ isSubmitting: true }) })); return this.preprintProjectsService.removePreprintProjectRelationship(createdPreprintId).pipe( tap(() => { ctx.patchState({ - createdPreprint: { - ...ctx.getState().createdPreprint, + preprint: { + ...ctx.getState().preprint, data: { - ...ctx.getState().createdPreprint.data!, + ...ctx.getState().preprint.data!, nodeId: null, }, isSubmitting: false, @@ -390,21 +390,21 @@ export class PreprintStepperState { }, }); }), - catchError((error) => handleSectionError(ctx, 'createdPreprint', error)) + catchError((error) => handleSectionError(ctx, 'preprint', error)) ); } @Action(ConnectProject) connectProject(ctx: StateContext, { projectId }: ConnectProject) { - const createdPreprintId = ctx.getState().createdPreprint.data?.id; + const createdPreprintId = ctx.getState().preprint.data?.id; if (!createdPreprintId) return EMPTY; - ctx.setState(patch({ createdPreprint: patch({ isSubmitting: true }) })); + ctx.setState(patch({ preprint: patch({ isSubmitting: true }) })); return this.preprintProjectsService.updatePreprintProjectRelationship(createdPreprintId, projectId).pipe( tap((preprint) => { ctx.patchState({ - createdPreprint: { + preprint: { data: preprint, isLoading: false, isSubmitting: false, @@ -412,13 +412,13 @@ export class PreprintStepperState { }, }); }), - catchError((error) => handleSectionError(ctx, 'createdPreprint', error)) + catchError((error) => handleSectionError(ctx, 'preprint', error)) ); } @Action(FetchPreprintProject) fetchPreprintProject(ctx: StateContext) { - const preprintProjectId = ctx.getState().createdPreprint.data?.nodeId; + const preprintProjectId = ctx.getState().preprint.data?.nodeId; if (!preprintProjectId) return EMPTY; ctx.setState(patch({ preprintProject: patch({ isLoading: true }) })); @@ -439,8 +439,8 @@ export class PreprintStepperState { @Action(CreateNewProject) createNewProject(ctx: StateContext, action: CreateNewProject) { - const createdPreprintId = ctx.getState().createdPreprint.data!.id; - ctx.setState(patch({ createdPreprint: patch({ isSubmitting: true }) })); + const createdPreprintId = ctx.getState().preprint.data!.id; + ctx.setState(patch({ preprint: patch({ isSubmitting: true }) })); ctx.setState(patch({ preprintProject: patch({ isLoading: true }) })); return this.preprintProjectsService @@ -454,10 +454,10 @@ export class PreprintStepperState { ), tap(([project, preprint]) => { ctx.patchState({ - createdPreprint: { - ...ctx.getState().createdPreprint, + preprint: { + ...ctx.getState().preprint, data: { - ...ctx.getState().createdPreprint.data!, + ...ctx.getState().preprint.data!, nodeId: preprint.nodeId, }, isSubmitting: false, @@ -475,13 +475,13 @@ export class PreprintStepperState { @Action(SubmitPreprint) submitPreprint(ctx: StateContext) { - const createdPreprintId = ctx.getState().createdPreprint.data!.id; - ctx.setState(patch({ createdPreprint: patch({ isSubmitting: true }) })); + const createdPreprintId = ctx.getState().preprint.data!.id; + ctx.setState(patch({ preprint: patch({ isSubmitting: true }) })); return this.preprintsService.submitPreprint(createdPreprintId).pipe( tap(() => { - ctx.setState(patch({ createdPreprint: patch({ isSubmitting: false }), hasBeenSubmitted: true })); + ctx.setState(patch({ preprint: patch({ isSubmitting: false }), hasBeenSubmitted: true })); }), - catchError((error) => this.handleError(ctx, 'createdPreprint', error)) + catchError((error) => this.handleError(ctx, 'preprint', error)) ); } @@ -494,7 +494,7 @@ export class PreprintStepperState { @Action(DeletePreprint) deletePreprint(ctx: StateContext) { const state = ctx.getState(); - const createdPreprintId = state.createdPreprint.data?.id; + const createdPreprintId = state.preprint.data?.id; if (createdPreprintId && !state.hasBeenSubmitted) { return this.preprintsService.deletePreprint(createdPreprintId); } From 36adddcdf563544dc58229b7f5499319ab195f68 Mon Sep 17 00:00:00 2001 From: Roma Date: Fri, 11 Jul 2025 14:37:34 +0300 Subject: [PATCH 2/4] fix(preprint-stepper): Update current step to the first step in the update process --- .../update-preprint-stepper.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/features/preprints/pages/update-preprint-stepper/update-preprint-stepper.component.ts b/src/app/features/preprints/pages/update-preprint-stepper/update-preprint-stepper.component.ts index 377d4e285..095269848 100644 --- a/src/app/features/preprints/pages/update-preprint-stepper/update-preprint-stepper.component.ts +++ b/src/app/features/preprints/pages/update-preprint-stepper/update-preprint-stepper.component.ts @@ -99,7 +99,7 @@ export class UpdatePreprintStepperComponent implements OnInit, OnDestroy, CanDea preprintProvider = select(PreprintProvidersSelectors.getPreprintProviderDetails(this.providerId())); isPreprintProviderLoading = select(PreprintProvidersSelectors.isPreprintProviderDetailsLoading); hasBeenSubmitted = select(PreprintStepperSelectors.hasBeenSubmitted); - currentStep = signal(updatePreprintSteps[4]); + currentStep = signal(updatePreprintSteps[0]); isWeb = toSignal(inject(IS_WEB)); readonly PreprintSteps = PreprintSteps; From 6bee470132c5c3754d9ad9cadadd9057ba590ec6 Mon Sep 17 00:00:00 2001 From: Roma Date: Mon, 14 Jul 2025 13:19:22 +0300 Subject: [PATCH 3/4] feat(create-new-version): Implemented stepper for creating new version of preprint --- .../create-new-version-steps.const.ts | 15 ++ src/app/features/preprints/constants/index.ts | 1 + .../create-new-version.component.html | 46 ++++++ .../create-new-version.component.scss | 0 .../create-new-version.component.spec.ts | 22 +++ .../create-new-version.component.ts | 135 ++++++++++++++++++ .../features/preprints/preprints.routes.ts | 8 ++ .../preprints/services/preprints.service.ts | 8 ++ .../preprint-stepper.actions.ts | 50 ++++--- .../preprint-stepper.state.ts | 59 ++++---- 10 files changed, 291 insertions(+), 53 deletions(-) create mode 100644 src/app/features/preprints/constants/create-new-version-steps.const.ts create mode 100644 src/app/features/preprints/pages/create-new-version/create-new-version.component.html create mode 100644 src/app/features/preprints/pages/create-new-version/create-new-version.component.scss create mode 100644 src/app/features/preprints/pages/create-new-version/create-new-version.component.spec.ts create mode 100644 src/app/features/preprints/pages/create-new-version/create-new-version.component.ts diff --git a/src/app/features/preprints/constants/create-new-version-steps.const.ts b/src/app/features/preprints/constants/create-new-version-steps.const.ts new file mode 100644 index 000000000..2b50b9a01 --- /dev/null +++ b/src/app/features/preprints/constants/create-new-version-steps.const.ts @@ -0,0 +1,15 @@ +import { PreprintSteps } from '@osf/features/preprints/enums'; +import { StepOption } from '@shared/models'; + +export const createNewVersionStepsConst: StepOption[] = [ + { + index: 0, + label: 'preprints.preprintStepper.steps.file', + value: PreprintSteps.File, + }, + { + index: 1, + label: 'preprints.preprintStepper.steps.review', + value: PreprintSteps.Review, + }, +]; diff --git a/src/app/features/preprints/constants/index.ts b/src/app/features/preprints/constants/index.ts index 8e5ae9b36..5eb8b968b 100644 --- a/src/app/features/preprints/constants/index.ts +++ b/src/app/features/preprints/constants/index.ts @@ -1,3 +1,4 @@ +export * from './create-new-version-steps.const'; export * from './form-input-limits.const'; export * from './prereg-link-options.const'; export * from './submit-preprint-steps.const'; diff --git a/src/app/features/preprints/pages/create-new-version/create-new-version.component.html b/src/app/features/preprints/pages/create-new-version/create-new-version.component.html new file mode 100644 index 000000000..72e5de089 --- /dev/null +++ b/src/app/features/preprints/pages/create-new-version/create-new-version.component.html @@ -0,0 +1,46 @@ +
+
+ @if (isPreprintProviderLoading()) { + + + } @else { + +

+ {{ 'Create New Version' }} +

+ } +
+ + @if (isWeb()) { + @if (isPreprintProviderLoading()) { + + } @else { + + } + } +
+ +
+ @switch (currentStep().value) { + @case (PreprintSteps.File) { + + } + @case (PreprintSteps.Review) { + + } + } +
diff --git a/src/app/features/preprints/pages/create-new-version/create-new-version.component.scss b/src/app/features/preprints/pages/create-new-version/create-new-version.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/features/preprints/pages/create-new-version/create-new-version.component.spec.ts b/src/app/features/preprints/pages/create-new-version/create-new-version.component.spec.ts new file mode 100644 index 000000000..ea0d486a4 --- /dev/null +++ b/src/app/features/preprints/pages/create-new-version/create-new-version.component.spec.ts @@ -0,0 +1,22 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CreateNewVersionComponent } from './create-new-version.component'; + +describe('CreateNewVersionComponent', () => { + let component: CreateNewVersionComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [CreateNewVersionComponent], + }).compileComponents(); + + fixture = TestBed.createComponent(CreateNewVersionComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/features/preprints/pages/create-new-version/create-new-version.component.ts b/src/app/features/preprints/pages/create-new-version/create-new-version.component.ts new file mode 100644 index 000000000..26d761afb --- /dev/null +++ b/src/app/features/preprints/pages/create-new-version/create-new-version.component.ts @@ -0,0 +1,135 @@ +import { createDispatchMap, select } from '@ngxs/store'; + +import { Skeleton } from 'primeng/skeleton'; + +import { map, Observable, of } from 'rxjs'; + +import { + ChangeDetectionStrategy, + Component, + effect, + HostBinding, + HostListener, + inject, + OnDestroy, + OnInit, + signal, +} from '@angular/core'; +import { toSignal } from '@angular/core/rxjs-interop'; +import { ActivatedRoute } from '@angular/router'; + +import { FileStepComponent, ReviewStepComponent } from '@osf/features/preprints/components'; +import { createNewVersionStepsConst } from '@osf/features/preprints/constants'; +import { PreprintSteps } from '@osf/features/preprints/enums'; +import { CanDeactivateComponent } from '@osf/features/preprints/models'; +import { GetPreprintProviderById, PreprintProvidersSelectors } from '@osf/features/preprints/store/preprint-providers'; +import { + CreateNewVersion, + FetchPreprintById, + PreprintStepperSelectors, + ResetState, + SetSelectedPreprintProviderId, +} from '@osf/features/preprints/store/preprint-stepper'; +import { StepperComponent } from '@shared/components'; +import { StepOption } from '@shared/models'; +import { BrandService } from '@shared/services'; +import { BrowserTabHelper, HeaderStyleHelper, IS_WEB } from '@shared/utils'; + +@Component({ + selector: 'osf-create-new-version', + imports: [Skeleton, StepperComponent, ReviewStepComponent, FileStepComponent], + templateUrl: './create-new-version.component.html', + styleUrl: './create-new-version.component.scss', + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class CreateNewVersionComponent implements OnInit, OnDestroy, CanDeactivateComponent { + @HostBinding('class') classes = 'flex-1 flex flex-column w-full'; + + private readonly route = inject(ActivatedRoute); + + private providerId = toSignal(this.route.params.pipe(map((params) => params['providerId'])) ?? of(undefined)); + private preprintId = toSignal(this.route.params.pipe(map((params) => params['preprintId'])) ?? of(undefined)); + + private actions = createDispatchMap({ + getPreprintProviderById: GetPreprintProviderById, + setSelectedPreprintProviderId: SetSelectedPreprintProviderId, + resetState: ResetState, + fetchPreprint: FetchPreprintById, + createNewVersion: CreateNewVersion, + }); + + readonly PreprintSteps = PreprintSteps; + readonly newVersionSteps = createNewVersionStepsConst; + + preprint = select(PreprintStepperSelectors.getPreprint); + preprintProvider = select(PreprintProvidersSelectors.getPreprintProviderDetails(this.providerId())); + isPreprintProviderLoading = select(PreprintProvidersSelectors.isPreprintProviderDetailsLoading); + hasBeenSubmitted = select(PreprintStepperSelectors.hasBeenSubmitted); + currentStep = signal(createNewVersionStepsConst[0]); + isWeb = toSignal(inject(IS_WEB)); + + constructor() { + effect(() => { + const provider = this.preprintProvider(); + + if (provider) { + this.actions.setSelectedPreprintProviderId(provider.id); + BrandService.applyBranding(provider.brand); + HeaderStyleHelper.applyHeaderStyles( + provider.brand.primaryColor, + provider.brand.secondaryColor, + provider.brand.heroBackgroundImageUrl + ); + BrowserTabHelper.updateTabStyles(provider.faviconUrl, provider.name); + } + }); + + effect(() => { + //[RNi] TODO: move this logic to handler of "Create New Version" button on preprint details page when implemented + const preprint = this.preprint(); + + if (!preprint) return; + + this.actions.createNewVersion(preprint.id); + }); + } + + ngOnInit() { + this.actions.getPreprintProviderById(this.providerId()); + this.actions.fetchPreprint(this.preprintId()); + } + + ngOnDestroy() { + HeaderStyleHelper.resetToDefaults(); + BrandService.resetBranding(); + BrowserTabHelper.resetToDefaults(); + this.actions.resetState(); + } + + canDeactivate(): Observable | boolean { + return this.hasBeenSubmitted(); + } + + stepChange(step: StepOption): void { + const currentStepIndex = this.currentStep()?.index ?? 0; + if (step.index >= currentStepIndex) { + return; + } + + this.currentStep.set(step); + } + + moveToNextStep() { + this.currentStep.set(this.newVersionSteps[this.currentStep()?.index + 1]); + } + + moveToPreviousStep() { + this.currentStep.set(this.newVersionSteps[this.currentStep()?.index - 1]); + } + + @HostListener('window:beforeunload', ['$event']) + public onBeforeUnload($event: BeforeUnloadEvent): boolean { + $event.preventDefault(); + return false; + } +} diff --git a/src/app/features/preprints/preprints.routes.ts b/src/app/features/preprints/preprints.routes.ts index 28bd9610d..4a1d0b549 100644 --- a/src/app/features/preprints/preprints.routes.ts +++ b/src/app/features/preprints/preprints.routes.ts @@ -76,6 +76,14 @@ export const preprintsRoutes: Routes = [ ), canDeactivate: [ConfirmLeavingGuard], }, + { + path: ':providerId/new-version/:preprintId', + loadComponent: () => + import('@osf/features/preprints/pages/create-new-version/create-new-version.component').then( + (c) => c.CreateNewVersionComponent + ), + canDeactivate: [ConfirmLeavingGuard], + }, ], }, ]; diff --git a/src/app/features/preprints/services/preprints.service.ts b/src/app/features/preprints/services/preprints.service.ts index 97c603fca..b8c6e47b2 100644 --- a/src/app/features/preprints/services/preprints.service.ts +++ b/src/app/features/preprints/services/preprints.service.ts @@ -84,6 +84,14 @@ export class PreprintsService { return this.jsonApiService.post(`${environment.apiUrl}/preprints/${preprintId}/review_actions/`, payload); } + createNewVersion(prevVersionPreprintId: string) { + return this.jsonApiService + .post< + JsonApiResponse, null> + >(`${environment.apiUrl}/preprints/${prevVersionPreprintId}/versions/`) + .pipe(map((response) => PreprintsMapper.fromPreprintJsonApi(response.data))); + } + private mapPreprintDomainToApiPayload(domainPayload: Partial): Partial { const apiPayload: Record = {}; Object.entries(domainPayload).forEach(([key, value]) => { diff --git a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.actions.ts b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.actions.ts index 1f8a2f92a..377cd16fa 100644 --- a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.actions.ts +++ b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.actions.ts @@ -4,13 +4,13 @@ import { Preprint } from '@osf/features/preprints/models'; import { LicenseOptions, OsfFile } from '@shared/models'; export class SetSelectedPreprintProviderId { - static readonly type = '[Submit Preprint] Set Selected Preprint Provider Id'; + static readonly type = '[Preprint Stepper] Set Selected Preprint Provider Id'; constructor(public id: StringOrNull) {} } export class CreatePreprint { - static readonly type = '[Submit Preprint] Create Preprint'; + static readonly type = '[Preprint Stepper] Create Preprint'; constructor( public title: string, @@ -20,7 +20,7 @@ export class CreatePreprint { } export class UpdatePreprint { - static readonly type = '[Submit Preprint] Update Preprint'; + static readonly type = '[Preprint Stepper] Update Preprint'; constructor( public id: string, @@ -29,67 +29,67 @@ export class UpdatePreprint { } export class FetchPreprintById { - static readonly type = '[Submit Preprint] Get Preprint By Id'; + static readonly type = '[Preprint Stepper] Get Preprint By Id'; constructor(public id: string) {} } export class SetSelectedPreprintFileSource { - static readonly type = '[Submit Preprint] Set Selected Preprint File Source'; + static readonly type = '[Preprint Stepper] Set Selected Preprint File Source'; constructor(public fileSource: PreprintFileSource) {} } export class FetchPreprintFilesLinks { - static readonly type = '[Submit Preprint] Get Preprint Files Links'; + static readonly type = '[Preprint Stepper] Get Preprint Files Links'; } export class UploadFile { - static readonly type = '[Submit Preprint] Upload File'; + static readonly type = '[Preprint Stepper] Upload File'; constructor(public file: File) {} } export class ReuploadFile { - static readonly type = '[Submit Preprint] Reupload File'; + static readonly type = '[Preprint Stepper] Reupload File'; constructor(public file: File) {} } export class CopyFileFromProject { - static readonly type = '[Submit Preprint] Copy File From Project'; + static readonly type = '[Preprint Stepper] Copy File From Project'; constructor(public file: OsfFile) {} } export class FetchPreprintFiles { - static readonly type = '[Submit Preprint] Get Preprint Files'; + static readonly type = '[Preprint Stepper] Get Preprint Files'; } export class FetchAvailableProjects { - static readonly type = '[Submit Preprint] Get Available Projects'; + static readonly type = '[Preprint Stepper] Get Available Projects'; constructor(public searchTerm: StringOrNull) {} } export class FetchProjectFiles { - static readonly type = '[Submit Preprint] Get Project Files'; + static readonly type = '[Preprint Stepper] Get Project Files'; constructor(public projectId: string) {} } export class FetchProjectFilesByLink { - static readonly type = '[Submit Preprint] Get Project Files By Link'; + static readonly type = '[Preprint Stepper] Get Project Files By Link'; constructor(public filesLink: string) {} } export class FetchLicenses { - static readonly type = '[Submit Preprint] Fetch Licenses'; + static readonly type = '[Preprint Stepper] Fetch Licenses'; } export class SaveLicense { - static readonly type = '[Submit Preprint] Save License'; + static readonly type = '[Preprint Stepper] Save License'; constructor( public licenseId: string, @@ -98,21 +98,21 @@ export class SaveLicense { } export class DisconnectProject { - static readonly type = '[Submit Preprint] Disconnect Preprint Project'; + static readonly type = '[Preprint Stepper] Disconnect Preprint Project'; } export class ConnectProject { - static readonly type = '[Submit Preprint] Connect Preprint Project'; + static readonly type = '[Preprint Stepper] Connect Preprint Project'; constructor(public projectId: string) {} } export class FetchPreprintProject { - static readonly type = '[Submit Preprint] Fetch Preprint Project'; + static readonly type = '[Preprint Stepper] Fetch Preprint Project'; } export class CreateNewProject { - static readonly type = '[Submit Preprint] Create Project'; + static readonly type = '[Preprint Stepper] Create Project'; constructor( public title: string, @@ -124,13 +124,19 @@ export class CreateNewProject { } export class SubmitPreprint { - static readonly type = '[Submit Preprint] Submit Preprint'; + static readonly type = '[Preprint Stepper] Preprint Stepper'; +} + +export class CreateNewVersion { + static readonly type = '[Preprint Stepper] Create New Version'; + + constructor(public preprintId: string) {} } export class ResetState { - static readonly type = '[Submit Preprint] Reset State'; + static readonly type = '[Preprint Stepper] Reset State'; } export class DeletePreprint { - static readonly type = '[Submit Preprint] Delete Preprint'; + static readonly type = '[Preprint Stepper] Delete Preprint'; } diff --git a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts index bf9655592..969c653be 100644 --- a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts +++ b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts @@ -1,7 +1,7 @@ import { Action, State, StateContext } from '@ngxs/store'; import { patch } from '@ngxs/store/operators'; -import { EMPTY, filter, forkJoin, of, switchMap, tap, throwError } from 'rxjs'; +import { EMPTY, filter, forkJoin, of, switchMap, tap } from 'rxjs'; import { catchError } from 'rxjs/operators'; import { HttpEventType } from '@angular/common/http'; @@ -23,6 +23,7 @@ import { ConnectProject, CopyFileFromProject, CreateNewProject, + CreateNewVersion, CreatePreprint, DeletePreprint, DisconnectProject, @@ -114,7 +115,7 @@ export class PreprintStepperState { tap((preprint) => { ctx.setState(patch({ preprint: patch({ isSubmitting: false, data: preprint }) })); }), - catchError((error) => this.handleError(ctx, 'preprint', error)) + catchError((error) => handleSectionError(ctx, 'preprint', error)) ); } @@ -126,7 +127,7 @@ export class PreprintStepperState { tap((preprint) => { ctx.setState(patch({ preprint: patch({ isSubmitting: false, data: preprint }) })); }), - catchError((error) => this.handleError(ctx, 'preprint', error)) + catchError((error) => handleSectionError(ctx, 'preprint', error)) ); } @@ -138,7 +139,7 @@ export class PreprintStepperState { tap((preprint) => { ctx.setState(patch({ preprint: patch({ isLoading: false, data: preprint }) })); }), - catchError((error) => this.handleError(ctx, 'preprint', error)) + catchError((error) => handleSectionError(ctx, 'preprint', error)) ); } @@ -185,7 +186,7 @@ export class PreprintStepperState { }, }); }), - catchError((error) => this.handleError(ctx, 'preprint', error)) + catchError((error) => handleSectionError(ctx, 'preprint', error)) ); }) ); @@ -226,7 +227,7 @@ export class PreprintStepperState { }) ); }), - catchError((error) => this.handleError(ctx, 'preprintFiles', error)) + catchError((error) => handleSectionError(ctx, 'preprintFiles', error)) ); } @@ -245,7 +246,7 @@ export class PreprintStepperState { }) ); }), - catchError((error) => this.handleError(ctx, 'availableProjects', error)) + catchError((error) => handleSectionError(ctx, 'availableProjects', error)) ); } @@ -272,7 +273,7 @@ export class PreprintStepperState { }), }) ); - return this.handleError(ctx, 'projectFiles', error); + return handleSectionError(ctx, 'projectFiles', error); }) ); } @@ -292,7 +293,7 @@ export class PreprintStepperState { }) ); }), - catchError((error) => this.handleError(ctx, 'projectFiles', error)) + catchError((error) => handleSectionError(ctx, 'projectFiles', error)) ); } @@ -331,10 +332,10 @@ export class PreprintStepperState { }, }); }), - catchError((error) => this.handleError(ctx, 'preprint', error)) + catchError((error) => handleSectionError(ctx, 'preprint', error)) ); }), - catchError((error) => this.handleError(ctx, 'preprintFiles', error)) + catchError((error) => handleSectionError(ctx, 'preprintFiles', error)) ); } @@ -348,7 +349,7 @@ export class PreprintStepperState { tap((licenses) => { ctx.setState(patch({ licenses: patch({ isLoading: false, data: licenses }) })); }), - catchError((error) => this.handleError(ctx, 'licenses', error)) + catchError((error) => handleSectionError(ctx, 'licenses', error)) ); } @@ -361,7 +362,7 @@ export class PreprintStepperState { tap((preprint) => { ctx.setState(patch({ preprint: patch({ isSubmitting: false, data: preprint }) })); }), - catchError((error) => this.handleError(ctx, 'preprint', error)) + catchError((error) => handleSectionError(ctx, 'preprint', error)) ); } @@ -469,7 +470,7 @@ export class PreprintStepperState { }, }); }), - catchError((error) => this.handleError(ctx, 'preprintProject', error)) + catchError((error) => handleSectionError(ctx, 'preprintProject', error)) ); } @@ -481,7 +482,19 @@ export class PreprintStepperState { tap(() => { ctx.setState(patch({ preprint: patch({ isSubmitting: false }), hasBeenSubmitted: true })); }), - catchError((error) => this.handleError(ctx, 'preprint', error)) + catchError((error) => handleSectionError(ctx, 'preprint', error)) + ); + } + + @Action(CreateNewVersion) + createNewVersion(ctx: StateContext, { preprintId }: CreateNewVersion) { + ctx.setState(patch({ preprint: patch({ isLoading: true }) })); + + return this.preprintsService.createNewVersion(preprintId).pipe( + tap((preprintNewVersion) => { + ctx.setState(patch({ preprint: patch({ data: preprintNewVersion, isSubmitting: false }) })); + }), + catchError((error) => handleSectionError(ctx, 'preprint', error)) ); } @@ -500,20 +513,4 @@ export class PreprintStepperState { } return EMPTY; } - - private handleError( - ctx: StateContext, - section: keyof PreprintStepperStateModel, - error: Error - ) { - ctx.patchState({ - [section]: { - ...(ctx.getState()[section] as object), - isLoading: false, - isSubmitting: false, - error: error.message, - }, - }); - return throwError(() => error); - } } From 587d3a2f031c0f16c2abe1dc0391b1cdaa8a2b67 Mon Sep 17 00:00:00 2001 From: Roma Date: Tue, 15 Jul 2025 22:46:31 +0300 Subject: [PATCH 4/4] feat(create-new-version): Adding api version explicitly, extracted strings to en.json --- .../my-reviewing-navigation.component.ts | 4 +-- .../create-new-version.component.html | 31 ++++++++++--------- .../create-new-version.component.ts | 15 ++++++--- .../preprints/services/preprints.service.ts | 2 +- .../preprint-stepper.state.ts | 2 +- src/assets/i18n/en.json | 3 +- 6 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/app/features/moderation/components/my-reviewing-navigation/my-reviewing-navigation.component.ts b/src/app/features/moderation/components/my-reviewing-navigation/my-reviewing-navigation.component.ts index e405f7ce8..2a18d6336 100644 --- a/src/app/features/moderation/components/my-reviewing-navigation/my-reviewing-navigation.component.ts +++ b/src/app/features/moderation/components/my-reviewing-navigation/my-reviewing-navigation.component.ts @@ -5,7 +5,7 @@ import { Button } from 'primeng/button'; import { ChangeDetectionStrategy, Component, input } from '@angular/core'; import { RouterLink } from '@angular/router'; -import { PreprintProviderShortInfo } from '@osf/features/preprints/models'; +import { PreprintProviderModerationInfo } from '@osf/features/moderation/models'; import { PREPRINT_REVIEWING_TABS } from '../../constants'; import { PreprintModerationTab } from '../../enums'; @@ -18,7 +18,7 @@ import { PreprintModerationTab } from '../../enums'; changeDetection: ChangeDetectionStrategy.OnPush, }) export class MyReviewingNavigationComponent { - provider = input.required(); + provider = input.required(); readonly tabOptions = PREPRINT_REVIEWING_TABS; readonly tabOption = PreprintModerationTab; diff --git a/src/app/features/preprints/pages/create-new-version/create-new-version.component.html b/src/app/features/preprints/pages/create-new-version/create-new-version.component.html index 72e5de089..2970e5ae8 100644 --- a/src/app/features/preprints/pages/create-new-version/create-new-version.component.html +++ b/src/app/features/preprints/pages/create-new-version/create-new-version.component.html @@ -11,7 +11,7 @@ [src]="preprintProvider()!.brand.heroLogoImageUrl" />

- {{ 'Create New Version' }} + {{ 'preprints.createNewVersionTitle' | translate }}

}

@@ -30,17 +30,20 @@

}

-
- @switch (currentStep().value) { - @case (PreprintSteps.File) { - - } - @case (PreprintSteps.Review) { - + +@if (!this.initMode()) { +
+ @switch (currentStep().value) { + @case (PreprintSteps.File) { + + } + @case (PreprintSteps.Review) { + + } } - } -
+
+} diff --git a/src/app/features/preprints/pages/create-new-version/create-new-version.component.ts b/src/app/features/preprints/pages/create-new-version/create-new-version.component.ts index 26d761afb..f070a5df6 100644 --- a/src/app/features/preprints/pages/create-new-version/create-new-version.component.ts +++ b/src/app/features/preprints/pages/create-new-version/create-new-version.component.ts @@ -1,5 +1,7 @@ import { createDispatchMap, select } from '@ngxs/store'; +import { TranslatePipe } from '@ngx-translate/core'; + import { Skeleton } from 'primeng/skeleton'; import { map, Observable, of } from 'rxjs'; @@ -21,7 +23,6 @@ import { ActivatedRoute } from '@angular/router'; import { FileStepComponent, ReviewStepComponent } from '@osf/features/preprints/components'; import { createNewVersionStepsConst } from '@osf/features/preprints/constants'; import { PreprintSteps } from '@osf/features/preprints/enums'; -import { CanDeactivateComponent } from '@osf/features/preprints/models'; import { GetPreprintProviderById, PreprintProvidersSelectors } from '@osf/features/preprints/store/preprint-providers'; import { CreateNewVersion, @@ -31,13 +32,13 @@ import { SetSelectedPreprintProviderId, } from '@osf/features/preprints/store/preprint-stepper'; import { StepperComponent } from '@shared/components'; -import { StepOption } from '@shared/models'; +import { CanDeactivateComponent, StepOption } from '@shared/models'; import { BrandService } from '@shared/services'; import { BrowserTabHelper, HeaderStyleHelper, IS_WEB } from '@shared/utils'; @Component({ selector: 'osf-create-new-version', - imports: [Skeleton, StepperComponent, ReviewStepComponent, FileStepComponent], + imports: [Skeleton, StepperComponent, ReviewStepComponent, FileStepComponent, TranslatePipe], templateUrl: './create-new-version.component.html', styleUrl: './create-new-version.component.scss', changeDetection: ChangeDetectionStrategy.OnPush, @@ -67,6 +68,7 @@ export class CreateNewVersionComponent implements OnInit, OnDestroy, CanDeactiva hasBeenSubmitted = select(PreprintStepperSelectors.hasBeenSubmitted); currentStep = signal(createNewVersionStepsConst[0]); isWeb = toSignal(inject(IS_WEB)); + initMode = signal(true); constructor() { effect(() => { @@ -88,9 +90,14 @@ export class CreateNewVersionComponent implements OnInit, OnDestroy, CanDeactiva //[RNi] TODO: move this logic to handler of "Create New Version" button on preprint details page when implemented const preprint = this.preprint(); + if (!this.initMode()) return; if (!preprint) return; - this.actions.createNewVersion(preprint.id); + this.actions.createNewVersion(preprint.id).subscribe({ + complete: () => { + this.initMode.set(false); + }, + }); }); } diff --git a/src/app/features/preprints/services/preprints.service.ts b/src/app/features/preprints/services/preprints.service.ts index b8c6e47b2..6d0b306ce 100644 --- a/src/app/features/preprints/services/preprints.service.ts +++ b/src/app/features/preprints/services/preprints.service.ts @@ -88,7 +88,7 @@ export class PreprintsService { return this.jsonApiService .post< JsonApiResponse, null> - >(`${environment.apiUrl}/preprints/${prevVersionPreprintId}/versions/`) + >(`${environment.apiUrl}/preprints/${prevVersionPreprintId}/versions/?version=2.20`) .pipe(map((response) => PreprintsMapper.fromPreprintJsonApi(response.data))); } diff --git a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts index a7d0e6b22..c75f1e04c 100644 --- a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts +++ b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts @@ -494,7 +494,7 @@ export class PreprintStepperState { return this.preprintsService.createNewVersion(preprintId).pipe( tap((preprintNewVersion) => { - ctx.setState(patch({ preprint: patch({ data: preprintNewVersion, isSubmitting: false }) })); + ctx.setState(patch({ preprint: patch({ data: preprintNewVersion, isLoading: false }) })); }), catchError((error) => handleSectionError(ctx, 'preprint', error)) ); diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index 0a21a5087..eea132e80 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -1846,7 +1846,8 @@ } } }, - "providers": "Providers" + "providers": "Providers", + "createNewVersionTitle": "Create New Version" }, "registries": { "title": "Registries",