mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2361] added breadcrumb transform function to the breadcrumb comp… (#3050)
* [ADF-2361] added breadcrumb transform function to the breadcrumb component * [ADF-2361] added PR review changes
This commit is contained in:
@@ -25,6 +25,7 @@ Indicates the current position within a navigation hierarchy.
|
|||||||
| root | `string` | `null` | (optional) Name of the root element of the breadcrumb. You can use this property to rename "Company Home" to "Personal Files" for example. You can use an i18n resource key for the property value. |
|
| root | `string` | `null` | (optional) Name of the root element of the breadcrumb. You can use this property to rename "Company Home" to "Personal Files" for example. You can use an i18n resource key for the property value. |
|
||||||
| rootId | `string` | `null` | (optional) The id of the root element. You can use this property to set a custom element the breadcrumb should start with. |
|
| rootId | `string` | `null` | (optional) The id of the root element. You can use this property to set a custom element the breadcrumb should start with. |
|
||||||
| target | `DocumentListComponent` | | (optional) Document List component to operate with. The list will update when the breadcrumb is clicked. |
|
| target | `DocumentListComponent` | | (optional) Document List component to operate with. The list will update when the breadcrumb is clicked. |
|
||||||
|
| transform | (node) => any | null | Action to be performed to the chosen/folder node before building the breadcrumb UI. Can be useful when custom formatting is needed to the breadcrumb, so changing the node's path elements that help build the breadcrumb can be done through this function. |
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
|
@@ -205,4 +205,28 @@ describe('Breadcrumb', () => {
|
|||||||
expect(route[0].id).toBe('custom-id');
|
expect(route[0].id).toBe('custom-id');
|
||||||
expect(route[0].name).toBe('custom-name');
|
expect(route[0].name).toBe('custom-name');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should apply the transformation function when there is one', () => {
|
||||||
|
const node: any = {
|
||||||
|
id: null,
|
||||||
|
name: null,
|
||||||
|
path: {
|
||||||
|
elements: [
|
||||||
|
{ id: 'element-1-id', name: 'element-1-name' },
|
||||||
|
{ id: 'element-2-id', name: 'element-2-name' },
|
||||||
|
{ id: 'element-3-id', name: 'element-3-name' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
component.transform = ((transformNode) => {
|
||||||
|
transformNode.id = 'test-id';
|
||||||
|
transformNode.name = 'test-name';
|
||||||
|
return transformNode;
|
||||||
|
});
|
||||||
|
let change = new SimpleChange(null, node, true);
|
||||||
|
component.ngOnChanges({'folderNode': change});
|
||||||
|
expect(component.route.length).toBe(4);
|
||||||
|
expect(component.route[3].id).toBe('test-id');
|
||||||
|
expect(component.route[3].name).toBe('test-name');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -15,7 +15,14 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges, ViewEncapsulation } from '@angular/core';
|
import { Component,
|
||||||
|
EventEmitter,
|
||||||
|
Input,
|
||||||
|
OnChanges,
|
||||||
|
Output,
|
||||||
|
SimpleChanges,
|
||||||
|
ViewEncapsulation,
|
||||||
|
OnInit } from '@angular/core';
|
||||||
import { MinimalNodeEntryEntity, PathElementEntity } from 'alfresco-js-api';
|
import { MinimalNodeEntryEntity, PathElementEntity } from 'alfresco-js-api';
|
||||||
import { DocumentListComponent } from '../document-list';
|
import { DocumentListComponent } from '../document-list';
|
||||||
|
|
||||||
@@ -28,7 +35,7 @@ import { DocumentListComponent } from '../document-list';
|
|||||||
'class': 'adf-breadcrumb'
|
'class': 'adf-breadcrumb'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
export class BreadcrumbComponent implements OnChanges {
|
export class BreadcrumbComponent implements OnInit, OnChanges {
|
||||||
|
|
||||||
/** Active node, builds UI based on folderNode.path.elements collection. */
|
/** Active node, builds UI based on folderNode.path.elements collection. */
|
||||||
@Input()
|
@Input()
|
||||||
@@ -53,6 +60,9 @@ export class BreadcrumbComponent implements OnChanges {
|
|||||||
@Input()
|
@Input()
|
||||||
target: DocumentListComponent;
|
target: DocumentListComponent;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
transform: (node) => any;
|
||||||
|
|
||||||
route: PathElementEntity[] = [];
|
route: PathElementEntity[] = [];
|
||||||
|
|
||||||
get hasRoot(): boolean {
|
get hasRoot(): boolean {
|
||||||
@@ -63,9 +73,14 @@ export class BreadcrumbComponent implements OnChanges {
|
|||||||
@Output()
|
@Output()
|
||||||
navigate: EventEmitter<PathElementEntity> = new EventEmitter<PathElementEntity>();
|
navigate: EventEmitter<PathElementEntity> = new EventEmitter<PathElementEntity>();
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.transform = this.transform ? this.transform : null ;
|
||||||
|
}
|
||||||
|
|
||||||
ngOnChanges(changes: SimpleChanges): void {
|
ngOnChanges(changes: SimpleChanges): void {
|
||||||
if (changes.folderNode) {
|
if (changes.folderNode) {
|
||||||
const node: MinimalNodeEntryEntity = changes.folderNode.currentValue;
|
let node: MinimalNodeEntryEntity = null;
|
||||||
|
node = this.transform ? this.transform(changes.folderNode.currentValue) : changes.folderNode.currentValue;
|
||||||
this.route = this.parseRoute(node);
|
this.route = this.parseRoute(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -40,6 +40,7 @@
|
|||||||
class="adf-content-node-selector-content-breadcrumb"
|
class="adf-content-node-selector-content-breadcrumb"
|
||||||
(navigate)="clear()"
|
(navigate)="clear()"
|
||||||
[target]="documentList"
|
[target]="documentList"
|
||||||
|
[transform]="breadcrumbTransform"
|
||||||
[folderNode]="breadcrumbFolderNode"
|
[folderNode]="breadcrumbFolderNode"
|
||||||
data-automation-id="content-node-selector-content-breadcrumb">
|
data-automation-id="content-node-selector-content-breadcrumb">
|
||||||
</adf-dropdown-breadcrumb>
|
</adf-dropdown-breadcrumb>
|
||||||
|
@@ -261,7 +261,7 @@ describe('ContentNodeSelectorComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should make changes to breadcrumb\'s folderNode if breadcrumbTransform is defined', (done) => {
|
it('should make changes to breadcrumb\'s folderNode if breadcrumbTransform is defined', (done) => {
|
||||||
const transformedFolderNode = <MinimalNodeEntryEntity> { path: { elements: [{id: 'testId', name: 'testName'}] } };
|
const transformedFolderNode = <MinimalNodeEntryEntity> { id: 'trans-node', name: 'trans-node-name', path: { elements: [{id: 'testId', name: 'testName'}] } };
|
||||||
component.breadcrumbTransform = (() => {
|
component.breadcrumbTransform = (() => {
|
||||||
return transformedFolderNode;
|
return transformedFolderNode;
|
||||||
});
|
});
|
||||||
@@ -272,7 +272,8 @@ describe('ContentNodeSelectorComponent', () => {
|
|||||||
expect(component.breadcrumbTransform).not.toBeNull();
|
expect(component.breadcrumbTransform).not.toBeNull();
|
||||||
|
|
||||||
const breadcrumb = fixture.debugElement.query(By.directive(DropdownBreadcrumbComponent));
|
const breadcrumb = fixture.debugElement.query(By.directive(DropdownBreadcrumbComponent));
|
||||||
expect(breadcrumb.componentInstance.folderNode).toBe(transformedFolderNode);
|
expect(breadcrumb.componentInstance.route[0].name).toBe('testName');
|
||||||
|
expect(breadcrumb.componentInstance.route[0].id).toBe('testId');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -174,7 +174,7 @@ export class ContentNodeSelectorPanelComponent implements OnInit {
|
|||||||
folderNode = this.documentList.folderNode;
|
folderNode = this.documentList.folderNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.breadcrumbTransform ? this.breadcrumbTransform(folderNode) : folderNode;
|
return folderNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user