mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACS-5093] Optimise Categories facet names load (#8498)
* [ACS-5093] removed redundant API call * [ACS-5093] added error handling
This commit is contained in:
committed by
GitHub
parent
a563dc2f54
commit
9b2d433f2b
@@ -22,6 +22,9 @@ Manages categories in Content Services.
|
|||||||
- **getCategory**(categoryId: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`CategoryEntry`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/api/content-rest-api/docs/CategoryEntry.md)`>`<br/>
|
- **getCategory**(categoryId: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`CategoryEntry`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/api/content-rest-api/docs/CategoryEntry.md)`>`<br/>
|
||||||
Gets a specific category by categoryId.
|
Gets a specific category by categoryId.
|
||||||
- _categoryId:_ `string` - The identifier of a category
|
- _categoryId:_ `string` - The identifier of a category
|
||||||
|
- _opts:_ `any` - Optional parameters
|
||||||
|
- _opts.fields_ `string[]` - A list of field names
|
||||||
|
- _opts.include_ `string[]` - Returns additional information about the category. The following optional fields can be requested: count, path
|
||||||
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`CategoryEntry`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/api/content-rest-api/docs/CategoryEntry.md)`>` - CategoryEntry object (defined in JS-API) containing information about the category.
|
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`CategoryEntry`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/api/content-rest-api/docs/CategoryEntry.md)`>` - CategoryEntry object (defined in JS-API) containing information about the category.
|
||||||
- **createSubcategories**(parentCategoryId: `string`, payload: [`CategoryBody[]`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/api/content-rest-api/docs/CategoryBody.md)): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`CategoryPaging`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/api/content-rest-api/docs/CategoryPaging.md) | [`CategoryEntry`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/api/content-rest-api/docs/CategoryEntry.md)`>`<br/>
|
- **createSubcategories**(parentCategoryId: `string`, payload: [`CategoryBody[]`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/api/content-rest-api/docs/CategoryBody.md)): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`CategoryPaging`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/api/content-rest-api/docs/CategoryPaging.md) | [`CategoryEntry`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/api/content-rest-api/docs/CategoryEntry.md)`>`<br/>
|
||||||
Creates subcategories under category with provided categoryId.
|
Creates subcategories under category with provided categoryId.
|
||||||
|
@@ -67,8 +67,8 @@ describe('CategoryService', () => {
|
|||||||
|
|
||||||
it('should fetch the category with the provided categoryId', fakeAsync(() => {
|
it('should fetch the category with the provided categoryId', fakeAsync(() => {
|
||||||
const getSpy = spyOn(categoryService.categoriesApi, 'getCategory').and.returnValue(Promise.resolve(fakeCategoryEntry));
|
const getSpy = spyOn(categoryService.categoriesApi, 'getCategory').and.returnValue(Promise.resolve(fakeCategoryEntry));
|
||||||
categoryService.getCategory(fakeParentCategoryId).subscribe(() => {
|
categoryService.getCategory(fakeParentCategoryId, {include: ['path']}).subscribe(() => {
|
||||||
expect(getSpy).toHaveBeenCalledOnceWith(fakeParentCategoryId);
|
expect(getSpy).toHaveBeenCalledOnceWith(fakeParentCategoryId, {include: ['path']});
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@@ -62,10 +62,15 @@ export class CategoryService {
|
|||||||
* Get a category by ID
|
* Get a category by ID
|
||||||
*
|
*
|
||||||
* @param categoryId The identifier of a category.
|
* @param categoryId The identifier of a category.
|
||||||
|
* @param opts Optional parameters.
|
||||||
|
* @param opts.fields A list of field names.
|
||||||
|
* @param opts.include Returns additional information about the category. The following optional fields can be requested:
|
||||||
|
* count
|
||||||
|
* path
|
||||||
* @return Observable<CategoryEntry>
|
* @return Observable<CategoryEntry>
|
||||||
*/
|
*/
|
||||||
getCategory(categoryId: string): Observable<CategoryEntry> {
|
getCategory(categoryId: string, opts?: any): Observable<CategoryEntry> {
|
||||||
return from(this.categoriesApi.getCategory(categoryId));
|
return from(this.categoriesApi.getCategory(categoryId, opts));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -34,8 +34,7 @@ describe('SearchFacetFiltersService', () => {
|
|||||||
providers: [{
|
providers: [{
|
||||||
provide: CategoryService,
|
provide: CategoryService,
|
||||||
useValue: {
|
useValue: {
|
||||||
getCategory: () => EMPTY,
|
getCategory: () => EMPTY
|
||||||
searchCategories: () => EMPTY
|
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
@@ -472,22 +471,9 @@ describe('SearchFacetFiltersService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should load category names for cm:categories facet', () => {
|
it('should load category names for cm:categories facet', () => {
|
||||||
const entry = {id: 'test-id-test', name: 'name'};
|
const entry = {id: 'test-id-test', name: 'name', path: '/categories/General/Test Category/Subcategory'};
|
||||||
searchFacetFiltersService.responseFacets = null;
|
searchFacetFiltersService.responseFacets = null;
|
||||||
spyOn(categoryService, 'getCategory').and.returnValue(of({entry}));
|
spyOn(categoryService, 'getCategory').and.returnValue(of({entry}));
|
||||||
spyOn(categoryService, 'searchCategories').and.returnValue(of({
|
|
||||||
list: {
|
|
||||||
entries: [{
|
|
||||||
entry: {
|
|
||||||
...entry,
|
|
||||||
nodeType: 'node-type',
|
|
||||||
path: { name: '/categories/General/Test Category/Subcategory'},
|
|
||||||
isFolder: false,
|
|
||||||
isFile: false
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
queryBuilder.config = {
|
queryBuilder.config = {
|
||||||
categories: [],
|
categories: [],
|
||||||
@@ -521,8 +507,7 @@ describe('SearchFacetFiltersService', () => {
|
|||||||
|
|
||||||
searchFacetFiltersService.onDataLoaded(data);
|
searchFacetFiltersService.onDataLoaded(data);
|
||||||
|
|
||||||
expect(categoryService.getCategory).toHaveBeenCalledWith(entry.id);
|
expect(categoryService.getCategory).toHaveBeenCalledWith(entry.id, { include: [ 'path' ]});
|
||||||
expect(categoryService.searchCategories).toHaveBeenCalledWith(entry.name);
|
|
||||||
expect(searchFacetFiltersService.responseFacets[1].buckets.items[0].display).toBe(`Test Category/Subcategory/${entry.name}`);
|
expect(searchFacetFiltersService.responseFacets[1].buckets.items[0].display).toBe(`Test Category/Subcategory/${entry.name}`);
|
||||||
expect(searchFacetFiltersService.responseFacets[1].buckets.length).toEqual(1);
|
expect(searchFacetFiltersService.responseFacets[1].buckets.length).toEqual(1);
|
||||||
expect(searchFacetFiltersService.responseFacets.length).toEqual(2);
|
expect(searchFacetFiltersService.responseFacets.length).toEqual(2);
|
||||||
|
@@ -22,7 +22,7 @@ import { SEARCH_QUERY_SERVICE_TOKEN } from '../search-query-service.token';
|
|||||||
import { SearchQueryBuilderService } from './search-query-builder.service';
|
import { SearchQueryBuilderService } from './search-query-builder.service';
|
||||||
import { TranslationService } from '@alfresco/adf-core';
|
import { TranslationService } from '@alfresco/adf-core';
|
||||||
import { SearchService } from './search.service';
|
import { SearchService } from './search.service';
|
||||||
import { catchError, concatMap, takeUntil } from 'rxjs/operators';
|
import { catchError, takeUntil } from 'rxjs/operators';
|
||||||
import { GenericBucket, GenericFacetResponse, ResultSetContext, ResultSetPaging } from '@alfresco/js-api';
|
import { GenericBucket, GenericFacetResponse, ResultSetContext, ResultSetPaging } from '@alfresco/js-api';
|
||||||
import { SearchFilterList } from '../models/search-filter-list.model';
|
import { SearchFilterList } from '../models/search-filter-list.model';
|
||||||
import { FacetFieldBucket } from '../models/facet-field-bucket.interface';
|
import { FacetFieldBucket } from '../models/facet-field-bucket.interface';
|
||||||
@@ -345,19 +345,14 @@ export class SearchFacetFiltersService implements OnDestroy {
|
|||||||
private loadCategoryNames(bucketList: FacetFieldBucket[]) {
|
private loadCategoryNames(bucketList: FacetFieldBucket[]) {
|
||||||
bucketList.forEach((item) => {
|
bucketList.forEach((item) => {
|
||||||
const categoryId = item.label.split('/').pop();
|
const categoryId = item.label.split('/').pop();
|
||||||
this.categoryService.getCategory(categoryId)
|
this.categoryService.getCategory(categoryId, {include: ['path']})
|
||||||
.pipe(
|
.pipe(catchError(error => throwError(error)))
|
||||||
concatMap((categoryEntry) => this.categoryService.searchCategories(categoryEntry.entry.name)),
|
|
||||||
catchError(error => throwError(error))
|
|
||||||
)
|
|
||||||
.subscribe(
|
.subscribe(
|
||||||
result => {
|
category => {
|
||||||
const nextAfterGeneralPathPartIndex = 3;
|
const nextAfterGeneralPathPartIndex = 3;
|
||||||
const pathSeparator = '/';
|
const pathSeparator = '/';
|
||||||
const currentCat = result.list.entries.filter(entry => entry.entry.id === categoryId)[0];
|
const path = category.entry.path.split(pathSeparator).slice(nextAfterGeneralPathPartIndex).join('/');
|
||||||
const path = currentCat.entry.path.name.split(pathSeparator).slice(nextAfterGeneralPathPartIndex).join('/');
|
item.display = path ? `${path}/${category.entry.name}` : category.entry.name;
|
||||||
|
|
||||||
item.display = path ? `${path}/${currentCat.entry.name}` : currentCat.entry.name;
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user