Skip to content

Commit

Permalink
Merge pull request #2811 from DSpace/backport-2794-to-dspace-7_x
Browse files Browse the repository at this point in the history
[Port dspace-7_x] Added scope @input() to the SearchComponent & fixed related bugs
  • Loading branch information
tdonohue authored Feb 15, 2024
2 parents b350916 + d96c048 commit 9dc0363
Show file tree
Hide file tree
Showing 17 changed files with 118 additions and 95 deletions.
1 change: 1 addition & 0 deletions src/app/core/shared/search/search-filter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const filterStateSelector = (state: SearchFiltersState) => state.searchFilter;
export const FILTER_CONFIG: InjectionToken<SearchFilterConfig> = new InjectionToken<SearchFilterConfig>('filterConfig');
export const IN_PLACE_SEARCH: InjectionToken<boolean> = new InjectionToken<boolean>('inPlaceSearch');
export const REFRESH_FILTER: InjectionToken<BehaviorSubject<any>> = new InjectionToken<boolean>('refreshFilters');
export const SCOPE: InjectionToken<string> = new InjectionToken<string>('scope');

/**
* Service that performs all actions that have to do with search filters and facets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FilterType } from '../../../models/filter-type.model';
import { SearchFilterConfig } from '../../../models/search-filter-config.model';
import {
FILTER_CONFIG,
SCOPE,
IN_PLACE_SEARCH,
REFRESH_FILTER
} from '../../../../../core/shared/search/search-filter.service';
Expand Down Expand Up @@ -35,6 +36,11 @@ export class SearchFacetFilterWrapperComponent implements OnInit {
*/
@Input() refreshFilters: BehaviorSubject<boolean>;

/**
* The current scope
*/
@Input() scope: string;

/**
* The constructor of the search facet filter that should be rendered, based on the filter config's type
*/
Expand All @@ -56,7 +62,8 @@ export class SearchFacetFilterWrapperComponent implements OnInit {
providers: [
{ provide: FILTER_CONFIG, useFactory: () => (this.filterConfig), deps: [] },
{ provide: IN_PLACE_SEARCH, useFactory: () => (this.inPlaceSearch), deps: [] },
{ provide: REFRESH_FILTER, useFactory: () => (this.refreshFilters), deps: [] }
{ provide: REFRESH_FILTER, useFactory: () => (this.refreshFilters), deps: [] },
{ provide: SCOPE, useFactory: () => (this.scope), deps: [] },
],
parent: this.injector
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TranslateModule } from '@ngx-translate/core';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import {
FILTER_CONFIG,
SCOPE,
IN_PLACE_SEARCH,
REFRESH_FILTER,
SearchFilterService
Expand Down Expand Up @@ -99,6 +100,7 @@ describe('SearchFacetFilterComponent', () => {
{ provide: SEARCH_CONFIG_SERVICE, useValue: new SearchConfigurationServiceStub() },
{ provide: IN_PLACE_SEARCH, useValue: false },
{ provide: REFRESH_FILTER, useValue: new BehaviorSubject<boolean>(false) },
{ provide: SCOPE, useValue: undefined },
{
provide: SearchFilterService, useValue: {
getSelectedValuesForFilter: () => observableOf(selectedValues),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { SearchFilterConfig } from '../../../models/search-filter-config.model';
import { SearchService } from '../../../../../core/shared/search/search.service';
import {
FILTER_CONFIG,
SCOPE,
IN_PLACE_SEARCH,
REFRESH_FILTER,
SearchFilterService
Expand Down Expand Up @@ -104,7 +105,9 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
@Inject(SEARCH_CONFIG_SERVICE) public searchConfigService: SearchConfigurationService,
@Inject(IN_PLACE_SEARCH) public inPlaceSearch: boolean,
@Inject(FILTER_CONFIG) public filterConfig: SearchFilterConfig,
@Inject(REFRESH_FILTER) public refreshFilters: BehaviorSubject<boolean>) {
@Inject(REFRESH_FILTER) public refreshFilters: BehaviorSubject<boolean>,
@Inject(SCOPE) public scope: string,
) {
}

/**
Expand All @@ -114,8 +117,11 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
this.currentUrl = this.router.url;
this.filterValues$ = new BehaviorSubject(createPendingRemoteDataObject());
this.currentPage = this.getCurrentPage().pipe(distinctUntilChanged());

this.searchOptions$ = this.searchConfigService.searchOptions;
this.searchOptions$ = this.searchConfigService.searchOptions.pipe(
map((options: SearchOptions) => hasNoValue(this.scope) ? options : Object.assign({}, options, {
scope: this.scope,
})),
);
this.subs.push(
this.searchOptions$.subscribe(() => this.updateFilterValueList()),
this.refreshFilters.asObservable().pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
(@slide.start)="startSlide($event)" (@slide.done)="finishSlide($event)"
class="search-filter-wrapper" [ngClass]="{ 'closed' : closed, 'notab': notab }">
<ds-search-facet-filter-wrapper
[scope]="scope"
[filterConfig]="filter"
[inPlaceSearch]="inPlaceSearch"
[refreshFilters]="refreshFilters" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { filter, map, startWith, switchMap, take } from 'rxjs/operators';
import { SearchFilterConfig } from '../../models/search-filter-config.model';
import { SearchFilterService } from '../../../../core/shared/search/search-filter.service';
import { slide } from '../../../animations/slide';
import { isNotEmpty } from '../../../empty.util';
import { isNotEmpty, hasValue } from '../../../empty.util';
import { SearchService } from '../../../../core/shared/search/search.service';
import { SearchConfigurationService } from '../../../../core/shared/search/search-configuration.service';
import { SEARCH_CONFIG_SERVICE } from '../../../../my-dspace-page/my-dspace-page.component';
Expand Down Expand Up @@ -38,6 +38,11 @@ export class SearchFilterComponent implements OnInit {
*/
@Input() refreshFilters: BehaviorSubject<boolean>;

/**
* The current scope
*/
@Input() scope: string;

/**
* True when the filter is 100% collapsed in the UI
*/
Expand Down Expand Up @@ -171,6 +176,9 @@ export class SearchFilterComponent implements OnInit {
} else {
return this.searchConfigService.searchOptions.pipe(
switchMap((options) => {
if (hasValue(this.scope)) {
options.scope = this.scope;
}
return this.searchService.getFacetValuesFor(this.filter, 1, options).pipe(
filter((RD) => !RD.isLoading),
map((valuesRD) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { CommonModule } from '@angular/common';
import { SearchService } from '../../../../../core/shared/search/search.service';
import {
FILTER_CONFIG,
SCOPE,
IN_PLACE_SEARCH,
SearchFilterService,
REFRESH_FILTER
Expand Down Expand Up @@ -75,7 +76,8 @@ describe('SearchHierarchyFilterComponent', () => {
{ provide: SEARCH_CONFIG_SERVICE, useValue: new SearchConfigurationServiceStub() },
{ provide: IN_PLACE_SEARCH, useValue: false },
{ provide: FILTER_CONFIG, useValue: Object.assign(new SearchFilterConfig(), { name: testSearchFilter }) },
{ provide: REFRESH_FILTER, useValue: new BehaviorSubject<boolean>(false)}
{ provide: REFRESH_FILTER, useValue: new BehaviorSubject<boolean>(false)},
{ provide: SCOPE, useValue: undefined },
],
schemas: [NO_ERRORS_SCHEMA],
}).compileComponents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { SearchService } from '../../../../../core/shared/search/search.service';
import {
FILTER_CONFIG,
SCOPE,
IN_PLACE_SEARCH,
SearchFilterService, REFRESH_FILTER
} from '../../../../../core/shared/search/search-filter.service';
Expand Down Expand Up @@ -49,9 +50,10 @@ export class SearchHierarchyFilterComponent extends SearchFacetFilterComponent i
@Inject(SEARCH_CONFIG_SERVICE) public searchConfigService: SearchConfigurationService,
@Inject(IN_PLACE_SEARCH) public inPlaceSearch: boolean,
@Inject(FILTER_CONFIG) public filterConfig: SearchFilterConfig,
@Inject(REFRESH_FILTER) public refreshFilters: BehaviorSubject<boolean>
@Inject(REFRESH_FILTER) public refreshFilters: BehaviorSubject<boolean>,
@Inject(SCOPE) public scope: string,
) {
super(searchService, filterService, rdbs, router, searchConfigService, inPlaceSearch, filterConfig, refreshFilters);
super(searchService, filterService, rdbs, router, searchConfigService, inPlaceSearch, filterConfig, refreshFilters, scope);
}

vocabularyExists$: Observable<boolean>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TranslateModule } from '@ngx-translate/core';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import {
FILTER_CONFIG,
SCOPE,
IN_PLACE_SEARCH,
REFRESH_FILTER,
SearchFilterService
Expand Down Expand Up @@ -105,6 +106,7 @@ describe('SearchRangeFilterComponent', () => {
{ provide: SEARCH_CONFIG_SERVICE, useValue: new SearchConfigurationServiceStub() },
{ provide: IN_PLACE_SEARCH, useValue: false },
{ provide: REFRESH_FILTER, useValue: new BehaviorSubject<boolean>(false) },
{ provide: SCOPE, useValue: undefined },
{
provide: SearchFilterService, useValue: {
getSelectedValuesForFilter: () => selectedValues,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { facetLoad, SearchFacetFilterComponent } from '../search-facet-filter/se
import { SearchFilterConfig } from '../../../models/search-filter-config.model';
import {
FILTER_CONFIG,
SCOPE,
IN_PLACE_SEARCH,
REFRESH_FILTER,
SearchFilterService
Expand Down Expand Up @@ -101,8 +102,9 @@ export class SearchRangeFilterComponent extends SearchFacetFilterComponent imple
@Inject(FILTER_CONFIG) public filterConfig: SearchFilterConfig,
@Inject(PLATFORM_ID) private platformId: any,
@Inject(REFRESH_FILTER) public refreshFilters: BehaviorSubject<boolean>,
@Inject(SCOPE) public scope: string,
private route: RouteService) {
super(searchService, filterService, rdbs, router, searchConfigService, inPlaceSearch, filterConfig, refreshFilters);
super(searchService, filterService, rdbs, router, searchConfigService, inPlaceSearch, filterConfig, refreshFilters, scope);

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h3>{{"search.filters.head" | translate}}</h3>
<div *ngIf="(filters | async)?.hasSucceeded">
<div *ngFor="let filter of (filters | async)?.payload; trackBy: trackUpdate">
<ds-search-filter [filter]="filter" [inPlaceSearch]="inPlaceSearch" [refreshFilters]="refreshFilters"></ds-search-filter>
<ds-search-filter [scope]="currentScope" [filter]="filter" [inPlaceSearch]="inPlaceSearch" [refreshFilters]="refreshFilters"></ds-search-filter>
</div>
</div>
<a class="btn btn-primary" [routerLink]="[searchLink]" [queryParams]="clearParams | async" queryParamsHandling="merge" role="button"><i class="fas fa-undo"></i> {{"search.filters.reset" | translate}}</a>
Original file line number Diff line number Diff line change
@@ -1,53 +1,39 @@
import { SearchService } from '../../../core/shared/search/search.service';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { SearchSettingsComponent } from './search-settings.component';
import { of as observableOf } from 'rxjs';
import { PaginationComponentOptions } from '../../pagination/pagination-component-options.model';
import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model';
import { TranslateModule } from '@ngx-translate/core';
import { RouterTestingModule } from '@angular/router/testing';
import { ActivatedRoute } from '@angular/router';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { EnumKeysPipe } from '../../utils/enum-keys-pipe';
import { By } from '@angular/platform-browser';
import { SearchFilterService } from '../../../core/shared/search/search-filter.service';
import { VarDirective } from '../../utils/var.directive';
import { SEARCH_CONFIG_SERVICE } from '../../../my-dspace-page/my-dspace-page.component';
import { SidebarService } from '../../sidebar/sidebar.service';
import { SidebarServiceStub } from '../../testing/sidebar-service.stub';
import { PaginationService } from '../../../core/pagination/pagination.service';
import { PaginationServiceStub } from '../../testing/pagination-service.stub';

describe('SearchSettingsComponent', () => {

let comp: SearchSettingsComponent;
let fixture: ComponentFixture<SearchSettingsComponent>;
let searchServiceObject: SearchService;

let pagination: PaginationComponentOptions;
let sort: SortOptions;
let mockResults;
let searchServiceStub;

let queryParam;
let scopeParam;
let paginatedSearchOptions;

let paginationService;
let paginationService: PaginationServiceStub;

let activatedRouteStub;

beforeEach(waitForAsync(() => {
beforeEach(waitForAsync(async () => {
pagination = new PaginationComponentOptions();
pagination.id = 'search-results-pagination';
pagination.currentPage = 1;
pagination.pageSize = 10;
sort = new SortOptions('score', SortDirection.DESC);
mockResults = ['test', 'data'];
searchServiceStub = {
searchOptions: { pagination: pagination, sort: sort },
search: () => mockResults,
};

queryParam = 'test query';
scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
Expand All @@ -58,30 +44,12 @@ describe('SearchSettingsComponent', () => {
sort,
};

activatedRouteStub = {
queryParams: observableOf({
query: queryParam,
scope: scopeParam,
}),
};

paginationService = new PaginationServiceStub(pagination, sort);

TestBed.configureTestingModule({
await TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
declarations: [SearchSettingsComponent, EnumKeysPipe, VarDirective],
providers: [
{ provide: SearchService, useValue: searchServiceStub },

{ provide: ActivatedRoute, useValue: activatedRouteStub },
{
provide: SidebarService,
useValue: SidebarServiceStub,
},
{
provide: SearchFilterService,
useValue: {},
},
{
provide: PaginationService,
useValue: paginationService,
Expand Down Expand Up @@ -111,10 +79,7 @@ describe('SearchSettingsComponent', () => {

// SearchPageComponent test instance
fixture.detectChanges();
searchServiceObject = (comp as any).service;
spyOn(comp, 'reloadOrder');
spyOn(searchServiceObject, 'search').and.callThrough();

});

it('it should show the order settings with the respective selectable options', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Component, Inject, Input } from '@angular/core';
import { SearchService } from '../../../core/shared/search/search.service';
import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model';
import { ActivatedRoute, Router } from '@angular/router';
import { SearchConfigurationService } from '../../../core/shared/search/search-configuration.service';
import { SEARCH_CONFIG_SERVICE } from '../../../my-dspace-page/my-dspace-page.component';
import { PaginationService } from '../../../core/pagination/pagination.service';
Expand All @@ -26,11 +24,10 @@ export class SearchSettingsComponent {
*/
@Input() sortOptionsList: SortOptions[];

constructor(private service: SearchService,
private route: ActivatedRoute,
private router: Router,
private paginationService: PaginationService,
@Inject(SEARCH_CONFIG_SERVICE) public searchConfigurationService: SearchConfigurationService) {
constructor(
protected paginationService: PaginationService,
@Inject(SEARCH_CONFIG_SERVICE) public searchConfigurationService: SearchConfigurationService,
) {
}

/**
Expand Down
Loading

0 comments on commit 9dc0363

Please sign in to comment.