added support for Object.entries, removed a console.log and fixed an issue where the page wouldn't reset after selecting a new filter

This commit is contained in:
Art Lowel
2018-04-26 14:36:19 +02:00
parent 5ad190c906
commit d6fc8aca4f
5 changed files with 13 additions and 7 deletions

View File

@@ -124,14 +124,14 @@ describe('SearchFacetFilterComponent', () => {
describe('when the getAddParams method is called wih a value', () => { describe('when the getAddParams method is called wih a value', () => {
it('should return the selectedValue list with the new parameter value', () => { it('should return the selectedValue list with the new parameter value', () => {
const result = comp.getAddParams(value3); const result = comp.getAddParams(value3);
expect(result).toEqual({ [mockFilterConfig.paramName]: [value1, value2, value3] }); expect(result[mockFilterConfig.paramName]).toEqual([value1, value2, value3]);
}); });
}); });
describe('when the getRemoveParams method is called wih a value', () => { describe('when the getRemoveParams method is called wih a value', () => {
it('should return the selectedValue list with the parameter value left out', () => { it('should return the selectedValue list with the parameter value left out', () => {
const result = comp.getRemoveParams(value1); const result = comp.getRemoveParams(value1);
expect(result).toEqual({ [mockFilterConfig.paramName]: [value2] }); expect(result[mockFilterConfig.paramName]).toEqual([value2]);
}); });
}); });

View File

@@ -100,11 +100,17 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
return hasValue(o); return hasValue(o);
} }
getRemoveParams(value: string) { getRemoveParams(value: string) {
return { [this.filterConfig.paramName]: this.selectedValues.filter((v) => v !== value) }; return {
[this.filterConfig.paramName]: this.selectedValues.filter((v) => v !== value),
page: 1
};
} }
getAddParams(value: string) { getAddParams(value: string) {
return { [this.filterConfig.paramName]: [...this.selectedValues, value] }; return {
[this.filterConfig.paramName]: [...this.selectedValues, value],
page: 1
};
} }
ngOnDestroy(): void { ngOnDestroy(): void {

View File

@@ -23,8 +23,6 @@ export class SearchFiltersComponent {
constructor(private searchService: SearchService, private filterService: SearchFilterService) { constructor(private searchService: SearchService, private filterService: SearchFilterService) {
this.filters = searchService.getConfig(); this.filters = searchService.getConfig();
this.clearParams = filterService.getCurrentFilters().map((filters) => {Object.keys(filters).forEach((f) => filters[f] = null); return filters;}); this.clearParams = filterService.getCurrentFilters().map((filters) => {Object.keys(filters).forEach((f) => filters[f] = null); return filters;});
this.filters.subscribe((v) => console.log('this.filters', v));
} }
getSearchLink() { getSearchLink() {

View File

@@ -1,5 +1,6 @@
import { isNotEmpty } from '../shared/empty.util'; import { isNotEmpty } from '../shared/empty.util';
import { URLCombiner } from '../core/url-combiner/url-combiner'; import { URLCombiner } from '../core/url-combiner/url-combiner';
import 'core-js/fn/object/entries';
export enum ViewMode { export enum ViewMode {
List = 'list', List = 'list',

View File

@@ -26,7 +26,8 @@
"es6", "es6",
"es2015", "es2015",
"es2016", "es2016",
"es2017" "es2017",
"es2017.object"
] ]
}, },
"exclude": [ "exclude": [