From 22df3ec7f2a8542831ba98dab821ebe4477cf9aa Mon Sep 17 00:00:00 2001 From: Yana De Pauw Date: Thu, 29 Aug 2019 16:33:38 +0200 Subject: [PATCH] 64644: Removal of filtered discovery page --- .../my-dspace-page.component.spec.ts | 3 -- .../search-filter.service.spec.ts | 18 +------ .../search-filter/search-filter.service.ts | 9 ---- .../search-fixed-filter.service.spec.ts | 23 ++------ .../search-fixed-filter.service.ts | 53 ------------------- .../search-page.component.spec.ts | 6 +-- .../search-configuration.service.spec.ts | 8 --- .../search-configuration.service.ts | 23 -------- 8 files changed, 6 insertions(+), 137 deletions(-) diff --git a/src/app/+my-dspace-page/my-dspace-page.component.spec.ts b/src/app/+my-dspace-page/my-dspace-page.component.spec.ts index 34af21073f..d9b5facb5b 100644 --- a/src/app/+my-dspace-page/my-dspace-page.component.spec.ts +++ b/src/app/+my-dspace-page/my-dspace-page.component.spec.ts @@ -82,9 +82,6 @@ describe('MyDSpacePageComponent', () => { expand: () => this.isCollapsed = observableOf(false) }; const mockFixedFilterService: SearchFixedFilterService = { - getQueryByFilterName: (filter: string) => { - return observableOf(undefined) - } } as SearchFixedFilterService; beforeEach(async(() => { diff --git a/src/app/+search-page/search-filters/search-filter/search-filter.service.spec.ts b/src/app/+search-page/search-filters/search-filter/search-filter.service.spec.ts index e317a27698..fe89d182d4 100644 --- a/src/app/+search-page/search-filters/search-filter/search-filter.service.spec.ts +++ b/src/app/+search-page/search-filters/search-filter/search-filter.service.spec.ts @@ -28,11 +28,7 @@ describe('SearchFilterService', () => { pageSize: 2 }); - const mockFixedFilterService: SearchFixedFilterService = { - getQueryByFilterName: (filter: string) => { - return observableOf(undefined) - } - } as SearchFixedFilterService + const mockFixedFilterService: SearchFixedFilterService = {} as SearchFixedFilterService const value1 = 'random value'; // const value2 = 'another value'; const store: Store = jasmine.createSpyObj('store', { @@ -264,19 +260,7 @@ describe('SearchFilterService', () => { }); }); - describe('when the getCurrentFixedFilter method is called', () => { - const filter = 'filter'; - beforeEach(() => { - spyOn(routeServiceStub, 'getRouteParameterValue').and.returnValue(observableOf(filter)); - spyOn(mockFixedFilterService, 'getQueryByFilterName').and.returnValue(observableOf(filter)); - service.getCurrentFixedFilter().subscribe(); - }); - - it('should call getQueryByFilterName on the fixed-filter service with the correct filter', () => { - expect(mockFixedFilterService.getQueryByFilterName).toHaveBeenCalledWith(filter); - }); - }); describe('when the getCurrentView method is called', () => { beforeEach(() => { diff --git a/src/app/+search-page/search-filters/search-filter/search-filter.service.ts b/src/app/+search-page/search-filters/search-filter/search-filter.service.ts index 4b12417084..68aca01a9e 100644 --- a/src/app/+search-page/search-filters/search-filter/search-filter.service.ts +++ b/src/app/+search-page/search-filters/search-filter/search-filter.service.ts @@ -117,15 +117,6 @@ export class SearchFilterService { return this.routeService.getQueryParamsWithPrefix('f.'); } - /** - * Fetch the current active fixed filter from the route parameters and return the query by filter name - * @returns {Observable} - */ - getCurrentFixedFilter(): Observable { - const filter: Observable = this.routeService.getRouteParameterValue('filter'); - return filter.pipe(mergeMap((f) => this.fixedFilterService.getQueryByFilterName(f))); - } - /** * Fetch the current view from the query parameters * @returns {Observable} diff --git a/src/app/+search-page/search-filters/search-filter/search-fixed-filter.service.spec.ts b/src/app/+search-page/search-filters/search-filter/search-fixed-filter.service.spec.ts index 3f6c2ef133..1ff52e89a4 100644 --- a/src/app/+search-page/search-filters/search-filter/search-fixed-filter.service.spec.ts +++ b/src/app/+search-page/search-filters/search-filter/search-fixed-filter.service.spec.ts @@ -4,7 +4,7 @@ import { RequestService } from '../../../core/data/request.service'; import { HALEndpointService } from '../../../core/shared/hal-endpoint.service'; import { of as observableOf } from 'rxjs'; import { RequestEntry } from '../../../core/data/request.reducer'; -import { FilteredDiscoveryQueryResponse, RestResponse } from '../../../core/cache/response.models'; +import { FilteredDiscoveryQueryResponse } from '../../../core/cache/response.models'; describe('SearchFixedFilterService', () => { let service: SearchFixedFilterService; @@ -14,7 +14,8 @@ describe('SearchFixedFilterService', () => { const routeServiceStub = {} as RouteService; const requestServiceStub = Object.assign({ /* tslint:disable:no-empty */ - configure: () => {}, + configure: () => { + }, /* tslint:enable:no-empty */ generateRequestId: () => 'fake-id', getByHref: () => observableOf(Object.assign(new RequestEntry(), { @@ -26,23 +27,7 @@ describe('SearchFixedFilterService', () => { }); beforeEach(() => { - service = new SearchFixedFilterService(routeServiceStub, requestServiceStub, halServiceStub); - }); - - describe('when getQueryByFilterName is called with a filterName', () => { - it('should return the filter query', () => { - service.getQueryByFilterName('filter').subscribe((query) => { - expect(query).toBe(filterQuery); - }); - }); - }); - - describe('when getQueryByFilterName is called without a filterName', () => { - it('should return undefined', () => { - service.getQueryByFilterName(undefined).subscribe((query) => { - expect(query).toBeUndefined(); - }); - }); + service = new SearchFixedFilterService(); }); describe('when getQueryByRelations is called', () => { diff --git a/src/app/+search-page/search-filters/search-filter/search-fixed-filter.service.ts b/src/app/+search-page/search-filters/search-filter/search-fixed-filter.service.ts index 0f17b508c9..e2ac7e1547 100644 --- a/src/app/+search-page/search-filters/search-filter/search-fixed-filter.service.ts +++ b/src/app/+search-page/search-filters/search-filter/search-fixed-filter.service.ts @@ -1,63 +1,10 @@ import { Injectable } from '@angular/core'; -import { flatMap, map, switchMap, tap } from 'rxjs/operators'; -import { Observable, of as observableOf } from 'rxjs'; -import { HALEndpointService } from '../../../core/shared/hal-endpoint.service'; -import { GetRequest, RestRequest } from '../../../core/data/request.models'; -import { RequestService } from '../../../core/data/request.service'; -import { ResponseParsingService } from '../../../core/data/parsing.service'; -import { GenericConstructor } from '../../../core/shared/generic-constructor'; -import { FilteredDiscoveryPageResponseParsingService } from '../../../core/data/filtered-discovery-page-response-parsing.service'; -import { hasValue } from '../../../shared/empty.util'; -import { configureRequest, getResponseFromEntry } from '../../../core/shared/operators'; -import { RouteService } from '../../../shared/services/route.service'; -import { FilteredDiscoveryQueryResponse } from '../../../core/cache/response.models'; /** * Service for performing actions on the filtered-discovery-pages REST endpoint */ @Injectable() export class SearchFixedFilterService { - private queryByFilterPath = 'filtered-discovery-pages'; - - constructor(private routeService: RouteService, - protected requestService: RequestService, - private halService: HALEndpointService) { - - } - - /** - * Get the filter query for a certain filter by name - * @param {string} filterName Name of the filter - * @returns {Observable} Filter query - */ - getQueryByFilterName(filterName: string): Observable { - if (hasValue(filterName)) { - const requestUuid = this.requestService.generateRequestId(); - const requestObs = this.halService.getEndpoint(this.queryByFilterPath).pipe( - map((url: string) => { - url += ('/' + filterName); - const request = new GetRequest(requestUuid, url); - return Object.assign(request, { - getResponseParser(): GenericConstructor { - return FilteredDiscoveryPageResponseParsingService; - } - }); - }), - configureRequest(this.requestService) - ); - - const requestEntryObs = requestObs.pipe( - switchMap((request: RestRequest) => this.requestService.getByHref(request.href)), - ); - const filterQuery = requestEntryObs.pipe( - getResponseFromEntry(), - map((response: FilteredDiscoveryQueryResponse) => - response.filterQuery - )); - return filterQuery; - } - return observableOf(undefined); - } /** * Get the query for looking up items by relation type diff --git a/src/app/+search-page/search-page.component.spec.ts b/src/app/+search-page/search-page.component.spec.ts index fe4c301bd5..1b26e70ba9 100644 --- a/src/app/+search-page/search-page.component.spec.ts +++ b/src/app/+search-page/search-page.component.spec.ts @@ -89,11 +89,7 @@ const routeServiceStub = { return observableOf('') } }; -const mockFixedFilterService: SearchFixedFilterService = { - getQueryByFilterName: (filter: string) => { - return observableOf(undefined) - } -} as SearchFixedFilterService; +const mockFixedFilterService: SearchFixedFilterService = {} as SearchFixedFilterService; export function configureSearchComponentTestingModule(compType) { TestBed.configureTestingModule({ diff --git a/src/app/+search-page/search-service/search-configuration.service.spec.ts b/src/app/+search-page/search-service/search-configuration.service.spec.ts index fb95ab8d04..f1aedd9fe5 100644 --- a/src/app/+search-page/search-service/search-configuration.service.spec.ts +++ b/src/app/+search-page/search-service/search-configuration.service.spec.ts @@ -163,12 +163,4 @@ describe('SearchConfigurationService', () => { }); }); - describe('when getCurrentFixedFilter is called', () => { - beforeEach(() => { - service.getCurrentFixedFilter(); - }); - it('should call getRouteParameterValue on the routeService with parameter name \'filter\'', () => { - expect((service as any).routeService.getRouteParameterValue).toHaveBeenCalledWith('filter'); - }); - }); }); diff --git a/src/app/+search-page/search-service/search-configuration.service.ts b/src/app/+search-page/search-service/search-configuration.service.ts index 06efc16be2..6258140a4e 100644 --- a/src/app/+search-page/search-service/search-configuration.service.ts +++ b/src/app/+search-page/search-service/search-configuration.service.ts @@ -205,15 +205,6 @@ export class SearchConfigurationService implements OnDestroy { })); } - /** - * @returns {Observable} Emits the current fixed filter as a string - */ - getCurrentFixedFilter(): Observable { - return this.routeService.getRouteParameterValue('filter').pipe( - switchMap((f) => this.fixedFilterService.getQueryByFilterName(f)) - ); - } - /** * @returns {Observable} Emits the current active filters with their values as they are displayed in the frontend URL */ @@ -233,7 +224,6 @@ export class SearchConfigurationService implements OnDestroy { this.getQueryPart(defaults.query), this.getDSOTypePart(), this.getFiltersPart(), - this.getFixedFilterPart() ).subscribe((update) => { const currentValue: SearchOptions = this.searchOptions.getValue(); const updatedValue: SearchOptions = Object.assign(currentValue, update); @@ -255,7 +245,6 @@ export class SearchConfigurationService implements OnDestroy { this.getQueryPart(defaults.query), this.getDSOTypePart(), this.getFiltersPart(), - this.getFixedFilterPart() ).subscribe((update) => { const currentValue: PaginatedSearchOptions = this.paginatedSearchOptions.getValue(); const updatedValue: PaginatedSearchOptions = Object.assign(currentValue, update); @@ -352,16 +341,4 @@ export class SearchConfigurationService implements OnDestroy { return { filters } })); } - - /** - * @returns {Observable} Emits the current fixed filter as a partial SearchOptions object - */ - private getFixedFilterPart(): Observable { - return this.getCurrentFixedFilter().pipe( - isNotEmptyOperator(), - map((fixedFilter) => { - return { fixedFilter } - }), - ); - } }