From c7237486dffe45730454feca259dd1308657dc04 Mon Sep 17 00:00:00 2001 From: Maurizio Vitale Date: Wed, 29 Jul 2020 12:46:37 +0100 Subject: [PATCH] [AAE-3113] Node selector - Be able to restrict the breadcrums to a specific root (#5912) * Be able to restrict the breadcrums to a specific root * Add unit test for breadcrumbs restriction * Fix refresh --- .../content-node-selector-panel.component.md | 2 +- .../content-node-selector-panel.component.html | 1 + ...ntent-node-selector-panel.component.spec.ts | 18 ++++++++++++++++-- .../content-node-selector-panel.component.ts | 8 +++++--- ...t-node-selector.component-data.interface.ts | 1 + .../content-node-selector.component.html | 1 + .../content-cloud-node-selector.service.ts | 1 + 7 files changed, 26 insertions(+), 6 deletions(-) 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 17c9422fe7..2085b971e0 100644 --- a/docs/content-services/components/content-node-selector-panel.component.md +++ b/docs/content-services/components/content-node-selector-panel.component.md @@ -37,7 +37,7 @@ Opens a [Content Node Selector](content-node-selector.component.md) in its own | imageResolver | [`ImageResolver`](../../../lib/content-services/src/lib/document-list/data/image-resolver.model.ts) | null | Custom image resolver function. See the [Image Resolver Model](image-resolver.model.md) page for more information. | | isSelectionValid | [`ValidationFunction`](../../../lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.ts) | defaultValidation | Function used to decide if the selected node has permission to be selected. Default value is a function that always returns true. | | pageSize | `number` | | Number of items shown per page in the list. | -| restrictSearchToCurrentFolderId | `boolean` | false | If true will restrict the search to the currentFolderId | +| restrictRootToCurrentFolderId | `boolean` | false | If true will restrict the search and breadcrumbs to the currentFolderId | | where | `string` | | Custom _where_ filter function. See the [Document List component](../../content-services/components/document-list.component.md) for more information. | | excludeSiteContent | `string[]` | | Custom list of site content componentIds. Used to filter out the corresponding items from the displayed nodes | | rowFilter | [`RowFilter`](../../../lib/content-services/src/lib/document-list/data/row-filter.model.ts) | | Custom row filter function. See the [Row Filter Model](row-filter.model.md) page for more information. | diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.html b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.html index 3e90f3693c..60de757949 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.html +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.html @@ -42,6 +42,7 @@ class="adf-content-node-selector-content-breadcrumb" (navigate)="clearSearch()" [target]="documentList" + [rootId]="breadcrumbRootId" [transform]="breadcrumbTransform" [folderNode]="breadcrumbFolderNode" [root]="breadcrumbFolderTitle" 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 868441e18f..aebd12f6a8 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 @@ -638,7 +638,7 @@ describe('ContentNodeSelectorComponent', () => { it('should restrict the search to the currentFolderId in case is defined', () => { component.currentFolderId = 'my-root-id'; - component.restrictSearchToCurrentFolderId = true; + component.restrictRootToCurrentFolderId = true; component.ngOnInit(); component.search('search'); @@ -647,7 +647,7 @@ describe('ContentNodeSelectorComponent', () => { 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.restrictRootToCurrentFolderId = true; component.ngOnInit(); component.siteChanged( { entry: { guid: 'my-site-id' } }); component.search('search'); @@ -655,6 +655,20 @@ describe('ContentNodeSelectorComponent', () => { expect(cnSearchSpy).toHaveBeenCalledWith('search', 'my-site-id', 0, 25, [], false); }); + it('should restrict the breadcrumb to the currentFolderId in case restrictedRoot is true', () => { + component.currentFolderId = 'my-root-id'; + component.restrictRootToCurrentFolderId = true; + component.ngOnInit(); + expect(component.breadcrumbRootId).toEqual('my-root-id'); + }); + + it('should NOT restrict the breadcrumb to the currentFolderId in case restrictedRoot is false', () => { + component.currentFolderId = 'my-root-id'; + component.restrictRootToCurrentFolderId = false; + component.ngOnInit(); + expect(component.breadcrumbRootId).toBeUndefined(); + }); + 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 05e36068da..0c43102a42 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,9 +60,9 @@ export class ContentNodeSelectorPanelComponent implements OnInit, OnDestroy { private showSearchField = true; private showFiles = false; - /** If true will restrict the search to the currentFolderId */ + /** If true will restrict the search and breadcrumbs to the currentFolderId */ @Input() - restrictSearchToCurrentFolderId: boolean = false; + restrictRootToCurrentFolderId: boolean = false; /** Node ID of the folder currently listed. */ @Input() @@ -198,6 +198,7 @@ export class ContentNodeSelectorPanelComponent implements OnInit, OnDestroy { nodePaging: NodePaging | null = null; siteId: null | string; + breadcrumbRootId: null | string; searchTerm: string = ''; showingSearchResults: boolean = false; loadingSearchResults: boolean = false; @@ -252,7 +253,8 @@ export class ContentNodeSelectorPanelComponent implements OnInit, OnDestroy { this.target = this.documentList; this.folderIdToShow = this.currentFolderId; if (this.currentFolderId) { - if (this.restrictSearchToCurrentFolderId) { + if (this.restrictRootToCurrentFolderId) { + this.breadcrumbRootId = this.currentFolderId; this.siteId = this.currentFolderId; } else { this.getStartSite(); diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector.component-data.interface.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector.component-data.interface.ts index b59c7c6569..69e283e1db 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector.component-data.interface.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector.component-data.interface.ts @@ -23,6 +23,7 @@ export interface ContentNodeSelectorComponentData { actionName?: string; currentFolderId: string; dropdownHideMyFiles?: boolean; + restrictRootToCurrentFolderId?: boolean; dropdownSiteList?: SitePaging; rowFilter?: any; where?: string; diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.html b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.html index 302371d796..b3f76c70a4 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.html +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.html @@ -7,6 +7,7 @@ entry.isFile,