[ADF-4193] search error notifications and empty results (#4567)

* search error notifications and empty results

* update docs
This commit is contained in:
Denys Vuika
2019-04-08 14:25:47 +01:00
committed by Eugenio Romano
parent 2c9fdf0d4d
commit f89bf507f5
3 changed files with 62 additions and 6 deletions

View File

@@ -11,6 +11,14 @@ Stores information from all the custom search and faceted search widgets, compil
## Class members ## Class members
### Events
| Name | Type | Details |
| --- | --- | --- |
| updated | QueryBody | Raised when query gets updated but before query is executed |
| executed | ResultSetPaging | Raised when query gets executed and results are available |
| error | any | Raised when search api emits internal error |
### Methods ### Methods
- **addFilterQuery**(query: `string`)<br/> - **addFilterQuery**(query: `string`)<br/>

View File

@@ -613,4 +613,38 @@ describe('SearchQueryBuilder', () => {
expect(compiled.highlight.mergeContiguous).toBe(true); expect(compiled.highlight.mergeContiguous).toBe(true);
}); });
it('should emit error event', (done) => {
const config: SearchConfiguration = {
categories: [
<any> { id: 'cat1', enabled: true }
]
};
const builder = new SearchQueryBuilderService(buildConfig(config), null);
spyOn(builder, 'buildQuery').and.throwError('some error');
builder.error.subscribe(() => {
done();
});
builder.execute();
});
it('should emit empty results on error', (done) => {
const config: SearchConfiguration = {
categories: [
<any> { id: 'cat1', enabled: true }
]
};
const builder = new SearchQueryBuilderService(buildConfig(config), null);
spyOn(builder, 'buildQuery').and.throwError('some error');
builder.executed.subscribe((data) => {
expect(data.list.entries).toEqual([]);
expect(data.list.pagination.totalItems).toBe(0);
done();
});
builder.execute();
});
}); });

View File

@@ -42,8 +42,9 @@ export class SearchQueryBuilderService {
private _userQuery = ''; private _userQuery = '';
updated: Subject<QueryBody> = new Subject(); updated = new Subject<QueryBody>();
executed: Subject<ResultSetPaging> = new Subject(); executed = new Subject<ResultSetPaging>();
error = new Subject();
categories: Array<SearchCategory> = []; categories: Array<SearchCategory> = [];
queryFragments: { [id: string]: string } = {}; queryFragments: { [id: string]: string } = {};
@@ -196,10 +197,23 @@ export class SearchQueryBuilderService {
* @returns Nothing * @returns Nothing
*/ */
async execute() { async execute() {
const query = this.buildQuery(); try {
if (query) { const query = this.buildQuery();
const resultSetPaging: ResultSetPaging = await this.alfrescoApiService.searchApi.search(query); if (query) {
this.executed.next(resultSetPaging); const resultSetPaging: ResultSetPaging = await this.alfrescoApiService.searchApi.search(query);
this.executed.next(resultSetPaging);
}
} catch (error) {
this.error.next(error);
this.executed.next({
list: {
pagination: {
totalItems: 0
},
entries: []
}
});
} }
} }