Skip to content

Commit

Permalink
Options to (de)select page in lookup search results made available co…
Browse files Browse the repository at this point in the history
…nditionally

- Emit a result list even if no items are found (result list of 0 items)
- The "Select page" and "Deselect page" drop-down options in the search results list are disabled if there are zero items in the result list

Fixes: #3312
  • Loading branch information
jlipka committed Oct 18, 2024
1 parent 9d6af0a commit a28269b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand All @@ -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);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
select(...selectableObjects: SearchResult<DSpaceObject>[]) {
this.zone.runOutsideAngular(
() => {
const obs: Observable<any[]> = observableCombineLatest([...selectableObjects.map((sri: SearchResult<Item>) => {
const obs: Observable<any[]> = observableCombineLatest([...selectableObjects.filter((object: SearchResult<DSpaceObject>) => object).map((sri: SearchResult<Item>) => {
this.addNameVariantSubscription(sri);
return this.relationshipService.getNameVariant(this.listId, sri.indexableObject.uuid)
.pipe(
Expand Down Expand Up @@ -333,7 +333,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
*/
deselect(...selectableObjects: SearchResult<DSpaceObject>[]) {
this.zone.runOutsideAngular(
() => selectableObjects.forEach((object) => {
() => selectableObjects.filter((object: SearchResult<DSpaceObject>) => 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));
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
</button>
<div ngbDropdownMenu aria-labelledby="resultdropdown" *ngVar="(resultsRD$ | async) as resultsRD">
<button class="dropdown-item"
[disabled]="resultsRD?.page.length === 0"
(click)="selectPage(resultsRD?.page)">{{ ('submission.sections.describe.relationship-lookup.search-tab.select-page' | translate) }}</button>
<button class="dropdown-item"
[disabled]="resultsRD?.page.length === 0"
(click)="deselectPage(resultsRD?.page)">{{ ('submission.sections.describe.relationship-lookup.search-tab.deselect-page' | translate) }}</button>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
.pipe(take(1))
.subscribe((selection: SearchResult<Item>[]) => {
const filteredPage: SearchResult<DSpaceObject>[] = page.filter((pageItem: SearchResult<DSpaceObject>) => selection.findIndex((selected: SearchResult<Item>) => selected.equals(pageItem)) < 0);
this.selectObject.emit(...filteredPage);
if (filteredPage && filteredPage.length > 0) {
this.selectObject.emit(...filteredPage);
}
});
this.selectableListService.select(this.listId, page);
}
Expand All @@ -235,7 +237,9 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
.pipe(take(1))
.subscribe((selection: SearchResult<Item>[]) => {
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);
}
Expand All @@ -260,7 +264,9 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
take(1),
tap((selection: SearchResult<Item>[]) => {
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),
)),
Expand Down
4 changes: 1 addition & 3 deletions src/app/shared/search/search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit a28269b

Please sign in to comment.