diff --git a/e2e/suites/actions/context-menu-single-selection.test.ts b/e2e/suites/actions/context-menu-single-selection.test.ts index 19b1a53c0..94710c739 100755 --- a/e2e/suites/actions/context-menu-single-selection.test.ts +++ b/e2e/suites/actions/context-menu-single-selection.test.ts @@ -126,10 +126,10 @@ describe('Context menu actions - single selection : ', () => { expect(await dataTable.hasContextMenu()).toBe(false, 'Context menu is displayed'); }); - it('Context menu does not appear for a library - [C286276]', async () => { + it('Context menu appears for a library - [C286276]', async () => { await page.clickFileLibrariesAndWait(); await dataTable.rightClickOnItem(siteName); - expect(await dataTable.hasContextMenu()).toBe(false, 'Context menu is displayed for a site'); + expect(await dataTable.hasContextMenu()).toBe(true, 'Context menu is displayed for a site'); }); }); diff --git a/src/app/components/favorite-libraries/favorite-libraries.component.html b/src/app/components/favorite-libraries/favorite-libraries.component.html index a84496845..98ccd390d 100644 --- a/src/app/components/favorite-libraries/favorite-libraries.component.html +++ b/src/app/components/favorite-libraries/favorite-libraries.component.html @@ -15,9 +15,17 @@
- + diff --git a/src/app/components/libraries/libraries.component.html b/src/app/components/libraries/libraries.component.html index 69db4a84c..68b397527 100644 --- a/src/app/components/libraries/libraries.component.html +++ b/src/app/components/libraries/libraries.component.html @@ -15,6 +15,7 @@
{ let fixture; let component; let contentManagementService; const selection = { library: { entry: { id: 'libraryId' } } }; + const mockRouter = { + url: '' + }; - setupTestBed({ - imports: [CoreModule, AppTestingModule], - declarations: [ToggleFavoriteLibraryComponent, LibraryFavoriteDirective], - providers: [ - { - provide: AlfrescoApiService, - useClass: AlfrescoApiServiceMock - }, - { - provide: Store, - useValue: { - dispatch: () => {}, - select: () => of(selection) - } - }, - ContentManagementService - ], - schemas: [NO_ERRORS_SCHEMA] + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [CoreModule, AppTestingModule], + declarations: [ToggleFavoriteLibraryComponent, LibraryFavoriteDirective], + providers: [ + { + provide: Router, + useValue: mockRouter + }, + { + provide: AlfrescoApiService, + useClass: AlfrescoApiServiceMock + }, + { + provide: Store, + useValue: { + dispatch: () => {}, + select: () => of(selection) + } + }, + ContentManagementService + ], + schemas: [NO_ERRORS_SCHEMA] + }); }); beforeEach(() => { @@ -76,7 +85,17 @@ describe('ToggleFavoriteLibraryComponent', () => { it('should get library selection from Store', done => { fixture.detectChanges(); component.selection$.subscribe(selected => { - expect(selected).toEqual(selection); + expect(selected.library.entry.id).toEqual(selection.library.entry.id); + done(); + }); + }); + + it('should mark selection as favorite when on favorite libraries route', done => { + mockRouter.url = '/favorite/libraries'; + fixture.detectChanges(); + + component.selection$.subscribe(selected => { + expect(selected.library.isFavorite).toBe(true); done(); }); }); diff --git a/src/app/components/toolbar/toggle-favorite-library/toggle-favorite-library.component.ts b/src/app/components/toolbar/toggle-favorite-library/toggle-favorite-library.component.ts index c33ad2a64..e586cae1d 100644 --- a/src/app/components/toolbar/toggle-favorite-library/toggle-favorite-library.component.ts +++ b/src/app/components/toolbar/toggle-favorite-library/toggle-favorite-library.component.ts @@ -30,6 +30,8 @@ import { appSelection } from '../../../store/selectors/app.selectors'; import { Observable } from 'rxjs'; import { SelectionState } from '@alfresco/adf-extensions'; import { ContentManagementService } from '../../../services/content-management.service'; +import { distinctUntilChanged, map } from 'rxjs/operators'; +import { Router } from '@angular/router'; @Component({ selector: 'app-toggle-favorite-library', @@ -39,6 +41,11 @@ import { ContentManagementService } from '../../../services/content-management.s #favoriteLibrary="favoriteLibrary" (toggle)="onToggleEvent()" [acaFavoriteLibrary]="(selection$ | async).library" + [attr.title]=" + favoriteLibrary.isFavorite() + ? ('APP.ACTIONS.REMOVE_FAVORITE' | translate) + : ('APP.ACTIONS.ADD_FAVORITE' | translate) + " > star star_border @@ -53,11 +60,26 @@ export class ToggleFavoriteLibraryComponent implements OnInit { constructor( private store: Store, - private content: ContentManagementService + private content: ContentManagementService, + private router: Router ) {} ngOnInit() { - this.selection$ = this.store.select(appSelection); + const isFavoriteLibraries = this.router.url.startsWith( + '/favorite/libraries' + ); + + this.selection$ = this.store.select(appSelection).pipe( + distinctUntilChanged(), + map(selection => { + // favorite libraries list should already be marked as favorite + if (selection.library && isFavoriteLibraries) { + (selection.library).isFavorite = true; + return selection; + } + return selection; + }) + ); } onToggleEvent() { diff --git a/src/app/directives/library-favorite.directive.ts b/src/app/directives/library-favorite.directive.ts index 1a9c03ab7..8d8026d49 100644 --- a/src/app/directives/library-favorite.directive.ts +++ b/src/app/directives/library-favorite.directive.ts @@ -37,10 +37,6 @@ import { AlfrescoApiService } from '@alfresco/adf-core'; interface LibraryEntity { entry: Site; isLibrary: boolean; -} - -interface FavoriteLibrary { - entry: Site; isFavorite: boolean; } @@ -55,7 +51,7 @@ export class LibraryFavoriteDirective implements OnChanges { @Output() toggle: EventEmitter = new EventEmitter(); @Output() error: EventEmitter = new EventEmitter(); - private targetLibrary: any = null; + private targetLibrary = null; @HostListener('click') onClick() { @@ -66,9 +62,11 @@ export class LibraryFavoriteDirective implements OnChanges { ngOnChanges(changes) { if (!changes.library.currentValue) { + this.targetLibrary = null; return; } + this.targetLibrary = changes.library.currentValue; this.markFavoriteLibrary(changes.library.currentValue); } @@ -77,10 +75,6 @@ export class LibraryFavoriteDirective implements OnChanges { } toggleFavorite() { - if (!this.targetLibrary) { - return; - } - if (this.targetLibrary.isFavorite) { this.removeFavorite(this.targetLibrary.entry.guid); } else { @@ -90,22 +84,18 @@ export class LibraryFavoriteDirective implements OnChanges { } private async markFavoriteLibrary(library: LibraryEntity) { - this.targetLibrary = await this.getFavoriteSite(library); + if (this.targetLibrary.isFavorite === undefined) { + await this.getFavoriteSite(library); + } else { + this.targetLibrary = library; + } } - private getFavoriteSite(library: LibraryEntity): Promise { - return this.alfrescoApiService.peopleApi + private getFavoriteSite(library: LibraryEntity) { + this.alfrescoApiService.peopleApi .getFavoriteSite('-me-', library.entry.id) - .then(() => { - return { - entry: { ...this.library.entry }, - isFavorite: true - }; - }) - .catch(() => ({ - entry: { ...this.library.entry }, - isFavorite: false - })); + .then(() => (this.targetLibrary.isFavorite = true)) + .catch(() => (this.targetLibrary.isFavorite = false)); } private createFavoriteBody(library: LibraryEntity): FavoriteBody { diff --git a/src/assets/app.extensions.json b/src/assets/app.extensions.json index 1bbea184e..f46cfc9de 100644 --- a/src/assets/app.extensions.json +++ b/src/assets/app.extensions.json @@ -623,12 +623,21 @@ "id": "app.context.menu.favorite", "comment": "workaround for Recent Files and Search API issue", "type": "custom", - "order": 501, + "order": 601, "component": "app.toolbar.toggleFavorite", "rules": { "visible": "app.toolbar.favorite.canToggle" } }, + { + "id": "app.context.menu.libraries.toggleFavorite", + "type": "custom", + "order": 602, + "component": "app.toolbar.toggleFavoriteLibrary", + "rules": { + "visible": "app.libraries.toolbar" + } + }, { "id": "app.context.menu.copy", "title": "APP.ACTIONS.COPY", @@ -665,6 +674,18 @@ "visible": "app.selection.canDelete" } }, + { + "id": "app.toolbar.deleteLibrary", + "order": 901, + "title": "APP.ACTIONS.DELETE", + "icon": "delete", + "actions": { + "click": "DELETE_LIBRARY" + }, + "rules": { + "visible": "app.libraries.toolbar" + } + }, { "id": "app.context.menu.versions", "title": "APP.ACTIONS.VERSIONS", diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index cffb1c53f..8de6d6329 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -189,6 +189,8 @@ "PERMISSIONS": "Permissions", "RESTORE": "Restore", "FAVORITE": "Favorite", + "ADD_FAVORITE": "Add favorite", + "REMOVE_FAVORITE": "Remove favorite", "UNSHARE": "Unshare", "DETAILS": "View details", "VERSIONS": "Manage Versions",