Use ADF Notification Service instead of NgRx store (#3991)

This commit is contained in:
Denys Vuika
2024-08-07 18:33:39 -04:00
committed by GitHub
parent 2d5b9ea708
commit 9455269ca8
18 changed files with 202 additions and 233 deletions

View File

@@ -27,9 +27,11 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { of } from 'rxjs';
import { Store } from '@ngrx/store';
import { NodeEntry } from '@alfresco/js-api';
import { DownloadNodesAction, EditOfflineAction, SnackbarErrorAction } from '@alfresco/aca-shared/store';
import { DownloadNodesAction, EditOfflineAction } from '@alfresco/aca-shared/store';
import { AppTestingModule } from '../../../testing/app-testing.module';
import { AppExtensionService } from '@alfresco/aca-shared';
import { NotificationService } from '@alfresco/adf-core';
import { MatSnackBarModule } from '@angular/material/snack-bar';
describe('ToggleEditOfflineComponent', () => {
let fixture: ComponentFixture<ToggleEditOfflineComponent>;
@@ -38,6 +40,7 @@ describe('ToggleEditOfflineComponent', () => {
let dispatchSpy: jasmine.Spy;
let selectSpy: jasmine.Spy;
let selection: any;
let showErrorSpy: jasmine.Spy;
const extensionsMock = {
updateSidebarActions: jasmine.createSpy('updateSidebarActions')
@@ -45,7 +48,7 @@ describe('ToggleEditOfflineComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule, ToggleEditOfflineComponent],
imports: [AppTestingModule, ToggleEditOfflineComponent, MatSnackBarModule],
providers: [
{
provide: Store,
@@ -71,6 +74,9 @@ describe('ToggleEditOfflineComponent', () => {
selectSpy = spyOn(store, 'select');
selection = { file: { entry: { name: 'test', properties: {}, isLocked: false } } };
const notificationService = TestBed.inject(NotificationService);
showErrorSpy = spyOn(notificationService, 'showError');
});
it('should initialized with data from store', () => {
@@ -122,11 +128,7 @@ describe('ToggleEditOfflineComponent', () => {
component.onLockError();
fixture.detectChanges();
expect(dispatchSpy.calls.argsFor(0)).toEqual([
new SnackbarErrorAction('APP.MESSAGES.ERRORS.LOCK_NODE', {
fileName: 'test'
})
]);
expect(showErrorSpy).toHaveBeenCalledWith('APP.MESSAGES.ERRORS.LOCK_NODE', null, { fileName: 'test' });
});
it('should raise notification on unlock error', () => {
@@ -136,11 +138,7 @@ describe('ToggleEditOfflineComponent', () => {
component.onUnlockError();
fixture.detectChanges();
expect(dispatchSpy.calls.argsFor(0)).toEqual([
new SnackbarErrorAction('APP.MESSAGES.ERRORS.UNLOCK_NODE', {
fileName: 'test'
})
]);
expect(showErrorSpy).toHaveBeenCalledWith('APP.MESSAGES.ERRORS.UNLOCK_NODE', null, { fileName: 'test' });
});
it('should call updateSidebarActions on click', async () => {

View File

@@ -22,19 +22,12 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/
import {
AppStore,
DownloadNodesAction,
EditOfflineAction,
SetSelectedNodesAction,
SnackbarErrorAction,
getAppSelection
} from '@alfresco/aca-shared/store';
import { AppStore, DownloadNodesAction, EditOfflineAction, SetSelectedNodesAction, getAppSelection } from '@alfresco/aca-shared/store';
import { NodeEntry, SharedLinkEntry, Node, NodesApi } from '@alfresco/js-api';
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { Component, inject, OnInit, ViewEncapsulation } from '@angular/core';
import { Store } from '@ngrx/store';
import { AppExtensionService, isLocked } from '@alfresco/aca-shared';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { AlfrescoApiService, NotificationService } from '@alfresco/adf-core';
import { CommonModule } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
import { MatMenuModule } from '@angular/material/menu';
@@ -54,6 +47,8 @@ import { MatIconModule } from '@angular/material/icon';
host: { class: 'app-toggle-edit-offline' }
})
export class ToggleEditOfflineComponent implements OnInit {
private notificationService = inject(NotificationService);
private nodesApi: NodesApi;
selection: NodeEntry;
nodeTitle = '';
@@ -104,19 +99,11 @@ export class ToggleEditOfflineComponent implements OnInit {
}
onLockError() {
this.store.dispatch(
new SnackbarErrorAction('APP.MESSAGES.ERRORS.LOCK_NODE', {
fileName: this.selection.entry.name
})
);
this.notificationService.showError('APP.MESSAGES.ERRORS.LOCK_NODE', null, { fileName: this.selection.entry.name });
}
onUnlockError() {
this.store.dispatch(
new SnackbarErrorAction('APP.MESSAGES.ERRORS.UNLOCK_NODE', {
fileName: this.selection.entry.name
})
);
this.notificationService.showError('APP.MESSAGES.ERRORS.UNLOCK_NODE', null, { fileName: this.selection.entry.name });
}
lockNode(nodeId: string) {

View File

@@ -22,7 +22,7 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/
import { AppStore, SetSelectedNodesAction, SnackbarErrorAction, SnackbarInfoAction, getAppSelection } from '@alfresco/aca-shared/store';
import { AppStore, SetSelectedNodesAction, getAppSelection } from '@alfresco/aca-shared/store';
import { AppHookService, UserProfileService } from '@alfresco/aca-shared';
import { SelectionState } from '@alfresco/adf-extensions';
import { Component, inject, ViewEncapsulation } from '@angular/core';
@@ -33,6 +33,7 @@ import { CommonModule } from '@angular/common';
import { MatButtonModule } from '@angular/material/button';
import { TranslateModule } from '@ngx-translate/core';
import { MatIconModule } from '@angular/material/icon';
import { NotificationService } from '@alfresco/adf-core';
@Component({
standalone: true,
@@ -58,16 +59,19 @@ import { MatIconModule } from '@angular/material/icon';
})
export class ToggleJoinLibraryButtonComponent {
private userProfileService = inject(UserProfileService);
private notificationService = inject(NotificationService);
private appHookService = inject(AppHookService);
private store = inject(Store<AppStore>);
selection$: Observable<SelectionState>;
profile$ = this.userProfileService.userProfile$;
constructor(private store: Store<AppStore>, private appHookService: AppHookService) {
constructor() {
this.selection$ = this.store.select(getAppSelection);
}
onToggleEvent(event: LibraryMembershipToggleEvent) {
this.store.dispatch(new SnackbarInfoAction(event.i18nKey));
this.notificationService.showInfo(event.i18nKey);
if (event.shouldReload) {
this.appHookService.libraryJoined.next();
@@ -80,6 +84,6 @@ export class ToggleJoinLibraryButtonComponent {
}
onErrorEvent(event: LibraryMembershipErrorEvent) {
this.store.dispatch(new SnackbarErrorAction(event.i18nKey));
this.notificationService.showError(event.i18nKey);
}
}

View File

@@ -23,9 +23,6 @@
*/
import { Component, ViewEncapsulation } from '@angular/core';
import { Store } from '@ngrx/store';
import { AppHookService } from '@alfresco/aca-shared';
import { AppStore } from '@alfresco/aca-shared/store';
import { ToggleJoinLibraryButtonComponent } from './toggle-join-library-button.component';
import { CommonModule } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
@@ -55,8 +52,4 @@ import { MatMenuModule } from '@angular/material/menu';
encapsulation: ViewEncapsulation.None,
host: { class: 'app-toggle-join-library' }
})
export class ToggleJoinLibraryMenuComponent extends ToggleJoinLibraryButtonComponent {
constructor(store: Store<AppStore>, appHookService: AppHookService) {
super(store, appHookService);
}
}
export class ToggleJoinLibraryMenuComponent extends ToggleJoinLibraryButtonComponent {}

View File

@@ -26,18 +26,20 @@ import { of } from 'rxjs';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Store } from '@ngrx/store';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { SnackbarErrorAction, SnackbarInfoAction } from '@alfresco/aca-shared/store';
import { AppTestingModule } from '../../../testing/app-testing.module';
import { ToggleJoinLibraryButtonComponent } from './toggle-join-library-button.component';
import { AppHookService, ContentApiService } from '@alfresco/aca-shared';
import { NotificationService } from '@alfresco/adf-core';
import { MatSnackBarModule } from '@angular/material/snack-bar';
describe('ToggleJoinLibraryComponent', () => {
let component: ToggleJoinLibraryButtonComponent;
let fixture: ComponentFixture<ToggleJoinLibraryButtonComponent>;
let appHookService: AppHookService;
let contentApiService: any;
let store: Store<any>;
let entry;
let showErrorSpy: jasmine.Spy;
let showInfoSpy: jasmine.Spy;
beforeEach(() => {
entry = {
@@ -48,7 +50,7 @@ describe('ToggleJoinLibraryComponent', () => {
};
TestBed.configureTestingModule({
imports: [AppTestingModule, ToggleJoinLibraryButtonComponent],
imports: [AppTestingModule, ToggleJoinLibraryButtonComponent, MatSnackBarModule],
providers: [
{
provide: Store,
@@ -61,9 +63,12 @@ describe('ToggleJoinLibraryComponent', () => {
schemas: [NO_ERRORS_SCHEMA]
});
store = TestBed.inject(Store);
appHookService = TestBed.inject(AppHookService);
const notificationService = TestBed.inject(NotificationService);
showErrorSpy = spyOn(notificationService, 'showError');
showInfoSpy = spyOn(notificationService, 'showInfo');
contentApiService = TestBed.inject(ContentApiService);
fixture = TestBed.createComponent(ToggleJoinLibraryButtonComponent);
component = fixture.componentInstance;
@@ -81,18 +86,18 @@ describe('ToggleJoinLibraryComponent', () => {
});
});
it('should dispatch `SnackbarErrorAction` action on error', () => {
it('should show error notification on error', () => {
const event = { error: {}, i18nKey: 'ERROR_i18nKey' };
component.onErrorEvent(event);
expect(store.dispatch).toHaveBeenCalledWith(new SnackbarErrorAction(event.i18nKey));
expect(showErrorSpy).toHaveBeenCalledWith(event.i18nKey);
});
it('should dispatch `SnackbarInfoAction` action on onToggleEvent', () => {
it('should show info notification on onToggleEvent', () => {
const event = { shouldReload: true, i18nKey: 'SOME_i18nKey' };
component.onToggleEvent(event);
expect(store.dispatch).toHaveBeenCalledWith(new SnackbarInfoAction(event.i18nKey));
expect(showInfoSpy).toHaveBeenCalledWith(event.i18nKey);
});
it('should call libraryJoined.next on contentManagementService onToggleEvent', (done) => {