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,12 +27,14 @@ import { TestBed, ComponentFixture } from '@angular/core/testing';
import { SearchInputComponent } from './search-input.component';
import { AppTestingModule } from '../../../testing/app-testing.module';
import { Actions, ofType } from '@ngrx/effects';
import { SearchByTermAction, SearchActionTypes, SnackbarErrorAction, SnackbarActionTypes } from '@alfresco/aca-shared/store';
import { SearchByTermAction, SearchActionTypes } from '@alfresco/aca-shared/store';
import { AppHookService, AppService } from '@alfresco/aca-shared';
import { map } from 'rxjs/operators';
import { SearchQueryBuilderService } from '@alfresco/adf-content-services';
import { SearchNavigationService } from '../search-navigation.service';
import { BehaviorSubject, Subject } from 'rxjs';
import { NotificationService } from '@alfresco/adf-core';
import { MatSnackBarModule } from '@angular/material/snack-bar';
describe('SearchInputComponent', () => {
let fixture: ComponentFixture<SearchInputComponent>;
@@ -40,6 +42,8 @@ describe('SearchInputComponent', () => {
let actions$: Actions;
let appHookService: AppHookService;
let searchInputService: SearchNavigationService;
let showErrorSpy: jasmine.Spy;
const appServiceMock = {
appNavNarMode$: new BehaviorSubject('collapsed'),
setAppNavbarMode: jasmine.createSpy('setAppNavbarMode'),
@@ -49,7 +53,7 @@ describe('SearchInputComponent', () => {
beforeEach(() => {
appServiceMock.setAppNavbarMode.calls.reset();
TestBed.configureTestingModule({
imports: [AppTestingModule, SearchInputComponent],
imports: [AppTestingModule, SearchInputComponent, MatSnackBarModule],
providers: [
{
provide: AppService,
@@ -65,6 +69,9 @@ describe('SearchInputComponent', () => {
appHookService = TestBed.inject(AppHookService);
searchInputService = TestBed.inject(SearchNavigationService);
component = fixture.componentInstance;
const notificationService = TestBed.inject(NotificationService);
showErrorSpy = spyOn(notificationService, 'showError');
});
afterEach(() => {
@@ -171,19 +178,9 @@ describe('SearchInputComponent', () => {
component.onSearchChange(searchedTerm);
});
it('should show snack for empty search', (done) => {
const searchedTerm = '';
actions$
.pipe(
ofType<SnackbarErrorAction>(SnackbarActionTypes.Error),
map((action) => {
expect(action.payload).toBe('APP.BROWSE.SEARCH.EMPTY_SEARCH');
})
)
.subscribe(() => {
done();
});
component.onSearchSubmit(searchedTerm);
it('should show snack for empty search', () => {
component.onSearchSubmit('');
expect(showErrorSpy).toHaveBeenCalled();
});
});

View File

@@ -23,10 +23,10 @@
*/
import { AppHookService, AppService } from '@alfresco/aca-shared';
import { AppStore, SearchByTermAction, SearchOptionIds, SearchOptionModel, SnackbarErrorAction } from '@alfresco/aca-shared/store';
import { AppStore, SearchByTermAction, SearchOptionIds, SearchOptionModel } from '@alfresco/aca-shared/store';
import { SearchQueryBuilderService } from '@alfresco/adf-content-services';
import { AppConfigService } from '@alfresco/adf-core';
import { Component, OnDestroy, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
import { AppConfigService, NotificationService } from '@alfresco/adf-core';
import { Component, inject, OnDestroy, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
import { MatMenuModule, MatMenuTrigger } from '@angular/material/menu';
import { NavigationEnd, PRIMARY_OUTLET, Router, RouterEvent, UrlSegment, UrlSegmentGroup, UrlTree } from '@angular/router';
import { Store } from '@ngrx/store';
@@ -67,6 +67,8 @@ import { FormsModule } from '@angular/forms';
host: { class: 'aca-search-input' }
})
export class SearchInputComponent implements OnInit, OnDestroy {
private notificationService = inject(NotificationService);
onDestroy$: Subject<boolean> = new Subject<boolean>();
hasOneChange = false;
hasNewChange = false;
@@ -174,7 +176,7 @@ export class SearchInputComponent implements OnInit, OnDestroy {
this.searchByOption();
} else {
this.store.dispatch(new SnackbarErrorAction('APP.BROWSE.SEARCH.EMPTY_SEARCH'));
this.notificationService.showError('APP.BROWSE.SEARCH.EMPTY_SEARCH');
}
if (this.trigger) {

View File

@@ -24,9 +24,9 @@
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { SearchResultsComponent } from './search-results.component';
import { AppConfigService, TranslationService } from '@alfresco/adf-core';
import { AppConfigService, NotificationService, TranslationService } from '@alfresco/adf-core';
import { Store } from '@ngrx/store';
import { NavigateToFolder, SnackbarErrorAction } from '@alfresco/aca-shared/store';
import { NavigateToFolder } from '@alfresco/aca-shared/store';
import { Pagination, SearchRequest } from '@alfresco/js-api';
import { SearchQueryBuilderService } from '@alfresco/adf-content-services';
import { ActivatedRoute, Router } from '@angular/router';
@@ -44,6 +44,7 @@ describe('SearchComponent', () => {
let router: Router;
const searchRequest = {} as SearchRequest;
let params: BehaviorSubject<any>;
let showErrorSpy: jasmine.Spy;
beforeEach(() => {
params = new BehaviorSubject({ q: 'TYPE: "cm:folder" AND %28=cm: name: email OR cm: name: budget%29' });
@@ -78,6 +79,9 @@ describe('SearchComponent', () => {
translate = TestBed.inject(TranslationService);
router = TestBed.inject(Router);
const notificationService = TestBed.inject(NotificationService);
showErrorSpy = spyOn(notificationService, 'showError');
config.config = {
search: {}
};
@@ -103,7 +107,7 @@ describe('SearchComponent', () => {
queryBuilder.execute();
tick();
expect(store.dispatch).toHaveBeenCalledWith(new SnackbarErrorAction('APP.BROWSE.SEARCH.ERRORS.GENERIC'));
expect(showErrorSpy).toHaveBeenCalledWith('APP.BROWSE.SEARCH.ERRORS.GENERIC');
}));
it('should raise a known error if search fails', fakeAsync(() => {
@@ -122,7 +126,7 @@ describe('SearchComponent', () => {
queryBuilder.execute();
tick();
expect(store.dispatch).toHaveBeenCalledWith(new SnackbarErrorAction('Known Error'));
expect(showErrorSpy).toHaveBeenCalledWith('Known Error');
}));
it('should raise a generic error if search fails', fakeAsync(() => {
@@ -141,7 +145,7 @@ describe('SearchComponent', () => {
queryBuilder.execute();
tick();
expect(store.dispatch).toHaveBeenCalledWith(new SnackbarErrorAction('Generic Error'));
expect(showErrorSpy).toHaveBeenCalledWith('Generic Error');
}));
it('should decode encoded URI', () => {

View File

@@ -22,7 +22,7 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { Component, inject, OnInit, ViewEncapsulation } from '@angular/core';
import { NodeEntry, Pagination, ResultSetPaging } from '@alfresco/js-api';
import { ActivatedRoute, Params } from '@angular/router';
import { AlfrescoViewerComponent, DocumentListModule, SearchModule, SearchQueryBuilderService, TagService } from '@alfresco/adf-content-services';
@@ -31,10 +31,9 @@ import {
NavigateToFolder,
SetInfoDrawerPreviewStateAction,
SetInfoDrawerStateAction,
ShowInfoDrawerPreviewAction,
SnackbarErrorAction
ShowInfoDrawerPreviewAction
} from '@alfresco/aca-shared/store';
import { DataTableModule, PaginationComponent, TranslationService, ViewerModule } from '@alfresco/adf-core';
import { DataTableModule, NotificationService, PaginationComponent, TranslationService, ViewerModule } from '@alfresco/adf-core';
import { combineLatest } from 'rxjs';
import {
ContextActionsDirective,
@@ -94,6 +93,8 @@ import { DocumentListPresetRef, DynamicColumnComponent } from '@alfresco/adf-ext
styleUrls: ['./search-results.component.scss']
})
export class SearchResultsComponent extends PageComponent implements OnInit {
private notificationService = inject(NotificationService);
infoDrawerPreview$ = this.store.select(infoDrawerPreview);
searchedWord: string;
@@ -180,13 +181,13 @@ export class SearchResultsComponent extends PageComponent implements OnInit {
const { statusCode } = JSON.parse(error.message).error;
const messageKey = `APP.BROWSE.SEARCH.ERRORS.${statusCode}`;
let translated = this.translationService.instant(messageKey);
let message = this.translationService.instant(messageKey);
if (translated === messageKey) {
translated = this.translationService.instant(`APP.BROWSE.SEARCH.ERRORS.GENERIC`);
if (message === messageKey) {
message = this.translationService.instant(`APP.BROWSE.SEARCH.ERRORS.GENERIC`);
}
this.store.dispatch(new SnackbarErrorAction(translated));
this.notificationService.showError(message);
}
private isOperator(input: string): boolean {

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) => {