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', () => {
it('should return the selectedValue list with the new parameter value', () => {
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', () => {
it('should return the selectedValue list with the parameter value left out', () => {
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);
}
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) {
return { [this.filterConfig.paramName]: [...this.selectedValues, value] };
return {
[this.filterConfig.paramName]: [...this.selectedValues, value],
page: 1
};
}
ngOnDestroy(): void {

View File

@@ -23,8 +23,6 @@ export class SearchFiltersComponent {
constructor(private searchService: SearchService, private filterService: SearchFilterService) {
this.filters = searchService.getConfig();
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() {

View File

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

View File

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