mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-4193] search error notifications and empty results (#4567)
* search error notifications and empty results * update docs
This commit is contained in:
committed by
Eugenio Romano
parent
2c9fdf0d4d
commit
f89bf507f5
@@ -11,6 +11,14 @@ Stores information from all the custom search and faceted search widgets, compil
|
||||
|
||||
## 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
|
||||
|
||||
- **addFilterQuery**(query: `string`)<br/>
|
||||
|
@@ -613,4 +613,38 @@ describe('SearchQueryBuilder', () => {
|
||||
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();
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -42,8 +42,9 @@ export class SearchQueryBuilderService {
|
||||
|
||||
private _userQuery = '';
|
||||
|
||||
updated: Subject<QueryBody> = new Subject();
|
||||
executed: Subject<ResultSetPaging> = new Subject();
|
||||
updated = new Subject<QueryBody>();
|
||||
executed = new Subject<ResultSetPaging>();
|
||||
error = new Subject();
|
||||
|
||||
categories: Array<SearchCategory> = [];
|
||||
queryFragments: { [id: string]: string } = {};
|
||||
@@ -196,11 +197,24 @@ export class SearchQueryBuilderService {
|
||||
* @returns Nothing
|
||||
*/
|
||||
async execute() {
|
||||
try {
|
||||
const query = this.buildQuery();
|
||||
if (query) {
|
||||
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: []
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user