Skip to content
Open
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 @@ -9,7 +9,7 @@ import { InputText } from 'primeng/inputtext';
import { Message } from 'primeng/message';
import { Tooltip } from 'primeng/tooltip';

import { ChangeDetectionStrategy, Component, inject, input, OnInit, output } from '@angular/core';
import { ChangeDetectionStrategy, Component, effect, inject, input, OnInit, output } from '@angular/core';
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';

import { formInputLimits } from '@osf/features/preprints/constants';
Expand Down Expand Up @@ -82,6 +82,21 @@ export class PreprintsMetadataStepComponent implements OnInit {
nextClicked = output<void>();
backClicked = output<void>();

constructor() {
effect(() => {
const licenses = this.licenses();
const preprint = this.createdPreprint();

if (licenses.length && preprint && !preprint.licenseId && preprint.defaultLicenseId) {
const defaultLicense = licenses.find((license) => license.id === preprint?.defaultLicenseId);

if (defaultLicense && !defaultLicense.requiredFields.length) {
this.actions.saveLicense(defaultLicense.id);
}
}
});
}

ngOnInit() {
this.actions.fetchLicenses();
this.initForm();
Expand Down
1 change: 1 addition & 0 deletions src/app/features/preprints/mappers/preprints.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export class PreprintsMapper {
articleDoiLink: response.links.doi,
embeddedLicense: null,
providerId: response.relationships?.provider?.data?.id,
defaultLicenseId: response.attributes.default_license_id,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface PreprintAttributesJsonApi {
why_no_prereg: StringOrNull;
prereg_links: string[];
prereg_link_info: PreregLinkInfo | null;
default_license_id: string;
}

export interface PreprintRelationshipsJsonApi {
Expand Down
1 change: 1 addition & 0 deletions src/app/features/preprints/models/preprint.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface PreprintModel {
articleDoiLink?: string;
identifiers?: IdentifierModel[];
providerId: string;
defaultLicenseId?: string;
}

export interface PreprintFilesLinks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ export class PreprintStepperState {
if (action.payload.isPublished) {
ctx.setState(patch({ hasBeenSubmitted: true }));
}

ctx.setState(patch({ preprint: patch({ isSubmitting: false, data: preprint }) }));
}),
catchError((error) => handleSectionError(ctx, 'preprint', error))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,20 @@ export class RegistriesLicenseComponent {
return;
}

if (!licenses.find((license) => license.id === selectedLicense.id)) {
this.control().patchValue({
id: null,
});
this.control().markAsTouched();
this.control().updateValueAndValidity();
const defaultLicenseId = this.draftRegistration()?.defaultLicenseId;
if (defaultLicenseId && !licenses.find((license) => license.id === selectedLicense.id)) {
const defaultLicense = licenses.find((license) => license.id === defaultLicenseId);
if (defaultLicense) {
this.control().patchValue({
id: defaultLicense.id,
});
this.control().markAsTouched();
this.control().updateValueAndValidity();

if (!defaultLicense.requiredFields.length) {
this.actions.saveLicense(this.draftId, defaultLicense.id);
}
}
}
});
}
Expand Down
1 change: 1 addition & 0 deletions src/app/shared/mappers/registration/registration.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class RegistrationMapper {
},
providerId: response.relationships.provider?.data?.id || '',
hasProject: !!response.attributes.has_project,
defaultLicenseId: response.attributes?.default_license_id,
components: [],
currentUserPermissions: response.attributes.current_user_permissions,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface DraftRegistrationModel {
branchedFrom?: Partial<ProjectModel>;
providerId: string;
hasProject: boolean;
defaultLicenseId?: string;
components: Partial<ProjectModel>[];
currentUserPermissions: UserPermissions[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface DraftRegistrationAttributesJsonApi {
datetime_updated: string;
description: string;
has_project: boolean;
default_license_id?: string;
node_license: LicenseRecordJsonApi;
registration_metadata: Record<string, unknown>;
registration_responses: Record<string, unknown>;
Expand Down