[CST-5674] Fix; enable policy and action type editing; test

This commit is contained in:
Davide Negretti
2022-05-04 11:35:54 +02:00
parent bb3cc1c619
commit 9173b9db60
2 changed files with 28 additions and 33 deletions

View File

@@ -222,8 +222,6 @@ describe('ResourcePolicyFormComponent test suite', () => {
testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>; testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
testComp = testFixture.componentInstance; testComp = testFixture.componentInstance;
testComp.resourcePolicy = resourcePolicy;
fixture.detectChanges();
}); });
afterEach(() => { afterEach(() => {

View File

@@ -161,27 +161,31 @@ export class ResourcePolicyFormComponent implements OnInit, OnDestroy {
this.formId = this.formService.getUniqueId('resource-policy-form'); this.formId = this.formService.getUniqueId('resource-policy-form');
this.formModel = this.buildResourcePolicyForm(); this.formModel = this.buildResourcePolicyForm();
const epersonRD$ = this.ePersonService.findByHref(this.resourcePolicy._links.eperson.href, false).pipe( if (this.isBeingEdited()) {
getFirstSucceededRemoteData() const epersonRD$ = this.ePersonService.findByHref(this.resourcePolicy._links.eperson.href, false).pipe(
); getFirstSucceededRemoteData()
const groupRD$ = this.groupService.findByHref(this.resourcePolicy._links.group.href, false).pipe( );
getFirstSucceededRemoteData() const groupRD$ = this.groupService.findByHref(this.resourcePolicy._links.group.href, false).pipe(
); getFirstSucceededRemoteData()
const dsoRD$: Observable<RemoteData<DSpaceObject>> = observableCombineLatest([epersonRD$, groupRD$]).pipe( );
map((rdArr: RemoteData<DSpaceObject>[]) => { const dsoRD$: Observable<RemoteData<DSpaceObject>> = observableCombineLatest([epersonRD$, groupRD$]).pipe(
return rdArr.find((rd: RemoteData<DSpaceObject>) => isNotEmpty(rd.payload)); map((rdArr: RemoteData<DSpaceObject>[]) => {
}), return rdArr.find((rd: RemoteData<DSpaceObject>) => isNotEmpty(rd.payload));
hasValueOperator(), }),
); hasValueOperator(),
this.subs.push( );
dsoRD$.pipe( this.subs.push(
filter(() => this.isActive), dsoRD$.pipe(
).subscribe((dsoRD: RemoteData<DSpaceObject>) => { filter(() => this.isActive),
this.resourcePolicyGrant = dsoRD.payload; ).subscribe((dsoRD: RemoteData<DSpaceObject>) => {
this.navActiveId = String(dsoRD.payload.type); this.resourcePolicyGrant = dsoRD.payload;
this.resourcePolicyTargetName$.next(this.getResourcePolicyTargetName()); this.navActiveId = String(dsoRD.payload.type);
}) this.resourcePolicyTargetName$.next(this.getResourcePolicyTargetName());
); })
)
} else {
}
} }
/** /**
@@ -202,19 +206,12 @@ export class ResourcePolicyFormComponent implements OnInit, OnDestroy {
*/ */
private buildResourcePolicyForm(): DynamicFormControlModel[] { private buildResourcePolicyForm(): DynamicFormControlModel[] {
const formModel: DynamicFormControlModel[] = []; const formModel: DynamicFormControlModel[] = [];
// TODO to be removed when https://github.com/DSpace/DSpace/issues/7812 will be implemented
const policyTypeConf = Object.assign({}, RESOURCE_POLICY_FORM_POLICY_TYPE_CONFIG, {
disabled: isNotEmpty(this.resourcePolicy)
});
// TODO to be removed when https://github.com/DSpace/DSpace/issues/7812 will be implemented
const actionConf = Object.assign({}, RESOURCE_POLICY_FORM_ACTION_TYPE_CONFIG, {
disabled: isNotEmpty(this.resourcePolicy)
});
formModel.push( formModel.push(
new DsDynamicInputModel(RESOURCE_POLICY_FORM_NAME_CONFIG), new DsDynamicInputModel(RESOURCE_POLICY_FORM_NAME_CONFIG),
new DsDynamicTextAreaModel(RESOURCE_POLICY_FORM_DESCRIPTION_CONFIG), new DsDynamicTextAreaModel(RESOURCE_POLICY_FORM_DESCRIPTION_CONFIG),
new DynamicSelectModel(policyTypeConf), new DynamicSelectModel(RESOURCE_POLICY_FORM_POLICY_TYPE_CONFIG),
new DynamicSelectModel(actionConf) new DynamicSelectModel(RESOURCE_POLICY_FORM_ACTION_TYPE_CONFIG)
); );
const startDateModel = new DynamicDatePickerModel( const startDateModel = new DynamicDatePickerModel(