From 826bd32e6084bfd04b56c0090912f1a7b900ac7d Mon Sep 17 00:00:00 2001 From: Maurizio Vitale Date: Tue, 21 Jul 2020 22:46:19 +0100 Subject: [PATCH] [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 --- .../content-node-selector-panel.component.md | 1 + ...tent-node-selector-panel.component.spec.ts | 19 +++++++++++++++++++ .../content-node-selector-panel.component.ts | 10 +++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/content-services/components/content-node-selector-panel.component.md b/docs/content-services/components/content-node-selector-panel.component.md index f97affb21c..5f8edf1800 100644 --- a/docs/content-services/components/content-node-selector-panel.component.md +++ b/docs/content-services/components/content-node-selector-panel.component.md @@ -31,6 +31,7 @@ Opens a [Content Node Selector](content-node-selector.component.md) in its own | Name | Type | Default value | Description | | ---- | ---- | ------------- | ----------- | | breadcrumbTransform | `Function` | | Transformation to be performed on the chosen/folder node before building the breadcrumb UI. Can be useful when custom formatting is needed for the breadcrumb. You can change the path elements from the node that are used to build the breadcrumb using this function. | +| restrictSearchToCurrentFolderId | `boolean` | false | If true will restrict the search to the currentFolderId. | | currentFolderId | `string` | null | [Node](https://github.com/Alfresco/alfresco-js-api/blob/development/src/api/content-rest-api/docs/Node.md) ID of the folder currently listed. | | dropdownHideMyFiles | `boolean` | false | Hide the "My Files" option added to the site list by default. See the [Sites Dropdown component](sites-dropdown.component.md) for more information. | | dropdownSiteList | [`SitePaging`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/SitePaging.md) | null | Custom site for site dropdown. This is the same as the `siteList`. property of the Sites Dropdown component (see its doc page for more information). | diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts index a9cb21a657..417ad1b8dd 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts @@ -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( { 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'); diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.ts index 47ba5a1e06..9f05b3bfd3 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.ts @@ -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;