diff --git a/src/app/category-list/category-list-page.spec.ts b/src/app/category-list/category-list-page.spec.ts index a0b0be3f92..044c082908 100644 --- a/src/app/category-list/category-list-page.spec.ts +++ b/src/app/category-list/category-list-page.spec.ts @@ -534,7 +534,7 @@ describe('CategoryListPage', () => { "groupSortBy": [{ "name": { "order": "asc", - "preference": ['audience', ['subject 1'], ["accountancy"],["subject 1"]] + "preference": ["accountancy",["subject 1"]] }, }]}, filterPillBy: null diff --git a/src/app/category-list/category-list-page.ts b/src/app/category-list/category-list-page.ts index 498c793ce4..498f7de1eb 100755 --- a/src/app/category-list/category-list-page.ts +++ b/src/app/category-list/category-list-page.ts @@ -81,6 +81,7 @@ export class CategoryListPage implements OnInit, OnDestroy { fromLibrary = false; sectionCode = ''; primaryFacetFiltersFormGroup: FormGroup; + filterFields: {[k: string]: any} = {}; private readonly searchCriteria: ContentSearchCriteria; private readonly filterCriteria: ContentSearchCriteria; @@ -202,7 +203,7 @@ export class CategoryListPage implements OnInit, OnDestroy { ); } - private async fetchAndSortData(searchCriteria, isInitialCall: boolean, refreshPillFilter = true, onSelectedFilter?: any) { + private async fetchAndSortData(searchCriteria, isInitialCall: boolean, refreshPillFilter = true, onSelectedFilter?: any, filterKey?) { this.showSheenAnimation = true; this.profile = await this.profileService.getActiveSessionProfile({ requiredFields: ProfileConstants.REQUIRED_FIELDS }).toPromise(); if (onSelectedFilter) { @@ -210,14 +211,20 @@ export class CategoryListPage implements OnInit, OnDestroy { onSelectedFilter.forEach((selectedFilter) => { selectedData.push(selectedFilter.name); }); + if (filterKey) { + this.filterFields = this.filterFields ? this.filterFields : {}; + this.filterFields[filterKey] = selectedData; + } if (this.formField.aggregate && this.formField.aggregate.groupSortBy && this.formField.aggregate.groupSortBy.length) { this.formField.aggregate.groupSortBy.forEach((data) => { - if (data.name && data.name.preference && data.name.preference.length) { - data.name.preference.push(selectedData); - } else { - data.name.preference = selectedData; - } - }); + let applyFilters = []; + Object.keys(this.filterFields).forEach((e) => { + if (this.filterFields[e].length) { + applyFilters = applyFilters.concat(this.filterFields[e]); + } + }); + data.name.preference = applyFilters; + }); } } @@ -503,11 +510,11 @@ export class CategoryListPage implements OnInit, OnDestroy { onSelectedFilter.push(selectedValue.name); }); - await this.applyFilter(appliedFilterCriteria, true, toApply); + await this.applyFilter(appliedFilterCriteria, true, toApply, primaryFacetFilter.code); } } - private async applyFilter(appliedFilterCriteria: ContentSearchCriteria, refreshPillFilter = true, onSelectedFilter?) { + private async applyFilter(appliedFilterCriteria: ContentSearchCriteria, refreshPillFilter = true, onSelectedFilter?, filterKey?) { const tempSearchCriteria: ContentSearchCriteria = { ...appliedFilterCriteria, mode: 'hard', @@ -521,7 +528,7 @@ export class CategoryListPage implements OnInit, OnDestroy { } } }); - await this.fetchAndSortData(tempSearchCriteria, false, refreshPillFilter, onSelectedFilter); + await this.fetchAndSortData(tempSearchCriteria, false, refreshPillFilter, onSelectedFilter, filterKey); } async pillFilterHandler(pill){