[AAE-3114] Ability to restrict search to a root folder (#5890)

* Ability to restrict the search to a specific root in case there is no site concept

* Add unit test

* Initialize the siteId with root

* Fix unit test

* Reuse existing property and add boolean

* add new line before extect

* Rename to restrictSearchToCurrentFolderId

* Typo

* Rename property into doc
This commit is contained in:
Maurizio Vitale
2020-07-21 22:46:19 +01:00
committed by GitHub
parent 94c99574f8
commit 826bd32e60
3 changed files with 29 additions and 1 deletions

View File

@@ -634,6 +634,25 @@ describe('ContentNodeSelectorComponent', () => {
expect(component.showingSearchResults).toBeFalsy();
});
it('should restrict the search to the currentFolderId in case is defined', () => {
component.currentFolderId = 'my-root-id';
component.restrictSearchToCurrentFolderId = true;
component.ngOnInit();
component.search('search');
expect(cnSearchSpy).toHaveBeenCalledWith('search', 'my-root-id', 0, 25, [], false);
});
it('should restrict the search to the site and not to the currentFolderId in case is changed', () => {
component.currentFolderId = 'my-root-id';
component.restrictSearchToCurrentFolderId = true;
component.ngOnInit();
component.siteChanged(<SiteEntry> { entry: { guid: 'my-site-id' } });
component.search('search');
expect(cnSearchSpy).toHaveBeenCalledWith('search', 'my-site-id', 0, 25, [], false);
});
it('should clear the search field, nodes and chosenNode when deleting the search input', fakeAsync(() => {
spyOn(component, 'clear').and.callThrough();
typeToSearchBox('a');

View File

@@ -60,6 +60,10 @@ export class ContentNodeSelectorPanelComponent implements OnInit, OnDestroy {
private showSearchField = true;
private showFiles = false;
/** If true will restrict the search to the currentFolderId */
@Input()
restrictSearchToCurrentFolderId: boolean = false;
/** Node ID of the folder currently listed. */
@Input()
currentFolderId: string = null;
@@ -248,7 +252,11 @@ export class ContentNodeSelectorPanelComponent implements OnInit, OnDestroy {
this.target = this.documentList;
this.folderIdToShow = this.currentFolderId;
if (this.currentFolderId) {
this.getStartSite();
if (this.restrictSearchToCurrentFolderId) {
this.siteId = this.currentFolderId;
} else {
this.getStartSite();
}
}
this.breadcrumbTransform = this.breadcrumbTransform ? this.breadcrumbTransform : null;