Skip to content

Commit 121121d

Browse files
committed
update preprint licance set logic
1 parent f0944a8 commit 121121d

File tree

6 files changed

+16
-18
lines changed

6 files changed

+16
-18
lines changed

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ import { InputText } from 'primeng/inputtext';
99
import { Message } from 'primeng/message';
1010
import { Tooltip } from 'primeng/tooltip';
1111

12-
import { ChangeDetectionStrategy, Component, inject, input, OnInit, output } from '@angular/core';
12+
import { ChangeDetectionStrategy, Component, effect, inject, input, OnInit, output, untracked } from '@angular/core';
1313
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
1414

1515
import { formInputLimits } from '@osf/features/preprints/constants';
1616
import { MetadataForm, PreprintModel, PreprintProviderDetails } from '@osf/features/preprints/models';
17-
import { PreprintSelectors } from '@osf/features/preprints/store/preprint';
1817
import {
1918
CreatePreprint,
2019
FetchLicenses,
@@ -78,18 +77,29 @@ export class PreprintsMetadataStepComponent implements OnInit {
7877
licenses = select(PreprintStepperSelectors.getLicenses);
7978
createdPreprint = select(PreprintStepperSelectors.getPreprint);
8079
isUpdatingPreprint = select(PreprintStepperSelectors.isPreprintSubmitting);
81-
isLicenseSet = select(PreprintSelectors.isLicenseSet);
8280

8381
provider = input.required<PreprintProviderDetails | undefined>();
8482
nextClicked = output<void>();
8583
backClicked = output<void>();
8684

85+
constructor() {
86+
effect(() => {
87+
const licenses = this.licenses();
88+
const preprint = this.createdPreprint();
89+
90+
if (licenses.length && preprint && !preprint.licenseId && preprint.defaultLicenseId) {
91+
const defaultLicense = licenses.find((license) => license.id === preprint?.defaultLicenseId);
92+
93+
if (defaultLicense && !defaultLicense.requiredFields.length) {
94+
this.actions.saveLicense(defaultLicense.id);
95+
}
96+
}
97+
});
98+
}
99+
87100
ngOnInit() {
88101
this.actions.fetchLicenses();
89102
this.initForm();
90-
console.log('this.createdPreprint ' + this.createdPreprint());
91-
// console.log('selectedLicense ' + this.selectedLicense());
92-
alert('this.createdPreprint ' + this.isLicenseSet());
93103
}
94104

95105
initForm() {
@@ -140,7 +150,6 @@ export class PreprintsMetadataStepComponent implements OnInit {
140150
}
141151

142152
selectLicense(license: LicenseModel) {
143-
alert('selectLicense');
144153
if (license.requiredFields.length) {
145154
return;
146155
}

src/app/features/preprints/mappers/preprints.mapper.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export class PreprintsMapper {
3838
static fromPreprintJsonApi(
3939
response: ApiData<PreprintAttributesJsonApi, null, PreprintRelationshipsJsonApi, PreprintLinksJsonApi>
4040
): PreprintModel {
41-
console.log(' response ', response);
4241
return {
4342
id: response.id,
4443
dateCreated: response.attributes.date_created,
@@ -84,8 +83,6 @@ export class PreprintsMapper {
8483
embeddedLicense: null,
8584
providerId: response.relationships?.provider?.data?.id,
8685
defaultLicenseId: response.attributes.default_license_id,
87-
// license: response.attributes.license_record,
88-
isLicenseSet: !!response.attributes.license_record,
8986
};
9087
}
9188

src/app/features/preprints/models/preprint.models.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export interface PreprintModel {
4848
identifiers?: IdentifierModel[];
4949
providerId: string;
5050
defaultLicenseId?: string;
51-
isLicenseSet?: boolean;
5251
}
5352

5453
export interface PreprintFilesLinks {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ export class PreprintStepperState {
138138
if (action.payload.isPublished) {
139139
ctx.setState(patch({ hasBeenSubmitted: true }));
140140
}
141-
142141
ctx.setState(patch({ preprint: patch({ isSubmitting: false, data: preprint }) }));
143142
}),
144143
catchError((error) => handleSectionError(ctx, 'preprint', error))

src/app/features/preprints/store/preprint/preprint.selectors.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ export class PreprintSelectors {
1111
return state.preprint.data;
1212
}
1313

14-
@Selector([PreprintState])
15-
static isLicenseSet(state: PreprintStateModel) {
16-
return state.preprint.data?.isLicenseSet || null;
17-
}
18-
1914
@Selector([PreprintState])
2015
static isPreprintSubmitting(state: PreprintStateModel) {
2116
return state.preprint.isSubmitting;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ export class RegistriesLicenseComponent {
9999
this.control().patchValue({
100100
id: license.id,
101101
});
102-
console.log('license.id', license.id);
103102
this.control().markAsTouched();
104103
this.control().updateValueAndValidity();
105104
this.actions.saveLicense(this.draftId, license.id);

0 commit comments

Comments
 (0)