mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
Improve search filter component: hide a facet if there is no filter category (#6282)
* New feature: Search Filter Component - Hide facet if there is no filter category * remove comments * Fix lint errors * Fix-Add unit tests * Change demo shell facet query to current year * Fix search e2e to use always current year Co-authored-by: Raphael Kister <raphael.kister@alfresco.com> Co-authored-by: Eugenio Romano <eugenio.romano@alfresco.com>
This commit is contained in:
@@ -609,3 +609,21 @@ export const filteredResult = [
|
||||
'my4 (665)',
|
||||
'my5 (1866)'
|
||||
];
|
||||
|
||||
export const mockContentSizeResponseBucket = {
|
||||
'label': '5875',
|
||||
'filterQuery': 'content.size:5875',
|
||||
'metrics': [
|
||||
{
|
||||
'type': 'count',
|
||||
'value': {
|
||||
'count': 364
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
export function getMockSearchResultWithResponseBucket() {
|
||||
mockSearchResult.list.context.facets[3].buckets.push(mockContentSizeResponseBucket);
|
||||
return mockSearchResult;
|
||||
}
|
||||
|
@@ -30,6 +30,7 @@ import {
|
||||
expandableCategories,
|
||||
expandedCategories,
|
||||
filteredResult,
|
||||
getMockSearchResultWithResponseBucket,
|
||||
mockSearchResult,
|
||||
searchFilter,
|
||||
simpleCategories,
|
||||
@@ -340,7 +341,7 @@ describe('SearchFilterComponent', () => {
|
||||
};
|
||||
|
||||
component.onDataLoaded(data);
|
||||
expect(component.responseFacets.length).toEqual(2);
|
||||
expect(component.responseFacets.length).toEqual(1);
|
||||
expect(component.responseFacets[0].buckets.items[0].count).toEqual(10);
|
||||
expect(component.responseFacets[0].buckets.items[1].count).toEqual(1);
|
||||
});
|
||||
@@ -706,9 +707,8 @@ describe('SearchFilterComponent', () => {
|
||||
|
||||
component.onDataLoaded(data);
|
||||
|
||||
expect(component.responseFacets.length).toBe(2);
|
||||
expect(component.responseFacets.length).toBe(1);
|
||||
expect(component.responseFacets[0].buckets.length).toEqual(1);
|
||||
expect(component.responseFacets[1].buckets.length).toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -799,9 +799,27 @@ describe('SearchFilterComponent', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel'));
|
||||
expect(panels.length).toBe(16);
|
||||
expect(panels.length).toBe(8);
|
||||
}));
|
||||
|
||||
it('should add a panel only for the response buckets that are present in the response', async () => {
|
||||
appConfigService.config.search = searchFilter;
|
||||
queryBuilder.resetToDefaults();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const inputElement = fixture.debugElement.query(By.css('[data-automation-id="expansion-panel-Name"] input'));
|
||||
inputElement.triggerEventHandler('change', { target: { value: '*' } });
|
||||
|
||||
queryBuilder.executed.next(<any> getMockSearchResultWithResponseBucket());
|
||||
fixture.detectChanges();
|
||||
|
||||
const panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel'));
|
||||
|
||||
expect(panels.length).toBe(9);
|
||||
});
|
||||
|
||||
it('should show the long facet options list with pagination', () => {
|
||||
const panel = '[data-automation-id="expansion-panel-Size facet queries"]';
|
||||
appConfigService.config.search = searchFilter;
|
||||
|
@@ -214,21 +214,22 @@ export class SearchFilterComponent implements OnInit, OnDestroy {
|
||||
|
||||
this.updateExistingBuckets(responseField, responseBuckets, alreadyExistingField, alreadyExistingBuckets);
|
||||
} else if (responseField && this.showContextFacets) {
|
||||
if (responseBuckets.length > 0) {
|
||||
const bucketList = new SearchFilterList<FacetFieldBucket>(responseBuckets, field.pageSize);
|
||||
bucketList.filter = this.getBucketFilterFunction(bucketList);
|
||||
|
||||
const bucketList = new SearchFilterList<FacetFieldBucket>(responseBuckets, field.pageSize);
|
||||
bucketList.filter = this.getBucketFilterFunction(bucketList);
|
||||
|
||||
if (!this.responseFacets) {
|
||||
this.responseFacets = [];
|
||||
if (!this.responseFacets) {
|
||||
this.responseFacets = [];
|
||||
}
|
||||
this.responseFacets.push(<FacetField> {
|
||||
...field,
|
||||
type: responseField.type || itemType,
|
||||
label: field.label,
|
||||
pageSize: field.pageSize | this.DEFAULT_PAGE_SIZE,
|
||||
currentPageSize: field.pageSize | this.DEFAULT_PAGE_SIZE,
|
||||
buckets: bucketList
|
||||
});
|
||||
}
|
||||
this.responseFacets.push(<FacetField> {
|
||||
...field,
|
||||
type: responseField.type || itemType,
|
||||
label: field.label,
|
||||
pageSize: field.pageSize | this.DEFAULT_PAGE_SIZE,
|
||||
currentPageSize: field.pageSize | this.DEFAULT_PAGE_SIZE,
|
||||
buckets: bucketList
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -269,21 +270,22 @@ export class SearchFilterComponent implements OnInit, OnDestroy {
|
||||
|
||||
this.updateExistingBuckets(responseField, responseBuckets, alreadyExistingField, alreadyExistingBuckets);
|
||||
} else if (responseField && this.showContextFacets) {
|
||||
if (responseBuckets.length > 0) {
|
||||
const bucketList = new SearchFilterList<FacetFieldBucket>(responseBuckets, this.facetQueriesPageSize);
|
||||
bucketList.filter = this.getBucketFilterFunction(bucketList);
|
||||
|
||||
const bucketList = new SearchFilterList<FacetFieldBucket>(responseBuckets, this.facetQueriesPageSize);
|
||||
bucketList.filter = this.getBucketFilterFunction(bucketList);
|
||||
|
||||
if (!this.responseFacets) {
|
||||
this.responseFacets = [];
|
||||
if (!this.responseFacets) {
|
||||
this.responseFacets = [];
|
||||
}
|
||||
this.responseFacets.push(<FacetField> {
|
||||
field: group,
|
||||
type: responseField.type || 'query',
|
||||
label: group,
|
||||
pageSize: this.DEFAULT_PAGE_SIZE,
|
||||
currentPageSize: this.DEFAULT_PAGE_SIZE,
|
||||
buckets: bucketList
|
||||
});
|
||||
}
|
||||
this.responseFacets.push(<FacetField> {
|
||||
field: group,
|
||||
type: responseField.type || 'query',
|
||||
label: group,
|
||||
pageSize: this.DEFAULT_PAGE_SIZE,
|
||||
currentPageSize: this.DEFAULT_PAGE_SIZE,
|
||||
buckets: bucketList
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user