diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.spec.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.spec.ts index 4f7c7be5c26..0c3d7e61b11 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.spec.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.spec.ts @@ -193,13 +193,15 @@ describe('DsDynamicLookupRelationModalComponent', () => { spyOn((component as any).store, 'dispatch'); }); - it('should dispatch an AddRelationshipAction for each selected object', () => { - component.select(searchResult1, searchResult2); + it('should dispatch an AddRelationshipAction for each (valid) selected object', () => { + component.select(searchResult1, undefined, searchResult2); const action = new AddRelationshipAction(component.item, searchResult1.indexableObject, relationship.relationshipType, submissionId, nameVariant); const action2 = new AddRelationshipAction(component.item, searchResult2.indexableObject, relationship.relationshipType, submissionId, nameVariant); expect((component as any).store.dispatch).toHaveBeenCalledWith(action); expect((component as any).store.dispatch).toHaveBeenCalledWith(action2); + expect((component as any).store.dispatch).not.toHaveBeenCalledWith(undefined); + expect((component as any).store.dispatch).toHaveBeenCalledTimes(2); }); }); @@ -210,13 +212,15 @@ describe('DsDynamicLookupRelationModalComponent', () => { spyOn((component as any).store, 'dispatch'); }); - it('should dispatch an RemoveRelationshipAction for each deselected object', () => { - component.deselect(searchResult1, searchResult2); + it('should dispatch an RemoveRelationshipAction for each (valid) deselected object', () => { + component.deselect(searchResult1, undefined, searchResult2); const action = new RemoveRelationshipAction(component.item, searchResult1.indexableObject, relationship.relationshipType, submissionId); const action2 = new RemoveRelationshipAction(component.item, searchResult2.indexableObject, relationship.relationshipType, submissionId); expect((component as any).store.dispatch).toHaveBeenCalledWith(action); expect((component as any).store.dispatch).toHaveBeenCalledWith(action2); + expect((component as any).store.dispatch).not.toHaveBeenCalledWith(undefined); + expect((component as any).store.dispatch).toHaveBeenCalledTimes(2); }); }); diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.ts index 6033fa1b61d..559637e6233 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.ts @@ -291,7 +291,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy select(...selectableObjects: SearchResult[]) { this.zone.runOutsideAngular( () => { - const obs: Observable = observableCombineLatest([...selectableObjects.map((sri: SearchResult) => { + const obs: Observable = observableCombineLatest([...selectableObjects.filter((object: SearchResult) => object).map((sri: SearchResult) => { this.addNameVariantSubscription(sri); return this.relationshipService.getNameVariant(this.listId, sri.indexableObject.uuid) .pipe( @@ -333,7 +333,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy */ deselect(...selectableObjects: SearchResult[]) { this.zone.runOutsideAngular( - () => selectableObjects.forEach((object) => { + () => selectableObjects.filter((object: SearchResult) => object).forEach((object) => { this.subMap[object.indexableObject.uuid].unsubscribe(); this.store.dispatch(new RemoveRelationshipAction(this.item, object.indexableObject as Item, this.relationshipOptions.relationshipType, this.submissionId)); }), diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.html b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.html index 02dec72baa4..bd777415a80 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.html +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/search-tab/dynamic-lookup-relation-search-tab.component.html @@ -33,8 +33,10 @@
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 b72fbf40a80..ec8fb856eb0 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 @@ -220,7 +220,9 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest .pipe(take(1)) .subscribe((selection: SearchResult[]) => { const filteredPage: SearchResult[] = page.filter((pageItem: SearchResult) => selection.findIndex((selected: SearchResult) => selected.equals(pageItem)) < 0); - this.selectObject.emit(...filteredPage); + if (filteredPage && filteredPage.length > 0) { + this.selectObject.emit(...filteredPage); + } }); this.selectableListService.select(this.listId, page); } @@ -235,7 +237,9 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest .pipe(take(1)) .subscribe((selection: SearchResult[]) => { const filteredPage = page.filter((pageItem) => selection.findIndex((selected) => selected.equals(pageItem)) >= 0); - this.deselectObject.emit(...filteredPage); + if (filteredPage && filteredPage.length > 0) { + this.deselectObject.emit(...filteredPage); + } }); this.selectableListService.deselect(this.listId, page); } @@ -260,7 +264,9 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest take(1), tap((selection: SearchResult[]) => { const filteredResults = results.filter((pageItem) => selection.findIndex((selected) => selected.equals(pageItem)) < 0); - this.selectObject.emit(...filteredResults); + if (filteredResults && filteredResults.length > 0) { + this.selectObject.emit(...filteredResults); + } }), mapTo(results), )), diff --git a/src/app/shared/search/search.component.ts b/src/app/shared/search/search.component.ts index 337cb67171e..2ea61ee19c3 100644 --- a/src/app/shared/search/search.component.ts +++ b/src/app/shared/search/search.component.ts @@ -540,9 +540,7 @@ export class SearchComponent implements OnDestroy, OnInit { if (this.trackStatistics) { this.service.trackSearch(searchOptionsWithHidden, results.payload); } - if (results.payload?.page?.length > 0) { - this.resultFound.emit(results.payload); - } + this.resultFound.emit(results.payload); } this.resultsRD$.next(results); });