diff --git a/src/app/components/common/trashcan-name-column/trashcan-name-column.component.spec.ts b/src/app/components/common/trashcan-name-column/trashcan-name-column.component.spec.ts
index 180579bbe..cfc7129c5 100644
--- a/src/app/components/common/trashcan-name-column/trashcan-name-column.component.spec.ts
+++ b/src/app/components/common/trashcan-name-column/trashcan-name-column.component.spec.ts
@@ -26,7 +26,89 @@
import { TrashcanNameColumnComponent } from './trashcan-name-column.component';
describe('TrashcanNameColumnComponent', () => {
- it('should be defined', () => {
- expect(TrashcanNameColumnComponent).toBeDefined();
+ let component;
+
+ beforeEach(() => {
+ component = new TrashcanNameColumnComponent();
+ });
+
+ it('should set displayText for content files', () => {
+ const context = {
+ data: { rows: [] },
+ row: {
+ node: {
+ entry: {
+ name: 'contentName',
+ nodeType: 'content'
+ }
+ }
+ }
+ };
+
+ component.context = context;
+ component.ngOnInit();
+
+ expect(component.displayText).toBe('contentName');
+ });
+
+ it('should set displayText for library', () => {
+ const context = {
+ data: {
+ rows: []
+ },
+ row: {
+ node: {
+ entry: {
+ nodeType: 'st:site',
+ properties: {
+ 'cm:title': 'libraryTitle'
+ }
+ }
+ }
+ }
+ };
+
+ component.context = context;
+ component.ngOnInit();
+
+ expect(component.displayText).toBe('libraryTitle');
+ });
+
+ it('should set custom displayText for libraries with same name', () => {
+ const context = {
+ data: {
+ rows: [
+ {
+ node: {
+ entry: {
+ id: 'id1',
+ name: 'name1',
+ nodeType: 'st:site',
+ properties: {
+ 'cm:title': 'bogus'
+ }
+ }
+ }
+ }
+ ]
+ },
+ row: {
+ node: {
+ entry: {
+ id: 'id2',
+ name: 'name1',
+ nodeType: 'st:site',
+ properties: {
+ 'cm:title': 'bogus'
+ }
+ }
+ }
+ }
+ };
+
+ component.context = context;
+ component.ngOnInit();
+
+ expect(component.displayText).toBe('bogus (name1)');
});
});
diff --git a/src/app/components/common/trashcan-name-column/trashcan-name-column.component.ts b/src/app/components/common/trashcan-name-column/trashcan-name-column.component.ts
index f3d88295a..627c246fc 100644
--- a/src/app/components/common/trashcan-name-column/trashcan-name-column.component.ts
+++ b/src/app/components/common/trashcan-name-column/trashcan-name-column.component.ts
@@ -30,12 +30,18 @@ import {
OnInit,
Input
} from '@angular/core';
+import { ShareDataRow } from '@alfresco/adf-content-services';
import { MinimalNodeEntity } from 'alfresco-js-api';
@Component({
selector: 'app-trashcan-name-column',
template: `
- {{ displayText }}
+
+ {{ displayText }}
+
+
+ {{ displayText }}
+
`,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
@@ -45,13 +51,45 @@ export class TrashcanNameColumnComponent implements OnInit {
@Input()
context: any;
+ isLibrary = false;
displayText: string;
+ displayTooltip: string;
node: MinimalNodeEntity;
ngOnInit() {
this.node = this.context.row.node;
+ const rows: Array = this.context.data.rows || [];
+
if (this.node && this.node.entry) {
- this.displayText = this.node.entry.name || this.node.entry.id;
+ this.isLibrary = this.node.entry.nodeType === 'st:site';
+
+ if (this.isLibrary) {
+ const { properties } = this.node.entry;
+
+ this.displayText = this.makeLibraryTitle(this.node.entry, rows);
+ this.displayTooltip =
+ properties['cm:description'] || properties['cm:title'];
+ } else {
+ this.displayText = this.node.entry.name || this.node.entry.id;
+ }
}
}
+
+ makeLibraryTitle(library: any, rows: Array): string {
+ const entries = rows.map((r: ShareDataRow) => r.node.entry);
+ const { id } = library;
+ const title = library.properties['cm:title'];
+
+ let isDuplicate = false;
+
+ if (entries) {
+ isDuplicate = entries.some((entry: any) => {
+ return entry.id !== id && entry.properties['cm:title'] === title;
+ });
+ }
+
+ return isDuplicate
+ ? `${library.properties['cm:title']} (${library.name})`
+ : `${library.properties['cm:title']}`;
+ }
}