ACS-8572: Switch to using ADF document list reload (#4021)

This commit is contained in:
Denys Vuika
2024-08-12 08:37:18 -04:00
committed by GitHub
parent 73f47b7d79
commit 435ea6e358
14 changed files with 72 additions and 87 deletions

View File

@@ -22,14 +22,14 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/
import { Component, ViewEncapsulation, OnInit, Input } from '@angular/core';
import { Component, ViewEncapsulation, OnInit, Input, inject } from '@angular/core';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs';
import { SelectionState } from '@alfresco/adf-extensions';
import { AppStore, ReloadDocumentListAction, getAppSelection } from '@alfresco/aca-shared/store';
import { AppStore, getAppSelection } from '@alfresco/aca-shared/store';
import { Router } from '@angular/router';
import { CommonModule } from '@angular/common';
import { NodeFavoriteDirective } from '@alfresco/adf-content-services';
import { DocumentListService, NodeFavoriteDirective } from '@alfresco/adf-content-services';
import { MatIconModule } from '@angular/material/icon';
import { TranslateModule } from '@ngx-translate/core';
import { MatMenuModule } from '@angular/material/menu';
@@ -49,6 +49,8 @@ import { MatMenuModule } from '@angular/material/menu';
host: { class: 'app-toggle-favorite' }
})
export class ToggleFavoriteComponent implements OnInit {
private documentListService = inject(DocumentListService);
@Input() data: any;
selection$: Observable<SelectionState>;
private reloadOnRoutes: string[] = [];
@@ -65,7 +67,7 @@ export class ToggleFavoriteComponent implements OnInit {
onToggleEvent() {
if (this.reloadOnRoutes.includes(this.router.url)) {
this.store.dispatch(new ReloadDocumentListAction());
this.documentListService.reload();
}
}
}

View File

@@ -54,9 +54,9 @@ describe('DocumentListDirective', () => {
url: ''
};
const appHookServiceMock: any = {
reload: new Subject<any>(),
reset: new Subject<any>()
const documentListServiceMock = {
reload$: new Subject<any>(),
resetSelection$: new Subject<any>()
};
const mockRoute: any = {
@@ -80,7 +80,7 @@ describe('DocumentListDirective', () => {
userPreferencesServiceMock,
mockRoute,
mockRouter,
appHookServiceMock
documentListServiceMock as any
);
});
@@ -139,26 +139,17 @@ describe('DocumentListDirective', () => {
expect(storeMock.dispatch).toHaveBeenCalled();
});
it('should reset and reload document list on `reload` event', () => {
documentListDirective.ngOnInit();
appHookServiceMock.reload.next();
expect(documentListMock.resetSelection).toHaveBeenCalled();
expect(documentListMock.reload).toHaveBeenCalled();
});
it('should reset store selection on `reload` event', () => {
documentListDirective.ngOnInit();
appHookServiceMock.reload.next();
documentListServiceMock.reload$.next();
expect(storeMock.dispatch).toHaveBeenCalledWith(new SetSelectedNodesAction([]));
});
it('should reset selection state on `reset` event', () => {
documentListDirective.ngOnInit();
appHookServiceMock.reset.next();
documentListServiceMock.resetSelection$.next();
expect(documentListMock.resetSelection).toHaveBeenCalled();
expect(storeMock.dispatch).toHaveBeenCalledWith(new SetSelectedNodesAction([]));
expect(documentListDirective.selectedNode).toBeNull();
});

View File

@@ -23,12 +23,11 @@
*/
import { Directive, OnDestroy, OnInit, HostListener } from '@angular/core';
import { DocumentListComponent } from '@alfresco/adf-content-services';
import { DocumentListComponent, DocumentListService } from '@alfresco/adf-content-services';
import { ActivatedRoute, Router } from '@angular/router';
import { UserPreferencesService } from '@alfresco/adf-core';
import { Subject } from 'rxjs';
import { Store } from '@ngrx/store';
import { AppHookService } from '@alfresco/aca-shared';
import { SetSelectedNodesAction } from '@alfresco/aca-shared/store';
import { takeUntil, filter } from 'rxjs/operators';
import { NodeEntry } from '@alfresco/js-api';
@@ -53,7 +52,7 @@ export class DocumentListDirective implements OnInit, OnDestroy {
private preferences: UserPreferencesService,
private route: ActivatedRoute,
private router: Router,
private appHookService: AppHookService
private documentListService: DocumentListService
) {}
ngOnInit() {
@@ -92,11 +91,11 @@ export class DocumentListDirective implements OnInit, OnDestroy {
)
.subscribe(() => this.onReady());
this.appHookService.reload.pipe(takeUntil(this.onDestroy$)).subscribe(() => {
this.documentListService.reload$.pipe(takeUntil(this.onDestroy$)).subscribe(() => {
this.reload();
});
this.appHookService.reset.pipe(takeUntil(this.onDestroy$)).subscribe(() => {
this.documentListService.resetSelection$.pipe(takeUntil(this.onDestroy$)).subscribe(() => {
this.reset();
});
}
@@ -167,14 +166,11 @@ export class DocumentListDirective implements OnInit, OnDestroy {
}
private reload() {
this.documentList.resetSelection();
this.store.dispatch(new SetSelectedNodesAction([]));
this.documentList.reload();
}
private reset() {
this.selectedNode = null;
this.documentList.resetSelection();
this.store.dispatch(new SetSelectedNodesAction([]));
}

View File

@@ -1582,7 +1582,7 @@ describe('ContentManagementService', () => {
expect(spyOnDispatch).toHaveBeenCalledOnceWith(new RefreshPreviewAction(fakeNodeIsFile));
});
it('should dispatch ReloadDocumentListAction if dialog emit view action', () => {
it('should dispatch ViewNodeVersionAction if dialog emit view action', () => {
const fakeVersionId = '1';
const fakeLocation: ViewNodeExtras = {
location: '/'

View File

@@ -32,7 +32,6 @@ import {
NavigateToParentFolder,
NodeInfo,
RefreshPreviewAction,
ReloadDocumentListAction,
SetSelectedNodesAction,
ShowLoaderAction,
SnackbarAction,
@@ -45,6 +44,7 @@ import {
ViewNodeVersionAction
} from '@alfresco/aca-shared/store';
import {
DocumentListService,
FolderDialogComponent,
LibraryDialogComponent,
NewVersionUploaderData,
@@ -90,7 +90,8 @@ export class ContentManagementService {
private appHookService: AppHookService,
private newVersionUploaderService: NewVersionUploaderService,
private router: Router,
private appSettingsService: AppSettingsService
private appSettingsService: AppSettingsService,
private documentListService: DocumentListService
) {}
addFavorite(nodes: Array<NodeEntry>) {
@@ -226,7 +227,7 @@ export class ContentManagementService {
dialogInstance.afterClosed().subscribe((node) => {
if (node) {
this.store.dispatch(new ReloadDocumentListAction());
this.documentListService.reload();
}
this.focusAfterClose(this.createMenuButtonSelector);
});
@@ -390,7 +391,7 @@ export class ContentManagementService {
const failedStatus = this.processStatus([]);
failedStatus.fail.push(...selection);
this.showRestoreNotification(failedStatus);
this.store.dispatch(new ReloadDocumentListAction());
this.documentListService.reload();
return;
}
@@ -409,7 +410,7 @@ export class ContentManagementService {
if (!remainingNodes.length) {
this.showRestoreNotification(status);
this.store.dispatch(new ReloadDocumentListAction());
this.documentListService.reload();
} else {
this.restoreDeletedNodes(remainingNodes);
}
@@ -436,7 +437,7 @@ export class ContentManagementService {
const [operationResult, moveResponse] = result;
this.showMoveMessage(nodes, operationResult, moveResponse);
this.store.dispatch(new ReloadDocumentListAction());
this.documentListService.reload();
},
(error) => {
this.showMoveMessage(nodes, error);
@@ -542,7 +543,7 @@ export class ContentManagementService {
forkJoin(...batch).subscribe(
() => {
this.appHookService.nodesDeleted.next(null);
this.store.dispatch(new ReloadDocumentListAction());
this.documentListService.reload();
},
(error) => {
let i18nMessageString = 'APP.MESSAGES.ERRORS.GENERIC';
@@ -632,7 +633,7 @@ export class ContentManagementService {
)
.subscribe(
() => {
this.store.dispatch(new ReloadDocumentListAction());
this.documentListService.reload();
},
(error) => {
let message = 'APP.MESSAGES.ERRORS.GENERIC';
@@ -670,7 +671,7 @@ export class ContentManagementService {
if (status.someSucceeded) {
this.appHookService.nodesDeleted.next();
this.store.dispatch(new ReloadDocumentListAction());
this.documentListService.reload();
}
this.store.dispatch(new ShowLoaderAction(false));
});
@@ -692,7 +693,7 @@ export class ContentManagementService {
}
if (processedData.someSucceeded) {
this.store.dispatch(new ReloadDocumentListAction());
this.documentListService.reload();
}
});
}
@@ -761,7 +762,7 @@ export class ContentManagementService {
const status = this.processStatus(purgedNodes);
if (status.success.length) {
this.store.dispatch(new ReloadDocumentListAction());
this.documentListService.reload();
}
this.sendPurgeMessage(status);

View File

@@ -26,18 +26,18 @@ import { Actions, ofType, createEffect } from '@ngrx/effects';
import { Injectable } from '@angular/core';
import { map } from 'rxjs/operators';
import { AppActionTypes, ReloadDocumentListAction, ResetSelectionAction } from '@alfresco/aca-shared/store';
import { AppHookService } from '@alfresco/aca-shared';
import { DocumentListService } from '@alfresco/adf-content-services';
@Injectable()
export class AppEffects {
constructor(private actions$: Actions, private appHookService: AppHookService) {}
constructor(private actions$: Actions, private documentListService: DocumentListService) {}
reload = createEffect(
() =>
this.actions$.pipe(
ofType<ReloadDocumentListAction>(AppActionTypes.ReloadDocumentList),
map((action) => {
this.appHookService.reload.next(action);
map(() => {
this.documentListService.reload();
})
),
{ dispatch: false }
@@ -47,8 +47,8 @@ export class AppEffects {
() =>
this.actions$.pipe(
ofType<ResetSelectionAction>(AppActionTypes.ResetSelection),
map((action) => {
this.appHookService.reset.next(action);
map(() => {
this.documentListService.resetSelection();
})
),
{ dispatch: false }

View File

@@ -33,14 +33,14 @@ 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';
import { DocumentListService } from '@alfresco/adf-content-services';
describe('TemplateEffects', () => {
let store: Store<any>;
let nodeTemplateService: NodeTemplateService;
let appHookService: AppHookService;
let documentListService: DocumentListService;
let templateEffects: TemplateEffects;
let copyNodeSpy;
let updateNodeSpy;
@@ -91,7 +91,7 @@ describe('TemplateEffects', () => {
store = TestBed.inject(Store);
nodeTemplateService = TestBed.inject(NodeTemplateService);
templateEffects = TestBed.inject(TemplateEffects);
appHookService = TestBed.inject(AppHookService);
documentListService = TestBed.inject(DocumentListService);
matDialog = TestBed.inject(MatDialog);
subject = new Subject<Node[]>();
@@ -99,7 +99,7 @@ describe('TemplateEffects', () => {
showErrorSpy = spyOn(notificationService, 'showError');
spyOn(store, 'dispatch').and.callThrough();
spyOn(appHookService.reload, 'next');
spyOn(documentListService, 'reload').and.stub();
spyOn(store, 'select').and.returnValue(of({ id: 'parent-id' }));
spyOn(nodeTemplateService, 'selectTemplateDialog').and.returnValue(subject);
@@ -212,6 +212,6 @@ describe('TemplateEffects', () => {
const TEST_NODE = { id: 'test-node-id' } as Node;
store.dispatch(new CreateFromTemplateSuccess(TEST_NODE));
tick();
expect(appHookService.reload.next).toHaveBeenCalledWith(TEST_NODE);
expect(documentListService.reload).toHaveBeenCalled();
}));
});

View File

@@ -37,14 +37,15 @@ import {
} from '@alfresco/aca-shared/store';
import { NodeTemplateService, TemplateDialogConfig } from '../../services/node-template.service';
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';
import { MatDialog } from '@angular/material/dialog';
import { DocumentListService } from '@alfresco/adf-content-services';
@Injectable()
export class TemplateEffects {
private notificationService = inject(NotificationService);
private documentListService = inject(DocumentListService);
private _nodesApi: NodesApi;
get nodesApi(): NodesApi {
@@ -54,7 +55,6 @@ export class TemplateEffects {
constructor(
private matDialog: MatDialog,
private appHookService: AppHookService,
private store: Store<AppStore>,
private apiService: AlfrescoApiService,
private actions$: Actions,
@@ -114,9 +114,9 @@ export class TemplateEffects {
() =>
this.actions$.pipe(
ofType<CreateFromTemplateSuccess>(TemplateActionTypes.CreateFromTemplateSuccess),
map((payload) => {
map(() => {
this.matDialog.closeAll();
this.appHookService.reload.next(payload.node);
this.documentListService.reload();
})
),
{ dispatch: false }