mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[ACS-9166]: introduces variable for search save mode threshold
This commit is contained in:
@@ -51,7 +51,7 @@ describe('SavedSearchesBaseService', () => {
|
|||||||
service.init();
|
service.init();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit updated searches with correct order if total of saved searches is less than 5', (done) => {
|
it('should emit updated searches with correct order if total of saved searches is less than limit (5)', (done) => {
|
||||||
service.mockFetch(SAVED_SEARCHES_CONTENT);
|
service.mockFetch(SAVED_SEARCHES_CONTENT);
|
||||||
const newSearch = { name: 'new-search' } as SavedSearch;
|
const newSearch = { name: 'new-search' } as SavedSearch;
|
||||||
service.saveSearch(newSearch).subscribe(() => {
|
service.saveSearch(newSearch).subscribe(() => {
|
||||||
@@ -68,7 +68,7 @@ describe('SavedSearchesBaseService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit updated searches with correct order if total of saved searches is more than 5', (done) => {
|
it('should emit updated searches with correct order if total of saved searches is more than limit (5)', (done) => {
|
||||||
const moreSavedSearches = [...SAVED_SEARCHES_CONTENT, ...SAVED_SEARCHES_CONTENT, ...SAVED_SEARCHES_CONTENT];
|
const moreSavedSearches = [...SAVED_SEARCHES_CONTENT, ...SAVED_SEARCHES_CONTENT, ...SAVED_SEARCHES_CONTENT];
|
||||||
service.mockFetch(moreSavedSearches);
|
service.mockFetch(moreSavedSearches);
|
||||||
const newSearch = { name: 'new-search' } as SavedSearch;
|
const newSearch = { name: 'new-search' } as SavedSearch;
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ import { AlfrescoApiService } from '../../services';
|
|||||||
export abstract class SavedSearchesBaseService implements SavedSearchStrategy {
|
export abstract class SavedSearchesBaseService implements SavedSearchStrategy {
|
||||||
private _nodesApi: NodesApi;
|
private _nodesApi: NodesApi;
|
||||||
|
|
||||||
|
private static readonly SAVE_MODE_THRESHOLD = 5;
|
||||||
|
|
||||||
protected readonly _savedSearches$ = new ReplaySubject<SavedSearch[]>(1);
|
protected readonly _savedSearches$ = new ReplaySubject<SavedSearch[]>(1);
|
||||||
readonly savedSearches$: Observable<SavedSearch[]> = this._savedSearches$.asObservable();
|
readonly savedSearches$: Observable<SavedSearch[]> = this._savedSearches$.asObservable();
|
||||||
|
|
||||||
@@ -35,7 +37,7 @@ export abstract class SavedSearchesBaseService implements SavedSearchStrategy {
|
|||||||
return this._nodesApi;
|
return this._nodesApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(
|
protected constructor(
|
||||||
protected readonly apiService: AlfrescoApiService,
|
protected readonly apiService: AlfrescoApiService,
|
||||||
protected readonly authService: AuthenticationService
|
protected readonly authService: AuthenticationService
|
||||||
) {}
|
) {}
|
||||||
@@ -52,17 +54,18 @@ export abstract class SavedSearchesBaseService implements SavedSearchStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
saveSearch(newSaveSearch: Pick<SavedSearch, 'name' | 'description' | 'encodedUrl'>): Observable<NodeEntry> {
|
saveSearch(newSaveSearch: Pick<SavedSearch, 'name' | 'description' | 'encodedUrl'>): Observable<NodeEntry> {
|
||||||
|
const limit = SavedSearchesBaseService.SAVE_MODE_THRESHOLD;
|
||||||
return this.fetchAllSavedSearches().pipe(
|
return this.fetchAllSavedSearches().pipe(
|
||||||
take(1),
|
take(1),
|
||||||
switchMap((savedSearches) => {
|
switchMap((savedSearches) => {
|
||||||
let updatedSavedSearches: SavedSearch[] = [];
|
let updatedSavedSearches: SavedSearch[] = [];
|
||||||
|
|
||||||
if (savedSearches.length < 5) {
|
if (savedSearches.length < limit) {
|
||||||
updatedSavedSearches = [{ ...newSaveSearch, order: 0 }, ...savedSearches];
|
updatedSavedSearches = [{ ...newSaveSearch, order: 0 }, ...savedSearches];
|
||||||
} else {
|
} else {
|
||||||
const firstFiveSearches = savedSearches.slice(0, 5);
|
const upToLimitSearches = savedSearches.slice(0, limit);
|
||||||
const restOfSearches = savedSearches.slice(5);
|
const restSearches = savedSearches.slice(limit);
|
||||||
updatedSavedSearches = [...firstFiveSearches, { ...newSaveSearch, order: 5 }, ...restOfSearches];
|
updatedSavedSearches = [...upToLimitSearches, { ...newSaveSearch, order: limit }, ...restSearches];
|
||||||
}
|
}
|
||||||
|
|
||||||
updatedSavedSearches = updatedSavedSearches.map((search, index) => ({ ...search, order: index }));
|
updatedSavedSearches = updatedSavedSearches.map((search, index) => ({ ...search, order: index }));
|
||||||
|
|||||||
Reference in New Issue
Block a user