diff --git a/src/app/shared/resource-policies/form/resource-policy-form.component.spec.ts b/src/app/shared/resource-policies/form/resource-policy-form.component.spec.ts index 456eb6db5e..4a2a3376e0 100644 --- a/src/app/shared/resource-policies/form/resource-policy-form.component.spec.ts +++ b/src/app/shared/resource-policies/form/resource-policy-form.component.spec.ts @@ -222,8 +222,6 @@ describe('ResourcePolicyFormComponent test suite', () => { testFixture = createTestComponent(html, TestComponent) as ComponentFixture; testComp = testFixture.componentInstance; - testComp.resourcePolicy = resourcePolicy; - fixture.detectChanges(); }); afterEach(() => { diff --git a/src/app/shared/resource-policies/form/resource-policy-form.component.ts b/src/app/shared/resource-policies/form/resource-policy-form.component.ts index 2783200d8f..09be58fca4 100644 --- a/src/app/shared/resource-policies/form/resource-policy-form.component.ts +++ b/src/app/shared/resource-policies/form/resource-policy-form.component.ts @@ -161,27 +161,31 @@ export class ResourcePolicyFormComponent implements OnInit, OnDestroy { this.formId = this.formService.getUniqueId('resource-policy-form'); this.formModel = this.buildResourcePolicyForm(); - 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 dsoRD$: Observable> = observableCombineLatest([epersonRD$, groupRD$]).pipe( - map((rdArr: RemoteData[]) => { - return rdArr.find((rd: RemoteData) => isNotEmpty(rd.payload)); - }), - hasValueOperator(), - ); - this.subs.push( - dsoRD$.pipe( - filter(() => this.isActive), - ).subscribe((dsoRD: RemoteData) => { - this.resourcePolicyGrant = dsoRD.payload; - this.navActiveId = String(dsoRD.payload.type); - this.resourcePolicyTargetName$.next(this.getResourcePolicyTargetName()); - }) - ); + if (this.isBeingEdited()) { + 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 dsoRD$: Observable> = observableCombineLatest([epersonRD$, groupRD$]).pipe( + map((rdArr: RemoteData[]) => { + return rdArr.find((rd: RemoteData) => isNotEmpty(rd.payload)); + }), + hasValueOperator(), + ); + this.subs.push( + dsoRD$.pipe( + filter(() => this.isActive), + ).subscribe((dsoRD: RemoteData) => { + this.resourcePolicyGrant = dsoRD.payload; + 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[] { 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( new DsDynamicInputModel(RESOURCE_POLICY_FORM_NAME_CONFIG), new DsDynamicTextAreaModel(RESOURCE_POLICY_FORM_DESCRIPTION_CONFIG), - new DynamicSelectModel(policyTypeConf), - new DynamicSelectModel(actionConf) + new DynamicSelectModel(RESOURCE_POLICY_FORM_POLICY_TYPE_CONFIG), + new DynamicSelectModel(RESOURCE_POLICY_FORM_ACTION_TYPE_CONFIG) ); const startDateModel = new DynamicDatePickerModel(