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

@@ -30,19 +30,21 @@ import {
LibraryActionTypes,
NavigateLibraryAction,
NavigateRouteAction,
SnackbarErrorAction,
UpdateLibraryAction,
getAppSelection
} from '@alfresco/aca-shared/store';
import { Injectable } from '@angular/core';
import { inject, Injectable } from '@angular/core';
import { Actions, ofType, createEffect } from '@ngrx/effects';
import { Store } from '@ngrx/store';
import { map, mergeMap, take } from 'rxjs/operators';
import { ContentApiService } from '@alfresco/aca-shared';
import { ContentManagementService } from '../../services/content-management.service';
import { NotificationService } from '@alfresco/adf-core';
@Injectable()
export class LibraryEffects {
private notificationService = inject(NotificationService);
constructor(
private store: Store<AppStore>,
private actions$: Actions,
@@ -120,7 +122,7 @@ export class LibraryEffects {
this.store.dispatch(new NavigateRouteAction([route, id]));
},
() => {
this.store.dispatch(new SnackbarErrorAction('APP.MESSAGES.ERRORS.MISSING_CONTENT'));
this.notificationService.showError('APP.MESSAGES.ERRORS.MISSING_CONTENT');
}
);
}

View File

@@ -27,13 +27,15 @@ import { AppTestingModule } from '../../testing/app-testing.module';
import { TemplateEffects } from './template.effects';
import { EffectsModule } from '@ngrx/effects';
import { Store } from '@ngrx/store';
import { CreateFromTemplate, CreateFromTemplateSuccess, FileFromTemplate, FolderFromTemplate, SnackbarErrorAction } from '@alfresco/aca-shared/store';
import { CreateFromTemplate, CreateFromTemplateSuccess, FileFromTemplate, FolderFromTemplate } from '@alfresco/aca-shared/store';
import { NodeTemplateService } from '../../services/node-template.service';
import { of, Subject } from 'rxjs';
import { Node, NodeEntry } from '@alfresco/js-api';
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { CreateFromTemplateDialogComponent } from '../../dialogs/node-template/create-from-template.dialog';
import { AppHookService } from '@alfresco/aca-shared';
import { NotificationService } from '@alfresco/adf-core';
import { MatSnackBarModule } from '@angular/material/snack-bar';
describe('TemplateEffects', () => {
let store: Store<any>;
@@ -43,6 +45,8 @@ describe('TemplateEffects', () => {
let copyNodeSpy;
let updateNodeSpy;
let matDialog: MatDialog;
let showErrorSpy;
const node: Node = {
name: 'node-name',
id: 'node-id',
@@ -72,7 +76,7 @@ describe('TemplateEffects', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule, EffectsModule.forRoot([TemplateEffects])],
imports: [AppTestingModule, EffectsModule.forRoot([TemplateEffects]), MatSnackBarModule],
providers: [
NodeTemplateService,
{
@@ -91,13 +95,16 @@ describe('TemplateEffects', () => {
matDialog = TestBed.inject(MatDialog);
subject = new Subject<Node[]>();
const notificationService = TestBed.inject(NotificationService);
showErrorSpy = spyOn(notificationService, 'showError');
spyOn(store, 'dispatch').and.callThrough();
spyOn(appHookService.reload, 'next');
spyOn(store, 'select').and.returnValue(of({ id: 'parent-id' }));
spyOn(nodeTemplateService, 'selectTemplateDialog').and.returnValue(subject);
copyNodeSpy = spyOn(templateEffects['nodesApi'], 'copyNode');
updateNodeSpy = spyOn(templateEffects['nodesApi'], 'updateNode');
copyNodeSpy = spyOn(templateEffects.nodesApi, 'copyNode');
updateNodeSpy = spyOn(templateEffects.nodesApi, 'updateNode');
});
afterEach(() => {
@@ -162,7 +169,7 @@ describe('TemplateEffects', () => {
tick();
expect(store.dispatch['calls'].mostRecent().args[0]).not.toEqual(new CreateFromTemplateSuccess(node));
expect(store.dispatch['calls'].argsFor(1)[0]).toEqual(new SnackbarErrorAction('APP.MESSAGES.ERRORS.GENERIC'));
expect(showErrorSpy).toHaveBeenCalledWith('APP.MESSAGES.ERRORS.GENERIC');
}));
it('should raise name conflict error when copyNode api returns 409', fakeAsync(() => {
@@ -172,7 +179,7 @@ describe('TemplateEffects', () => {
tick();
expect(store.dispatch['calls'].mostRecent().args[0]).not.toEqual(new CreateFromTemplateSuccess(node));
expect(store.dispatch['calls'].argsFor(1)[0]).toEqual(new SnackbarErrorAction('APP.MESSAGES.ERRORS.CONFLICT'));
expect(showErrorSpy).toHaveBeenCalledWith('APP.MESSAGES.ERRORS.CONFLICT');
}));
it('should resolve error with current node value when updateNode api fails', fakeAsync(() => {

View File

@@ -23,7 +23,7 @@
*/
import { Actions, ofType, createEffect } from '@ngrx/effects';
import { Injectable } from '@angular/core';
import { inject, Injectable } from '@angular/core';
import { map, switchMap, debounceTime, take, catchError } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import {
@@ -33,11 +33,10 @@ import {
CreateFromTemplateSuccess,
TemplateActionTypes,
getCurrentFolder,
AppStore,
SnackbarErrorAction
AppStore
} from '@alfresco/aca-shared/store';
import { NodeTemplateService, TemplateDialogConfig } from '../../services/node-template.service';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { AlfrescoApiService, NotificationService } from '@alfresco/adf-core';
import { AppHookService } from '@alfresco/aca-shared';
import { from, Observable, of } from 'rxjs';
import { NodeEntry, NodeBodyUpdate, Node, NodesApi } from '@alfresco/js-api';
@@ -45,6 +44,8 @@ import { MatDialog } from '@angular/material/dialog';
@Injectable()
export class TemplateEffects {
private notificationService = inject(NotificationService);
private _nodesApi: NodesApi;
get nodesApi(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance());
@@ -161,9 +162,9 @@ export class TemplateEffects {
}
if (statusCode !== 409) {
this.store.dispatch(new SnackbarErrorAction('APP.MESSAGES.ERRORS.GENERIC'));
this.notificationService.showError('APP.MESSAGES.ERRORS.GENERIC');
} else {
this.store.dispatch(new SnackbarErrorAction('APP.MESSAGES.ERRORS.CONFLICT'));
this.notificationService.showError('APP.MESSAGES.ERRORS.CONFLICT');
}
return of(null);

View File

@@ -24,7 +24,6 @@
import {
AppStore,
SnackbarErrorAction,
UnlockWriteAction,
UploadActionTypes,
UploadFilesAction,
@@ -32,8 +31,8 @@ import {
UploadFolderAction,
getCurrentFolder
} from '@alfresco/aca-shared/store';
import { FileUtils } from '@alfresco/adf-core';
import { Injectable, NgZone, RendererFactory2 } from '@angular/core';
import { FileUtils, NotificationService } from '@alfresco/adf-core';
import { inject, Injectable, NgZone, RendererFactory2 } from '@angular/core';
import { Actions, ofType, createEffect } from '@ngrx/effects';
import { Store } from '@ngrx/store';
import { of } from 'rxjs';
@@ -44,6 +43,8 @@ import { UploadService, FileModel } from '@alfresco/adf-content-services';
@Injectable()
export class UploadEffects {
private notificationService = inject(NotificationService);
private readonly fileInput: HTMLInputElement;
private readonly folderInput: HTMLInputElement;
private readonly fileVersionInput: HTMLInputElement;
@@ -133,7 +134,7 @@ export class UploadEffects {
.getNodeInfo()
.pipe(
catchError(() => {
this.store.dispatch(new SnackbarErrorAction('VERSION.ERROR.GENERIC'));
this.notificationService.showError('VERSION.ERROR.GENERIC');
return of(null);
})
)