Skip to content
Draft
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 @@ -14,6 +14,7 @@

import { formInputLimits } from '@osf/features/preprints/constants';
import { MetadataForm, PreprintModel, PreprintProviderDetails } from '@osf/features/preprints/models';
import { PreprintSelectors } from '@osf/features/preprints/store/preprint';
import {
CreatePreprint,
FetchLicenses,
Expand Down Expand Up @@ -77,6 +78,7 @@
licenses = select(PreprintStepperSelectors.getLicenses);
createdPreprint = select(PreprintStepperSelectors.getPreprint);
isUpdatingPreprint = select(PreprintStepperSelectors.isPreprintSubmitting);
isLicenseSet = select(PreprintSelectors.isLicenseSet);

provider = input.required<PreprintProviderDetails | undefined>();
nextClicked = output<void>();
Expand All @@ -85,6 +87,9 @@
ngOnInit() {
this.actions.fetchLicenses();
this.initForm();
console.log('this.createdPreprint ' + this.createdPreprint());

Check failure on line 90 in src/app/features/preprints/components/stepper/preprints-metadata-step/preprints-metadata-step.component.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
// console.log('selectedLicense ' + this.selectedLicense());
alert('this.createdPreprint ' + this.isLicenseSet());
}

initForm() {
Expand Down Expand Up @@ -135,6 +140,7 @@
}

selectLicense(license: LicenseModel) {
alert('selectLicense');
if (license.requiredFields.length) {
return;
}
Expand Down
4 changes: 4 additions & 0 deletions src/app/features/preprints/mappers/preprints.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
static fromPreprintJsonApi(
response: ApiData<PreprintAttributesJsonApi, null, PreprintRelationshipsJsonApi, PreprintLinksJsonApi>
): PreprintModel {
console.log(' response ', response);

Check failure on line 41 in src/app/features/preprints/mappers/preprints.mapper.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
return {
id: response.id,
dateCreated: response.attributes.date_created,
Expand Down Expand Up @@ -82,6 +83,9 @@
articleDoiLink: response.links.doi,
embeddedLicense: null,
providerId: response.relationships?.provider?.data?.id,
defaultLicenseId: response.attributes.default_license_id,
// license: response.attributes.license_record,
isLicenseSet: !!response.attributes.license_record,
};
}

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
2 changes: 2 additions & 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,8 @@ export interface PreprintModel {
articleDoiLink?: string;
identifiers?: IdentifierModel[];
providerId: string;
defaultLicenseId?: string;
isLicenseSet?: boolean;
}

export interface PreprintFilesLinks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export class PreprintSelectors {
return state.preprint.data;
}

@Selector([PreprintState])
static isLicenseSet(state: PreprintStateModel) {
return state.preprint.data?.isLicenseSet || null;
}

@Selector([PreprintState])
static isPreprintSubmitting(state: PreprintStateModel) {
return state.preprint.isSubmitting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,20 @@
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 All @@ -91,6 +99,7 @@
this.control().patchValue({
id: license.id,
});
console.log('license.id', license.id);

Check failure on line 102 in src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
this.control().markAsTouched();
this.control().updateValueAndValidity();
this.actions.saveLicense(this.draftId, license.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
Loading