Merge pull request #477 from atmire/64644-Removal-of-filtered-discovery-page

Removal of filtered-discovery-page in Angular
This commit is contained in:
Tim Donohue
2019-09-16 19:08:21 +02:00
committed by GitHub
8 changed files with 3 additions and 139 deletions

View File

@@ -82,9 +82,6 @@ describe('MyDSpacePageComponent', () => {
expand: () => this.isCollapsed = observableOf(false) expand: () => this.isCollapsed = observableOf(false)
}; };
const mockFixedFilterService: SearchFixedFilterService = { const mockFixedFilterService: SearchFixedFilterService = {
getQueryByFilterName: (filter: string) => {
return observableOf(undefined)
}
} as SearchFixedFilterService; } as SearchFixedFilterService;
beforeEach(async(() => { beforeEach(async(() => {

View File

@@ -28,11 +28,7 @@ describe('SearchFilterService', () => {
pageSize: 2 pageSize: 2
}); });
const mockFixedFilterService: SearchFixedFilterService = { const mockFixedFilterService: SearchFixedFilterService = {} as SearchFixedFilterService
getQueryByFilterName: (filter: string) => {
return observableOf(undefined)
}
} as SearchFixedFilterService
const value1 = 'random value'; const value1 = 'random value';
// const value2 = 'another value'; // const value2 = 'another value';
const store: Store<SearchFiltersState> = jasmine.createSpyObj('store', { const store: Store<SearchFiltersState> = jasmine.createSpyObj('store', {
@@ -264,20 +260,6 @@ 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', () => { describe('when the getCurrentView method is called', () => {
beforeEach(() => { beforeEach(() => {
spyOn(routeServiceStub, 'getQueryParameterValue'); spyOn(routeServiceStub, 'getQueryParameterValue');

View File

@@ -113,15 +113,6 @@ export class SearchFilterService {
return this.routeService.getQueryParamsWithPrefix('f.'); return this.routeService.getQueryParamsWithPrefix('f.');
} }
/**
* Fetch the current active fixed filter from the route parameters and return the query by filter name
* @returns {Observable<string>}
*/
getCurrentFixedFilter(): Observable<string> {
const filter: Observable<string> = this.routeService.getRouteParameterValue('filter');
return filter.pipe(mergeMap((f) => this.fixedFilterService.getQueryByFilterName(f)));
}
/** /**
* Fetch the current view from the query parameters * Fetch the current view from the query parameters
* @returns {Observable<string>} * @returns {Observable<string>}

View File

@@ -1,6 +1,5 @@
import { SearchFixedFilterService } from './search-fixed-filter.service'; import { SearchFixedFilterService } from './search-fixed-filter.service';
import { RequestService } from '../../../core/data/request.service'; import { RequestService } from '../../../core/data/request.service';
import { HALEndpointService } from '../../../core/shared/hal-endpoint.service';
import { of as observableOf } from 'rxjs'; import { of as observableOf } from 'rxjs';
import { RequestEntry } from '../../../core/data/request.reducer'; import { RequestEntry } from '../../../core/data/request.reducer';
import { FilteredDiscoveryQueryResponse } from '../../../core/cache/response.models'; import { FilteredDiscoveryQueryResponse } from '../../../core/cache/response.models';
@@ -20,28 +19,9 @@ describe('SearchFixedFilterService', () => {
response: new FilteredDiscoveryQueryResponse(filterQuery, 200, 'OK') response: new FilteredDiscoveryQueryResponse(filterQuery, 200, 'OK')
})) }))
}) as RequestService; }) as RequestService;
const halServiceStub = Object.assign(new HALEndpointService(requestServiceStub, undefined), {
getEndpoint: () => observableOf('fake-url')
});
beforeEach(() => { beforeEach(() => {
service = new SearchFixedFilterService(requestServiceStub, halServiceStub); service = new SearchFixedFilterService();
});
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();
});
});
}); });
describe('when getQueryByRelations is called', () => { describe('when getQueryByRelations is called', () => {

View File

@@ -1,61 +1,10 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { map, switchMap } 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 { FilteredDiscoveryQueryResponse } from '../../../core/cache/response.models';
/** /**
* Service for performing actions on the filtered-discovery-pages REST endpoint * Service for performing actions on the filtered-discovery-pages REST endpoint
*/ */
@Injectable() @Injectable()
export class SearchFixedFilterService { export class SearchFixedFilterService {
private queryByFilterPath = 'filtered-discovery-pages';
constructor(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<string>} Filter query
*/
getQueryByFilterName(filterName: string): Observable<string> {
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<ResponseParsingService> {
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 * Get the query for looking up items by relation type

View File

@@ -89,11 +89,7 @@ const routeServiceStub = {
return observableOf('') return observableOf('')
} }
}; };
const mockFixedFilterService: SearchFixedFilterService = { const mockFixedFilterService: SearchFixedFilterService = {} as SearchFixedFilterService;
getQueryByFilterName: (filter: string) => {
return observableOf(undefined)
}
} as SearchFixedFilterService;
export function configureSearchComponentTestingModule(compType) { export function configureSearchComponentTestingModule(compType) {
TestBed.configureTestingModule({ TestBed.configureTestingModule({

View File

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

View File

@@ -205,15 +205,6 @@ export class SearchConfigurationService implements OnDestroy {
})); }));
} }
/**
* @returns {Observable<string>} Emits the current fixed filter as a string
*/
getCurrentFixedFilter(): Observable<string> {
return this.routeService.getRouteParameterValue('filter').pipe(
switchMap((f) => this.fixedFilterService.getQueryByFilterName(f))
);
}
/** /**
* @returns {Observable<Params>} Emits the current active filters with their values as they are displayed in the frontend URL * @returns {Observable<Params>} 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.getQueryPart(defaults.query),
this.getDSOTypePart(), this.getDSOTypePart(),
this.getFiltersPart(), this.getFiltersPart(),
this.getFixedFilterPart()
).subscribe((update) => { ).subscribe((update) => {
const currentValue: SearchOptions = this.searchOptions.getValue(); const currentValue: SearchOptions = this.searchOptions.getValue();
const updatedValue: SearchOptions = Object.assign(currentValue, update); const updatedValue: SearchOptions = Object.assign(currentValue, update);
@@ -255,7 +245,6 @@ export class SearchConfigurationService implements OnDestroy {
this.getQueryPart(defaults.query), this.getQueryPart(defaults.query),
this.getDSOTypePart(), this.getDSOTypePart(),
this.getFiltersPart(), this.getFiltersPart(),
this.getFixedFilterPart()
).subscribe((update) => { ).subscribe((update) => {
const currentValue: PaginatedSearchOptions = this.paginatedSearchOptions.getValue(); const currentValue: PaginatedSearchOptions = this.paginatedSearchOptions.getValue();
const updatedValue: PaginatedSearchOptions = Object.assign(currentValue, update); const updatedValue: PaginatedSearchOptions = Object.assign(currentValue, update);
@@ -352,16 +341,4 @@ export class SearchConfigurationService implements OnDestroy {
return { filters } return { filters }
})); }));
} }
/**
* @returns {Observable<string>} Emits the current fixed filter as a partial SearchOptions object
*/
private getFixedFilterPart(): Observable<any> {
return this.getCurrentFixedFilter().pipe(
isNotEmptyOperator(),
map((fixedFilter) => {
return { fixedFilter }
}),
);
}
} }