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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -79,6 +79,9 @@ describe('ContentManagementService', () => {
let nodeAspectService: NodeAspectService; let nodeAspectService: NodeAspectService;
let appHookService: AppHookService; let appHookService: AppHookService;
let newVersionUploaderService: NewVersionUploaderService; let newVersionUploaderService: NewVersionUploaderService;
let showErrorSpy: jasmine.Spy;
let showInfoSpy: jasmine.Spy;
let showWarningSpy: jasmine.Spy;
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
@@ -90,6 +93,9 @@ describe('ContentManagementService', () => {
store = TestBed.inject(Store); store = TestBed.inject(Store);
contentManagementService = TestBed.inject(ContentManagementService); contentManagementService = TestBed.inject(ContentManagementService);
notificationService = TestBed.inject(NotificationService); notificationService = TestBed.inject(NotificationService);
showErrorSpy = spyOn(notificationService, 'showError');
showInfoSpy = spyOn(notificationService, 'showInfo');
showWarningSpy = spyOn(notificationService, 'showWarning');
nodeActions = TestBed.inject(NodeActionsService); nodeActions = TestBed.inject(NodeActionsService);
translationService = TestBed.inject(TranslationService); translationService = TestBed.inject(TranslationService);
nodesApiService = TestBed.inject(NodesApiService); nodesApiService = TestBed.inject(NodesApiService);
@@ -923,14 +929,7 @@ describe('ContentManagementService', () => {
}); });
describe('notification', () => { describe('notification', () => {
it('raises warning on multiple fail and one success', (done) => { it('raises warning on multiple fail and one success', () => {
actions$
.pipe(
ofType<SnackbarWarningAction>(SnackbarActionTypes.Warning),
map((action) => expect(action).toBeDefined())
)
.subscribe(() => done());
spyOn(contentApi, 'purgeDeletedNode').and.callFake((id) => { spyOn(contentApi, 'purgeDeletedNode').and.callFake((id) => {
if (id === '1') { if (id === '1') {
return of({}); return of({});
@@ -954,16 +953,10 @@ describe('ContentManagementService', () => {
]; ];
store.dispatch(new PurgeDeletedNodesAction(selection)); store.dispatch(new PurgeDeletedNodesAction(selection));
expect(showWarningSpy).toHaveBeenCalled();
}); });
it('raises warning on multiple success and multiple fail', (done) => { it('raises warning on multiple success and multiple fail', () => {
actions$
.pipe(
ofType<SnackbarWarningAction>(SnackbarActionTypes.Warning),
map((action) => expect(action).toBeDefined())
)
.subscribe(() => done());
spyOn(contentApi, 'purgeDeletedNode').and.callFake((id) => { spyOn(contentApi, 'purgeDeletedNode').and.callFake((id) => {
if (id === '1') { if (id === '1') {
return of({}); return of({});
@@ -992,46 +985,28 @@ describe('ContentManagementService', () => {
]; ];
store.dispatch(new PurgeDeletedNodesAction(selection)); store.dispatch(new PurgeDeletedNodesAction(selection));
expect(showWarningSpy).toHaveBeenCalled();
}); });
it('raises info on one selected node success', (done) => { it('raises info on one selected node success', () => {
actions$
.pipe(
ofType<SnackbarInfoAction>(SnackbarActionTypes.Info),
map((action) => expect(action).toBeDefined())
)
.subscribe(() => done());
spyOn(contentApi, 'purgeDeletedNode').and.returnValue(of({})); spyOn(contentApi, 'purgeDeletedNode').and.returnValue(of({}));
const selection: any[] = [{ entry: { id: '1', name: 'name1' } }]; const selection: any[] = [{ entry: { id: '1', name: 'name1' } }];
store.dispatch(new PurgeDeletedNodesAction(selection)); store.dispatch(new PurgeDeletedNodesAction(selection));
expect(showInfoSpy).toHaveBeenCalled();
}); });
it('raises error on one selected node fail', (done) => { it('raises error on one selected node fail', () => {
actions$
.pipe(
ofType<SnackbarErrorAction>(SnackbarActionTypes.Error),
map((action) => expect(action).toBeDefined())
)
.subscribe(() => done());
spyOn(contentApi, 'purgeDeletedNode').and.returnValue(throwError({})); spyOn(contentApi, 'purgeDeletedNode').and.returnValue(throwError({}));
const selection: any[] = [{ entry: { id: '1', name: 'name1' } }]; const selection: any[] = [{ entry: { id: '1', name: 'name1' } }];
store.dispatch(new PurgeDeletedNodesAction(selection)); store.dispatch(new PurgeDeletedNodesAction(selection));
expect(showErrorSpy).toHaveBeenCalled();
}); });
it('raises info on all nodes success', (done) => { it('raises info on all nodes success', () => {
actions$
.pipe(
ofType<SnackbarInfoAction>(SnackbarActionTypes.Info),
map((action) => expect(action).toBeDefined())
)
.subscribe(() => done());
spyOn(contentApi, 'purgeDeletedNode').and.callFake((id) => { spyOn(contentApi, 'purgeDeletedNode').and.callFake((id) => {
if (id === '1') { if (id === '1') {
return of({}); return of({});
@@ -1047,16 +1022,10 @@ describe('ContentManagementService', () => {
const selection: any[] = [{ entry: { id: '1', name: 'name1' } }, { entry: { id: '2', name: 'name2' } }]; const selection: any[] = [{ entry: { id: '1', name: 'name1' } }, { entry: { id: '2', name: 'name2' } }];
store.dispatch(new PurgeDeletedNodesAction(selection)); store.dispatch(new PurgeDeletedNodesAction(selection));
expect(showInfoSpy).toHaveBeenCalled();
}); });
it('raises error on all nodes fail', (done) => { it('raises error on all nodes fail', () => {
actions$
.pipe(
ofType<SnackbarErrorAction>(SnackbarActionTypes.Error),
map((action) => expect(action).toBeDefined())
)
.subscribe(() => done());
spyOn(contentApi, 'purgeDeletedNode').and.callFake((id) => { spyOn(contentApi, 'purgeDeletedNode').and.callFake((id) => {
if (id === '1') { if (id === '1') {
return throwError({}); return throwError({});
@@ -1072,6 +1041,7 @@ describe('ContentManagementService', () => {
const selection: any[] = [{ entry: { id: '1', name: 'name1' } }, { entry: { id: '2', name: 'name2' } }]; const selection: any[] = [{ entry: { id: '1', name: 'name1' } }, { entry: { id: '2', name: 'name2' } }];
store.dispatch(new PurgeDeletedNodesAction(selection)); store.dispatch(new PurgeDeletedNodesAction(selection));
expect(showErrorSpy).toHaveBeenCalled();
}); });
}); });
}); });
@@ -1510,11 +1480,7 @@ describe('ContentManagementService', () => {
tick(); tick();
flush(); flush();
expect(store.dispatch['calls'].argsFor(1)[0]).toEqual( expect(showErrorSpy).toHaveBeenCalledWith('APP.MESSAGES.ERRORS.UNLOCK_NODE', null, { fileName: 'some-file' });
new SnackbarErrorAction('APP.MESSAGES.ERRORS.UNLOCK_NODE', {
fileName: 'some-file'
})
);
})); }));
}); });
@@ -1573,7 +1539,8 @@ describe('ContentManagementService', () => {
const fakeError = 'Upload error'; const fakeError = 'Upload error';
spyOnOpenUploadNewVersionDialog.and.returnValue(throwError(fakeError)); spyOnOpenUploadNewVersionDialog.and.returnValue(throwError(fakeError));
contentManagementService.versionUpdateDialog(fakeNode, fakeFile); contentManagementService.versionUpdateDialog(fakeNode, fakeFile);
expect(spyOnDispatch).toHaveBeenCalledOnceWith(new SnackbarErrorAction(fakeError));
expect(showErrorSpy).toHaveBeenCalledOnceWith(fakeError);
}); });
}); });
@@ -1627,7 +1594,7 @@ describe('ContentManagementService', () => {
it('should show permission error is node is not a file and does not have nodeId', () => { it('should show permission error is node is not a file and does not have nodeId', () => {
contentManagementService.manageVersions(fakeNodeIsNotFile); contentManagementService.manageVersions(fakeNodeIsNotFile);
expect(spyOnDispatch).toHaveBeenCalledOnceWith(new SnackbarErrorAction('APP.MESSAGES.ERRORS.PERMISSION')); expect(showErrorSpy).toHaveBeenCalledWith('APP.MESSAGES.ERRORS.PERMISSION');
}); });
}); });
@@ -1658,7 +1625,7 @@ describe('ContentManagementService', () => {
mockDialogInstance.componentInstance.error.next('edit folder error'); mockDialogInstance.componentInstance.error.next('edit folder error');
expect(store.dispatch['calls'].argsFor(0)[0]).toEqual(new SnackbarErrorAction('edit folder error')); expect(showErrorSpy).toHaveBeenCalledWith('edit folder error');
})); }));
it('should call nodeUpdated event with edited node data', fakeAsync(() => { it('should call nodeUpdated event with edited node data', fakeAsync(() => {
@@ -1783,7 +1750,7 @@ describe('ContentManagementService', () => {
contentManagementService.deleteLibrary(libraryId); contentManagementService.deleteLibrary(libraryId);
tick(); tick();
expect(store.dispatch).toHaveBeenCalledWith(new SnackbarInfoAction('APP.MESSAGES.INFO.LIBRARY_DELETED')); expect(showInfoSpy).toHaveBeenCalledWith('APP.MESSAGES.INFO.LIBRARY_DELETED');
expect(store.dispatch).toHaveBeenCalledWith(new NavigateRouteAction(['/libraries'])); expect(store.dispatch).toHaveBeenCalledWith(new NavigateRouteAction(['/libraries']));
})); }));
}); });

View File

@@ -57,7 +57,7 @@ import {
} from '@alfresco/adf-content-services'; } from '@alfresco/adf-content-services';
import { NotificationService, TranslationService, ConfirmDialogComponent } from '@alfresco/adf-core'; import { NotificationService, TranslationService, ConfirmDialogComponent } from '@alfresco/adf-core';
import { DeletedNodesPaging, Node, NodeEntry, PathInfo, SiteBodyCreate, SiteEntry } from '@alfresco/js-api'; import { DeletedNodesPaging, Node, NodeEntry, PathInfo, SiteBodyCreate, SiteEntry } from '@alfresco/js-api';
import { Injectable } from '@angular/core'; import { inject, Injectable } from '@angular/core';
import { MatDialog, MatDialogConfig } from '@angular/material/dialog'; import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { forkJoin, Observable, of, zip } from 'rxjs'; import { forkJoin, Observable, of, zip } from 'rxjs';
@@ -75,6 +75,7 @@ interface RestoredNode {
providedIn: 'root' providedIn: 'root'
}) })
export class ContentManagementService { export class ContentManagementService {
private notificationService = inject(NotificationService);
private readonly createMenuButtonSelector = 'app-toolbar-menu button[id="app.toolbar.create"]'; private readonly createMenuButtonSelector = 'app-toolbar-menu button[id="app.toolbar.create"]';
constructor( constructor(
@@ -85,7 +86,6 @@ export class ContentManagementService {
private dialogRef: MatDialog, private dialogRef: MatDialog,
private nodeActionsService: NodeActionsService, private nodeActionsService: NodeActionsService,
private translation: TranslationService, private translation: TranslationService,
private notificationService: NotificationService,
private nodeAspectService: NodeAspectService, private nodeAspectService: NodeAspectService,
private appHookService: AppHookService, private appHookService: AppHookService,
private newVersionUploaderService: NewVersionUploaderService, private newVersionUploaderService: NewVersionUploaderService,
@@ -168,7 +168,7 @@ export class ContentManagementService {
} }
} }
}, },
(error) => this.store.dispatch(new SnackbarErrorAction(error)) (error) => this.notificationService.showError(error)
); );
}); });
} }
@@ -221,7 +221,7 @@ export class ContentManagementService {
}); });
dialogInstance.componentInstance.error.subscribe((message: string) => { dialogInstance.componentInstance.error.subscribe((message: string) => {
this.store.dispatch(new SnackbarErrorAction(message)); this.notificationService.showError(message);
}); });
dialogInstance.afterClosed().subscribe((node) => { dialogInstance.afterClosed().subscribe((node) => {
@@ -245,7 +245,7 @@ export class ContentManagementService {
}); });
dialog.componentInstance.error.subscribe((message: string) => { dialog.componentInstance.error.subscribe((message: string) => {
this.store.dispatch(new SnackbarErrorAction(message)); this.notificationService.showError(message);
}); });
dialog.afterClosed().subscribe((node) => { dialog.afterClosed().subscribe((node) => {
@@ -263,7 +263,7 @@ export class ContentManagementService {
}); });
dialogInstance.componentInstance.error.subscribe((message: string) => { dialogInstance.componentInstance.error.subscribe((message: string) => {
this.store.dispatch(new SnackbarErrorAction(message)); this.notificationService.showError(message);
}); });
return dialogInstance.afterClosed().pipe( return dialogInstance.afterClosed().pipe(
@@ -286,11 +286,11 @@ export class ContentManagementService {
this.contentApi.deleteSite(id).subscribe( this.contentApi.deleteSite(id).subscribe(
() => { () => {
this.appHookService.libraryDeleted.next(id); this.appHookService.libraryDeleted.next(id);
this.store.dispatch(new SnackbarInfoAction('APP.MESSAGES.INFO.LIBRARY_DELETED')); this.notificationService.showInfo('APP.MESSAGES.INFO.LIBRARY_DELETED');
this.store.dispatch(new NavigateRouteAction(['/libraries'])); this.store.dispatch(new NavigateRouteAction(['/libraries']));
}, },
() => { () => {
this.store.dispatch(new SnackbarErrorAction('APP.MESSAGES.ERRORS.DELETE_LIBRARY_FAILED')); this.notificationService.showError('APP.MESSAGES.ERRORS.DELETE_LIBRARY_FAILED');
} }
); );
} }
@@ -311,10 +311,10 @@ export class ContentManagementService {
this.contentApi.leaveSite(siteId).subscribe( this.contentApi.leaveSite(siteId).subscribe(
() => { () => {
this.appHookService.libraryLeft.next(siteId); this.appHookService.libraryLeft.next(siteId);
this.store.dispatch(new SnackbarInfoAction('APP.MESSAGES.INFO.LEFT_LIBRARY')); this.notificationService.showInfo('APP.MESSAGES.INFO.LEFT_LIBRARY');
}, },
() => { () => {
this.store.dispatch(new SnackbarErrorAction('APP.MESSAGES.ERRORS.LEAVE_LIBRARY_FAILED')); this.notificationService.showError('APP.MESSAGES.ERRORS.LEAVE_LIBRARY_FAILED');
} }
); );
} }
@@ -326,10 +326,10 @@ export class ContentManagementService {
this.contentApi.updateLibrary(siteId, siteBody).subscribe( this.contentApi.updateLibrary(siteId, siteBody).subscribe(
(siteEntry: SiteEntry) => { (siteEntry: SiteEntry) => {
this.appHookService.libraryUpdated.next(siteEntry); this.appHookService.libraryUpdated.next(siteEntry);
this.store.dispatch(new SnackbarInfoAction('LIBRARY.SUCCESS.LIBRARY_UPDATED')); this.notificationService.showInfo('LIBRARY.SUCCESS.LIBRARY_UPDATED');
}, },
() => { () => {
this.store.dispatch(new SnackbarErrorAction('LIBRARY.ERRORS.LIBRARY_UPDATE_ERROR')); this.notificationService.showError('LIBRARY.ERRORS.LIBRARY_UPDATE_ERROR');
} }
); );
} }
@@ -480,11 +480,7 @@ export class ContentManagementService {
unlockNode(node: NodeEntry): Promise<void | NodeEntry> { unlockNode(node: NodeEntry): Promise<void | NodeEntry> {
return this.contentApi.unlockNode(node.entry.id).catch(() => { return this.contentApi.unlockNode(node.entry.id).catch(() => {
this.store.dispatch( this.notificationService.showError('APP.MESSAGES.ERRORS.UNLOCK_NODE', null, { fileName: node.entry.name });
new SnackbarErrorAction('APP.MESSAGES.ERRORS.UNLOCK_NODE', {
fileName: node.entry.name
})
);
}); });
} }
@@ -560,7 +556,7 @@ export class ContentManagementService {
i18nMessageString = 'APP.MESSAGES.ERRORS.PERMISSION'; i18nMessageString = 'APP.MESSAGES.ERRORS.PERMISSION';
} }
this.store.dispatch(new SnackbarErrorAction(i18nMessageString)); this.notificationService.showError(i18nMessageString);
} }
); );
} }
@@ -594,7 +590,7 @@ export class ContentManagementService {
} }
}); });
} else { } else {
this.store.dispatch(new SnackbarErrorAction('APP.MESSAGES.ERRORS.PERMISSION')); this.notificationService.showError('APP.MESSAGES.ERRORS.PERMISSION');
} }
} }
@@ -603,7 +599,7 @@ export class ContentManagementService {
if (node.isFile || node.id) { if (node.isFile || node.id) {
this.nodeAspectService.updateNodeAspects(node.id, focusedElementOnCloseSelector); this.nodeAspectService.updateNodeAspects(node.id, focusedElementOnCloseSelector);
} else { } else {
this.store.dispatch(new SnackbarErrorAction('APP.MESSAGES.ERRORS.PERMISSION')); this.notificationService.showError('APP.MESSAGES.ERRORS.PERMISSION');
} }
} }
@@ -650,7 +646,7 @@ export class ContentManagementService {
message = 'APP.MESSAGES.ERRORS.PERMISSION'; message = 'APP.MESSAGES.ERRORS.PERMISSION';
} }
this.store.dispatch(new SnackbarErrorAction(message)); this.notificationService.showError(message);
} }
); );
} }
@@ -767,10 +763,8 @@ export class ContentManagementService {
if (status.success.length) { if (status.success.length) {
this.store.dispatch(new ReloadDocumentListAction()); this.store.dispatch(new ReloadDocumentListAction());
} }
const message = this.getPurgeMessage(status);
if (message) { this.sendPurgeMessage(status);
this.store.dispatch(message);
}
}); });
} }
@@ -832,38 +826,42 @@ export class ContentManagementService {
}, status); }, status);
} }
private getPurgeMessage(status: DeleteStatus): SnackbarAction { private sendPurgeMessage(status: DeleteStatus): void {
if (status.oneSucceeded && status.someFailed && !status.oneFailed) { if (status.oneSucceeded && status.someFailed && !status.oneFailed) {
return new SnackbarWarningAction('APP.MESSAGES.INFO.TRASH.NODES_PURGE.PARTIAL_SINGULAR', { this.notificationService.showWarning('APP.MESSAGES.INFO.TRASH.NODES_PURGE.PARTIAL_SINGULAR', null, {
name: status.success[0].name, name: status.success[0].name,
failed: status.fail.length failed: status.fail.length
}); });
return;
} }
if (status.someSucceeded && !status.oneSucceeded && status.someFailed) { if (status.someSucceeded && !status.oneSucceeded && status.someFailed) {
return new SnackbarWarningAction('APP.MESSAGES.INFO.TRASH.NODES_PURGE.PARTIAL_PLURAL', { this.notificationService.showWarning('APP.MESSAGES.INFO.TRASH.NODES_PURGE.PARTIAL_PLURAL', null, {
number: status.success.length, number: status.success.length,
failed: status.fail.length failed: status.fail.length
}); });
return;
} }
if (status.oneSucceeded) { if (status.oneSucceeded) {
return new SnackbarInfoAction('APP.MESSAGES.INFO.TRASH.NODES_PURGE.SINGULAR', { name: status.success[0].name }); this.notificationService.showInfo('APP.MESSAGES.INFO.TRASH.NODES_PURGE.SINGULAR', null, { name: status.success[0].name });
return;
} }
if (status.oneFailed) { if (status.oneFailed) {
return new SnackbarErrorAction('APP.MESSAGES.ERRORS.TRASH.NODES_PURGE.SINGULAR', { name: status.fail[0].name }); this.notificationService.showError('APP.MESSAGES.ERRORS.TRASH.NODES_PURGE.SINGULAR', null, { name: status.fail[0].name });
return;
} }
if (status.allSucceeded) { if (status.allSucceeded) {
return new SnackbarInfoAction('APP.MESSAGES.INFO.TRASH.NODES_PURGE.PLURAL', { number: status.success.length }); this.notificationService.showInfo('APP.MESSAGES.INFO.TRASH.NODES_PURGE.PLURAL', null, { number: status.success.length });
return;
} }
if (status.allFailed) { if (status.allFailed) {
return new SnackbarErrorAction('APP.MESSAGES.ERRORS.TRASH.NODES_PURGE.PLURAL', { number: status.fail.length }); this.notificationService.showError('APP.MESSAGES.ERRORS.TRASH.NODES_PURGE.PLURAL', null, { number: status.fail.length });
return;
} }
return null;
} }
private showRestoreNotification(status: DeleteStatus): void { private showRestoreNotification(status: DeleteStatus): void {

View File

@@ -24,18 +24,21 @@
import { TestBed, fakeAsync, tick } from '@angular/core/testing'; import { TestBed, fakeAsync, tick } from '@angular/core/testing';
import { EffectsModule } from '@ngrx/effects'; import { EffectsModule } from '@ngrx/effects';
import { AppStore, SnackbarErrorAction } from '@alfresco/aca-shared/store';
import { TemplateEffects } from '../store/effects/template.effects'; import { TemplateEffects } from '../store/effects/template.effects';
import { AppTestingModule } from '../testing/app-testing.module'; import { AppTestingModule } from '../testing/app-testing.module';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { MatDialog, MatDialogModule } from '@angular/material/dialog'; import { MatDialog, MatDialogModule } from '@angular/material/dialog';
import { NodeTemplateService } from './node-template.service'; import { NodeTemplateService } from './node-template.service';
import { ResultSetPaging } from '@alfresco/js-api'; import { ResultSetPaging } from '@alfresco/js-api';
import { NotificationService } from '@alfresco/adf-core';
import { MatSnackBarModule } from '@angular/material/snack-bar';
describe('NodeTemplateService', () => { describe('NodeTemplateService', () => {
let dialog: MatDialog; let dialog: MatDialog;
let store: Store<AppStore>; let store: Store<any>;
let nodeTemplateService: NodeTemplateService; let nodeTemplateService: NodeTemplateService;
let showErrorSpy: jasmine.Spy;
const fileTemplateConfig = { const fileTemplateConfig = {
primaryPathName: 'parent-file-templates', primaryPathName: 'parent-file-templates',
selectionType: 'file' selectionType: 'file'
@@ -47,7 +50,7 @@ describe('NodeTemplateService', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [AppTestingModule, EffectsModule.forRoot([TemplateEffects]), MatDialogModule], imports: [AppTestingModule, EffectsModule.forRoot([TemplateEffects]), MatDialogModule, MatSnackBarModule],
providers: [NodeTemplateService] providers: [NodeTemplateService]
}); });
@@ -55,10 +58,13 @@ describe('NodeTemplateService', () => {
dialog = TestBed.inject(MatDialog); dialog = TestBed.inject(MatDialog);
nodeTemplateService = TestBed.inject(NodeTemplateService); nodeTemplateService = TestBed.inject(NodeTemplateService);
spyOn(document, 'querySelector').and.returnValue(document.createElement('button')); spyOn(document, 'querySelector').and.returnValue(document.createElement('button'));
const notificationService = TestBed.inject(NotificationService);
showErrorSpy = spyOn(notificationService, 'showError');
}); });
it('should open dialog with parent node `id` as data property', fakeAsync(() => { it('should open dialog with parent node `id` as data property', fakeAsync(() => {
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue( spyOn(nodeTemplateService.searchApi, 'search').and.returnValue(
Promise.resolve({ Promise.resolve({
list: { entries: [{ entry: { id: 'parent-node-id' } }] } list: { entries: [{ entry: { id: 'parent-node-id' } }] }
} as ResultSetPaging) } as ResultSetPaging)
@@ -72,7 +78,7 @@ describe('NodeTemplateService', () => {
})); }));
it('should remove parents path for templates breadcrumb', fakeAsync(() => { it('should remove parents path for templates breadcrumb', fakeAsync(() => {
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue( spyOn(nodeTemplateService.searchApi, 'search').and.returnValue(
Promise.resolve({ Promise.resolve({
list: { list: {
entries: [ entries: [
@@ -112,7 +118,7 @@ describe('NodeTemplateService', () => {
})); }));
it('should set template folder path as root for breadcrumb', fakeAsync(() => { it('should set template folder path as root for breadcrumb', fakeAsync(() => {
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue( spyOn(nodeTemplateService.searchApi, 'search').and.returnValue(
Promise.resolve({ Promise.resolve({
list: { list: {
entries: [ entries: [
@@ -153,17 +159,17 @@ describe('NodeTemplateService', () => {
})); }));
it('should raise an error when getNodeInfo fails', fakeAsync(() => { it('should raise an error when getNodeInfo fails', fakeAsync(() => {
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue(Promise.reject(new Error('{ "error": { "statusCode": 404 } }'))); spyOn(nodeTemplateService.searchApi, 'search').and.returnValue(Promise.reject(new Error('{ "error": { "statusCode": 404 } }')));
spyOn(store, 'dispatch'); spyOn(store, 'dispatch');
nodeTemplateService.selectTemplateDialog(fileTemplateConfig); nodeTemplateService.selectTemplateDialog(fileTemplateConfig);
tick(); tick();
expect(store.dispatch).toHaveBeenCalledWith(new SnackbarErrorAction('APP.MESSAGES.ERRORS.GENERIC')); expect(showErrorSpy).toHaveBeenCalledWith('APP.MESSAGES.ERRORS.GENERIC');
})); }));
it('should return true if row is not a `link` nodeType', fakeAsync(() => { it('should return true if row is not a `link` nodeType', fakeAsync(() => {
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue( spyOn(nodeTemplateService.searchApi, 'search').and.returnValue(
Promise.resolve({ Promise.resolve({
list: { list: {
entries: [ entries: [
@@ -193,7 +199,7 @@ describe('NodeTemplateService', () => {
})); }));
it('should return false if row is a `filelink` nodeType', fakeAsync(() => { it('should return false if row is a `filelink` nodeType', fakeAsync(() => {
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue( spyOn(nodeTemplateService.searchApi, 'search').and.returnValue(
Promise.resolve({ Promise.resolve({
list: { list: {
entries: [ entries: [
@@ -223,7 +229,7 @@ describe('NodeTemplateService', () => {
})); }));
it('should return false if row is a `folderlink` nodeType', fakeAsync(() => { it('should return false if row is a `folderlink` nodeType', fakeAsync(() => {
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue( spyOn(nodeTemplateService.searchApi, 'search').and.returnValue(
Promise.resolve({ Promise.resolve({
list: { list: {
entries: [ entries: [
@@ -254,7 +260,7 @@ describe('NodeTemplateService', () => {
describe('File templates', () => { describe('File templates', () => {
it('should return false if selected node is not a file', fakeAsync(() => { it('should return false if selected node is not a file', fakeAsync(() => {
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue( spyOn(nodeTemplateService.searchApi, 'search').and.returnValue(
Promise.resolve({ Promise.resolve({
list: { entries: [{ entry: { id: 'templates-folder-id' } }] } list: { entries: [{ entry: { id: 'templates-folder-id' } }] }
} as ResultSetPaging) } as ResultSetPaging)
@@ -275,7 +281,7 @@ describe('NodeTemplateService', () => {
})); }));
it('should return true if selected node is a template file', fakeAsync(() => { it('should return true if selected node is a template file', fakeAsync(() => {
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue( spyOn(nodeTemplateService.searchApi, 'search').and.returnValue(
Promise.resolve({ Promise.resolve({
list: { entries: [{ entry: { id: 'templates-folder-id' } }] } list: { entries: [{ entry: { id: 'templates-folder-id' } }] }
} as ResultSetPaging) } as ResultSetPaging)
@@ -296,7 +302,7 @@ describe('NodeTemplateService', () => {
})); }));
it('should set dialog title for file templates', fakeAsync(() => { it('should set dialog title for file templates', fakeAsync(() => {
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue( spyOn(nodeTemplateService.searchApi, 'search').and.returnValue(
Promise.resolve({ Promise.resolve({
list: { entries: [{ entry: { id: 'templates-folder-id' } }] } list: { entries: [{ entry: { id: 'templates-folder-id' } }] }
} as ResultSetPaging) } as ResultSetPaging)
@@ -314,7 +320,7 @@ describe('NodeTemplateService', () => {
describe('Folder templates', () => { describe('Folder templates', () => {
it('should return false if selected node is not a folder', fakeAsync(() => { it('should return false if selected node is not a folder', fakeAsync(() => {
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue( spyOn(nodeTemplateService.searchApi, 'search').and.returnValue(
Promise.resolve({ Promise.resolve({
list: { entries: [{ entry: { id: 'templates-folder-id' } }] } list: { entries: [{ entry: { id: 'templates-folder-id' } }] }
} as ResultSetPaging) } as ResultSetPaging)
@@ -335,7 +341,7 @@ describe('NodeTemplateService', () => {
})); }));
it('should return false if current node is the parent folder', fakeAsync(() => { it('should return false if current node is the parent folder', fakeAsync(() => {
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue( spyOn(nodeTemplateService.searchApi, 'search').and.returnValue(
Promise.resolve({ Promise.resolve({
list: { entries: [{ entry: { id: 'templates-folder-id' } }] } list: { entries: [{ entry: { id: 'templates-folder-id' } }] }
} as ResultSetPaging) } as ResultSetPaging)
@@ -356,7 +362,7 @@ describe('NodeTemplateService', () => {
})); }));
it('should return true if selected node is a folder template', fakeAsync(() => { it('should return true if selected node is a folder template', fakeAsync(() => {
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue( spyOn(nodeTemplateService.searchApi, 'search').and.returnValue(
Promise.resolve({ Promise.resolve({
list: { list: {
entries: [{ entry: { id: 'templates-folder-id', path: { elements: [] } } }] entries: [{ entry: { id: 'templates-folder-id', path: { elements: [] } } }]
@@ -379,7 +385,7 @@ describe('NodeTemplateService', () => {
})); }));
it('should set dialog title for folder templates', fakeAsync(() => { it('should set dialog title for folder templates', fakeAsync(() => {
spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue( spyOn(nodeTemplateService.searchApi, 'search').and.returnValue(
Promise.resolve({ Promise.resolve({
list: { entries: [{ entry: { id: 'templates-folder-id' } }] } list: { entries: [{ entry: { id: 'templates-folder-id' } }] }
} as ResultSetPaging) } as ResultSetPaging)

View File

@@ -22,15 +22,13 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>. * from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/ */
import { Injectable } from '@angular/core'; import { inject, Injectable } from '@angular/core';
import { MatDialog, MatDialogRef } from '@angular/material/dialog'; import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { CreateFromTemplateDialogComponent } from '../dialogs/node-template/create-from-template.dialog'; import { CreateFromTemplateDialogComponent } from '../dialogs/node-template/create-from-template.dialog';
import { Subject, from, of } from 'rxjs'; import { Subject, from, of } from 'rxjs';
import { Node, ResultNode, PathElement, SearchApi } from '@alfresco/js-api'; import { Node, ResultNode, PathElement, SearchApi } from '@alfresco/js-api';
import { AlfrescoApiService, TranslationService } from '@alfresco/adf-core'; import { AlfrescoApiService, TranslationService, NotificationService } from '@alfresco/adf-core';
import { switchMap, catchError } from 'rxjs/operators'; import { switchMap, catchError } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import { AppStore, SnackbarErrorAction } from '@alfresco/aca-shared/store';
import { ContentNodeSelectorComponent, ContentNodeSelectorComponentData, ShareDataRow, NodeAction } from '@alfresco/adf-content-services'; import { ContentNodeSelectorComponent, ContentNodeSelectorComponentData, ShareDataRow, NodeAction } from '@alfresco/adf-content-services';
export interface TemplateDialogConfig { export interface TemplateDialogConfig {
@@ -42,6 +40,11 @@ export interface TemplateDialogConfig {
providedIn: 'root' providedIn: 'root'
}) })
export class NodeTemplateService { export class NodeTemplateService {
private alfrescoApiService = inject(AlfrescoApiService);
private notificationService = inject(NotificationService);
private translation = inject(TranslationService);
private dialog = inject(MatDialog);
private currentTemplateConfig: TemplateDialogConfig = null; private currentTemplateConfig: TemplateDialogConfig = null;
private rootNode: ResultNode; private rootNode: ResultNode;
@@ -51,13 +54,6 @@ export class NodeTemplateService {
return this._searchApi; return this._searchApi;
} }
constructor(
private store: Store<AppStore>,
private alfrescoApiService: AlfrescoApiService,
private translation: TranslationService,
public dialog: MatDialog
) {}
selectTemplateDialog(config: TemplateDialogConfig): Subject<Node[]> { selectTemplateDialog(config: TemplateDialogConfig): Subject<Node[]> {
this.currentTemplateConfig = config; this.currentTemplateConfig = config;
@@ -105,7 +101,7 @@ export class NodeTemplateService {
.afterClosed(); .afterClosed();
}), }),
catchError((error) => { catchError((error) => {
this.store.dispatch(new SnackbarErrorAction('APP.MESSAGES.ERRORS.GENERIC')); this.notificationService.showError('APP.MESSAGES.ERRORS.GENERIC');
return of(error); return of(error);
}) })
) )
@@ -120,7 +116,7 @@ export class NodeTemplateService {
panelClass: 'aca-create-from-template-dialog', panelClass: 'aca-create-from-template-dialog',
width: '630px' width: '630px'
}); });
dialog.afterClosed().subscribe(() => NodeTemplateService.focusCreateMenuButton()); dialog.afterClosed().subscribe(() => this.focusCreateMenuButton());
return dialog; return dialog;
} }
@@ -145,7 +141,7 @@ export class NodeTemplateService {
private close() { private close() {
this.dialog.closeAll(); this.dialog.closeAll();
NodeTemplateService.focusCreateMenuButton(); this.focusCreateMenuButton();
} }
private title(selectionType: string) { private title(selectionType: string) {
@@ -165,7 +161,7 @@ export class NodeTemplateService {
return node.path.elements.filter((pathElement) => !this.rootNode.path.elements.some((rootPathElement) => pathElement.id === rootPathElement.id)); return node.path.elements.filter((pathElement) => !this.rootNode.path.elements.some((rootPathElement) => pathElement.id === rootPathElement.id));
} }
private static focusCreateMenuButton(): void { private focusCreateMenuButton(): void {
document.querySelector<HTMLElement>('app-toolbar-menu button[id="app.toolbar.create"]').focus(); document.querySelector<HTMLElement>('app-toolbar-menu button[id="app.toolbar.create"]').focus();
} }
} }

View File

@@ -30,19 +30,21 @@ import {
LibraryActionTypes, LibraryActionTypes,
NavigateLibraryAction, NavigateLibraryAction,
NavigateRouteAction, NavigateRouteAction,
SnackbarErrorAction,
UpdateLibraryAction, UpdateLibraryAction,
getAppSelection getAppSelection
} from '@alfresco/aca-shared/store'; } from '@alfresco/aca-shared/store';
import { Injectable } from '@angular/core'; import { inject, Injectable } from '@angular/core';
import { Actions, ofType, createEffect } from '@ngrx/effects'; import { Actions, ofType, createEffect } from '@ngrx/effects';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { map, mergeMap, take } from 'rxjs/operators'; import { map, mergeMap, take } from 'rxjs/operators';
import { ContentApiService } from '@alfresco/aca-shared'; import { ContentApiService } from '@alfresco/aca-shared';
import { ContentManagementService } from '../../services/content-management.service'; import { ContentManagementService } from '../../services/content-management.service';
import { NotificationService } from '@alfresco/adf-core';
@Injectable() @Injectable()
export class LibraryEffects { export class LibraryEffects {
private notificationService = inject(NotificationService);
constructor( constructor(
private store: Store<AppStore>, private store: Store<AppStore>,
private actions$: Actions, private actions$: Actions,
@@ -120,7 +122,7 @@ export class LibraryEffects {
this.store.dispatch(new NavigateRouteAction([route, id])); 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 { TemplateEffects } from './template.effects';
import { EffectsModule } from '@ngrx/effects'; import { EffectsModule } from '@ngrx/effects';
import { Store } from '@ngrx/store'; 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 { NodeTemplateService } from '../../services/node-template.service';
import { of, Subject } from 'rxjs'; import { of, Subject } from 'rxjs';
import { Node, NodeEntry } from '@alfresco/js-api'; import { Node, NodeEntry } from '@alfresco/js-api';
import { MatDialog, MatDialogRef } from '@angular/material/dialog'; import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { CreateFromTemplateDialogComponent } from '../../dialogs/node-template/create-from-template.dialog'; import { CreateFromTemplateDialogComponent } from '../../dialogs/node-template/create-from-template.dialog';
import { AppHookService } from '@alfresco/aca-shared'; import { AppHookService } from '@alfresco/aca-shared';
import { NotificationService } from '@alfresco/adf-core';
import { MatSnackBarModule } from '@angular/material/snack-bar';
describe('TemplateEffects', () => { describe('TemplateEffects', () => {
let store: Store<any>; let store: Store<any>;
@@ -43,6 +45,8 @@ describe('TemplateEffects', () => {
let copyNodeSpy; let copyNodeSpy;
let updateNodeSpy; let updateNodeSpy;
let matDialog: MatDialog; let matDialog: MatDialog;
let showErrorSpy;
const node: Node = { const node: Node = {
name: 'node-name', name: 'node-name',
id: 'node-id', id: 'node-id',
@@ -72,7 +76,7 @@ describe('TemplateEffects', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [AppTestingModule, EffectsModule.forRoot([TemplateEffects])], imports: [AppTestingModule, EffectsModule.forRoot([TemplateEffects]), MatSnackBarModule],
providers: [ providers: [
NodeTemplateService, NodeTemplateService,
{ {
@@ -91,13 +95,16 @@ describe('TemplateEffects', () => {
matDialog = TestBed.inject(MatDialog); matDialog = TestBed.inject(MatDialog);
subject = new Subject<Node[]>(); subject = new Subject<Node[]>();
const notificationService = TestBed.inject(NotificationService);
showErrorSpy = spyOn(notificationService, 'showError');
spyOn(store, 'dispatch').and.callThrough(); spyOn(store, 'dispatch').and.callThrough();
spyOn(appHookService.reload, 'next'); spyOn(appHookService.reload, 'next');
spyOn(store, 'select').and.returnValue(of({ id: 'parent-id' })); spyOn(store, 'select').and.returnValue(of({ id: 'parent-id' }));
spyOn(nodeTemplateService, 'selectTemplateDialog').and.returnValue(subject); spyOn(nodeTemplateService, 'selectTemplateDialog').and.returnValue(subject);
copyNodeSpy = spyOn(templateEffects['nodesApi'], 'copyNode'); copyNodeSpy = spyOn(templateEffects.nodesApi, 'copyNode');
updateNodeSpy = spyOn(templateEffects['nodesApi'], 'updateNode'); updateNodeSpy = spyOn(templateEffects.nodesApi, 'updateNode');
}); });
afterEach(() => { afterEach(() => {
@@ -162,7 +169,7 @@ describe('TemplateEffects', () => {
tick(); tick();
expect(store.dispatch['calls'].mostRecent().args[0]).not.toEqual(new CreateFromTemplateSuccess(node)); 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(() => { it('should raise name conflict error when copyNode api returns 409', fakeAsync(() => {
@@ -172,7 +179,7 @@ describe('TemplateEffects', () => {
tick(); tick();
expect(store.dispatch['calls'].mostRecent().args[0]).not.toEqual(new CreateFromTemplateSuccess(node)); 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(() => { 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 { 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 { map, switchMap, debounceTime, take, catchError } from 'rxjs/operators';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { import {
@@ -33,11 +33,10 @@ import {
CreateFromTemplateSuccess, CreateFromTemplateSuccess,
TemplateActionTypes, TemplateActionTypes,
getCurrentFolder, getCurrentFolder,
AppStore, AppStore
SnackbarErrorAction
} from '@alfresco/aca-shared/store'; } from '@alfresco/aca-shared/store';
import { NodeTemplateService, TemplateDialogConfig } from '../../services/node-template.service'; 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 { AppHookService } from '@alfresco/aca-shared';
import { from, Observable, of } from 'rxjs'; import { from, Observable, of } from 'rxjs';
import { NodeEntry, NodeBodyUpdate, Node, NodesApi } from '@alfresco/js-api'; import { NodeEntry, NodeBodyUpdate, Node, NodesApi } from '@alfresco/js-api';
@@ -45,6 +44,8 @@ import { MatDialog } from '@angular/material/dialog';
@Injectable() @Injectable()
export class TemplateEffects { export class TemplateEffects {
private notificationService = inject(NotificationService);
private _nodesApi: NodesApi; private _nodesApi: NodesApi;
get nodesApi(): NodesApi { get nodesApi(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance()); this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance());
@@ -161,9 +162,9 @@ export class TemplateEffects {
} }
if (statusCode !== 409) { if (statusCode !== 409) {
this.store.dispatch(new SnackbarErrorAction('APP.MESSAGES.ERRORS.GENERIC')); this.notificationService.showError('APP.MESSAGES.ERRORS.GENERIC');
} else { } else {
this.store.dispatch(new SnackbarErrorAction('APP.MESSAGES.ERRORS.CONFLICT')); this.notificationService.showError('APP.MESSAGES.ERRORS.CONFLICT');
} }
return of(null); return of(null);

View File

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

View File

@@ -22,21 +22,21 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>. * from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/ */
import { Injectable } from '@angular/core'; import { inject, Injectable } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { Actions, ofType, createEffect } from '@ngrx/effects'; import { Actions, ofType, createEffect } from '@ngrx/effects';
import { Node, PathInfo } from '@alfresco/js-api'; import { Node, PathInfo } from '@alfresco/js-api';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import { AppStore } from '../states/app.state';
import { Location } from '@angular/common'; import { Location } from '@angular/common';
import { NavigateUrlAction, NavigateRouteAction, NavigateToFolder, NavigateToParentFolder, NavigateToPreviousPage } from '../actions/router.actions'; import { NavigateUrlAction, NavigateRouteAction, NavigateToFolder, NavigateToParentFolder, NavigateToPreviousPage } from '../actions/router.actions';
import { SnackbarErrorAction } from '../actions/snackbar.actions';
import { RouterActionTypes } from '../actions/router-action-types'; import { RouterActionTypes } from '../actions/router-action-types';
import { NotificationService } from '@alfresco/adf-core';
@Injectable() @Injectable()
export class RouterEffects { export class RouterEffects {
constructor(private store: Store<AppStore>, private actions$: Actions, private router: Router, private location: Location) {} private notificationService = inject(NotificationService);
constructor(private actions$: Actions, private router: Router, private location: Location) {}
navigateUrl$ = createEffect( navigateUrl$ = createEffect(
() => () =>
@@ -143,7 +143,7 @@ export class RouterEffects {
this.router.navigate(link); this.router.navigate(link);
}, 10); }, 10);
} else { } else {
this.store.dispatch(new SnackbarErrorAction('APP.MESSAGES.ERRORS.CANNOT_NAVIGATE_LOCATION')); this.notificationService.showError('APP.MESSAGES.ERRORS.CANNOT_NAVIGATE_LOCATION');
} }
} }