diff --git a/src/app/core/data/relationship.service.ts b/src/app/core/data/relationship.service.ts index 9eb09bdef0..0d58d16409 100644 --- a/src/app/core/data/relationship.service.ts +++ b/src/app/core/data/relationship.service.ts @@ -86,11 +86,11 @@ export class RelationshipService extends DataService { return this.getRelationshipEndpoint(id).pipe( isNotEmptyOperator(), take(1), + tap(() => this.removeRelationshipItemsFromCacheByRelationship(id)), map((endpointURL: string) => new DeleteRequest(this.requestService.generateRequestId(), endpointURL)), configureRequest(this.requestService), switchMap((restRequest: RestRequest) => this.requestService.getByUUID(restRequest.uuid)), getResponseFromEntry(), - tap(() => this.removeRelationshipItemsFromCacheByRelationship(id)) ); } diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html index 70cdce24dd..e1e6435796 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html @@ -5,7 +5,6 @@ [for]="model.id" [innerHTML]="(model.required && model.label) ? (model.label | translate) + ' *' : (model.label | translate)" [ngClass]="[getClass('element', 'label'), getClass('grid', 'label')]"> -
diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.ts index be3af9c8da..61551d00a9 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.ts @@ -60,7 +60,7 @@ import { DYNAMIC_FORM_CONTROL_TYPE_DSDATEPICKER } from './models/date-picker/dat import { DYNAMIC_FORM_CONTROL_TYPE_LOOKUP } from './models/lookup/dynamic-lookup.model'; import { DynamicListCheckboxGroupModel } from './models/list/dynamic-list-checkbox-group.model'; import { DynamicListRadioGroupModel } from './models/list/dynamic-list-radio-group.model'; -import { hasValue, isNotEmpty, isNotUndefined } from '../../../empty.util'; +import { hasNoValue, hasValue, isNotEmpty, isNotUndefined } from '../../../empty.util'; import { DYNAMIC_FORM_CONTROL_TYPE_LOOKUP_NAME } from './models/lookup/dynamic-lookup-name.model'; import { DsDynamicTagComponent } from './models/tag/dynamic-tag.component'; import { DsDatePickerComponent } from './models/date-picker/date-picker.component'; @@ -73,7 +73,7 @@ import { DsDynamicFormArrayComponent } from './models/array-group/dynamic-form-a import { DsDynamicRelationGroupComponent } from './models/relation-group/dynamic-relation-group.components'; import { DYNAMIC_FORM_CONTROL_TYPE_RELATION_GROUP } from './models/relation-group/dynamic-relation-group.model'; import { DsDatePickerInlineComponent } from './models/date-picker-inline/dynamic-date-picker-inline.component'; -import { map, startWith, switchMap, find, take, tap } from 'rxjs/operators'; +import { map, startWith, switchMap, find, take, tap, filter } from 'rxjs/operators'; import { combineLatest as observableCombineLatest, Observable, of as observableOf, Subscription } from 'rxjs'; import { SearchResult } from '../../../search/search-result.model'; import { DSpaceObject } from '../../../../core/shared/dspace-object.model'; @@ -97,6 +97,7 @@ import { Relationship } from '../../../../core/shared/item-relationships/relatio import { MetadataValue } from '../../../../core/shared/metadata.models'; import { FormService } from '../../form.service'; import { deepClone } from 'fast-json-patch'; +import { SelectableListState } from '../../../object-list/selectable-list/selectable-list.reducer'; export function dsDynamicFormControlMapFn(model: DynamicFormControlModel): Type | null { switch (model.type) { @@ -243,6 +244,7 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo this.relationshipValue$ = relationship$.pipe( switchMap((relationship: Relationship) => relationship.leftItem.pipe( + tap((t) => console.log(t)), getSucceededRemoteData(), getRemoteDataPayload(), map((leftItem: Item) => { @@ -256,11 +258,16 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo if (this.model.relationshipConfig) { this.listId = 'list-' + this.model.relationshipConfig.relationshipType; this.setItem(); - this.relationService.getRelatedItemsByLabel(this.item, this.model.relationshipConfig.relationshipType).pipe( - tap((t: any) => console.log(deepClone(t))), - getSucceededRemoteData(), - map((items: RemoteData>) => items.payload.page.map((item) => Object.assign(new ItemSearchResult(), { indexableObject: item }))), + const subscription = this.selectableListService.getSelectableList(this.listId).pipe( + find((list: SelectableListState) => hasNoValue(list)), + switchMap(() => { + return this.relationService.getRelatedItemsByLabel(this.item, this.model.relationshipConfig.relationshipType).pipe( + getSucceededRemoteData(), + map((items: RemoteData>) => items.payload.page.map((item) => Object.assign(new ItemSearchResult(), { indexableObject: item }))), + ) + }) ).subscribe((relatedItems: Array>) => this.selectableListService.select(this.listId, relatedItems)); + this.subs.push(subscription); } } diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.ts index e429f26d9f..f851e52537 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.ts @@ -13,7 +13,7 @@ import { SearchService } from '../../../../../../core/shared/search/search.servi import { ActivatedRoute, Router } from '@angular/router'; import { SelectableListService } from '../../../../../object-list/selectable-list/selectable-list.service'; import { hasValue } from '../../../../../empty.util'; -import { map, switchMap, take, tap } from 'rxjs/operators'; +import { map, startWith, switchMap, take, tap } from 'rxjs/operators'; import { getSucceededRemoteData } from '../../../../../../core/shared/operators'; import { RouteService } from '../../../../../../core/services/route.service'; import { CollectionElementLinkType } from '../../../../../object-collection/collection-element-link.type'; @@ -129,7 +129,7 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest this.routeService.setParameter('fixedFilterQuery', this.relationship.filter); this.routeService.setParameter('configuration', this.relationship.searchConfiguration); this.resultsRD$ = this.searchConfigService.paginatedSearchOptions.pipe( - switchMap((options) => this.lookupRelationService.getLocalResults(this.relationship, options)) + switchMap((options) => this.lookupRelationService.getLocalResults(this.relationship, options).pipe(startWith(undefined))) ); } diff --git a/src/app/shared/form/form.component.ts b/src/app/shared/form/form.component.ts index e6ebdeb91a..cbf54799e2 100644 --- a/src/app/shared/form/form.component.ts +++ b/src/app/shared/form/form.component.ts @@ -305,6 +305,7 @@ export class FormComponent implements OnDestroy, OnInit { this.formBuilderService.addFormArrayGroup(formArrayControl, arrayContext); const value = formArrayControl.controls[index].value; formArrayControl.controls[formArrayControl.length - 1].setValue(value); + formArrayControl.controls[index].setValue(undefined); formArrayControl.controls[index].reset(); this.addArrayItem.emit(this.getEvent($event, arrayContext, index, 'add')); this.formService.changeForm(this.formId, this.formModel);