From 766bb082f5ff242b486ac406a2f71de0448a32f8 Mon Sep 17 00:00:00 2001 From: Vito Date: Tue, 13 Mar 2018 17:28:25 +0000 Subject: [PATCH] [ADF-2393] fixed reloading on delete with infinite scrolling (#3057) * [ADF-2393] fixed reloading on delete with infinite scrolling * [ADF-2393] refactored after PR --- .../src/app/components/files/files.component.ts | 11 ++++++++++- .../services/document-actions.service.spec.ts | 13 ------------- .../services/document-actions.service.ts | 8 +------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/demo-shell/src/app/components/files/files.component.ts b/demo-shell/src/app/components/files/files.component.ts index f7ebf5b68a..9b5e99ea5b 100644 --- a/demo-shell/src/app/components/files/files.component.ts +++ b/demo-shell/src/app/components/files/files.component.ts @@ -295,7 +295,7 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy { } emitReadyEvent(event: any) { - if (this.pageIsEmpty(event)) { + if (this.standardPagination && this.pageIsEmpty(event)) { this.standardPagination.goPrevious(); } else { this.documentListReady.emit(event); @@ -328,11 +328,20 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy { onContentActionSuccess(message) { const translatedMessage: any = this.translateService.get(message); this.notificationService.openSnackMessage(translatedMessage.value, 4000); + this.reloadForInfiniteScrolling(); } onDeleteActionSuccess(message) { this.uploadService.fileDeleted.next(message); this.deleteElementSuccess.emit(); + this.reloadForInfiniteScrolling(); + } + + private reloadForInfiniteScrolling() { + if (this.infiniteScrolling) { + this.documentList.skipCount = 0; + this.documentList.reload(); + } } onManageVersions(event) { diff --git a/lib/content-services/document-list/services/document-actions.service.spec.ts b/lib/content-services/document-list/services/document-actions.service.spec.ts index 7641cab82a..bb3aec951c 100644 --- a/lib/content-services/document-list/services/document-actions.service.spec.ts +++ b/lib/content-services/document-list/services/document-actions.service.spec.ts @@ -204,19 +204,6 @@ describe('DocumentActionsService', () => { expect(documentListService.deleteNode).not.toHaveBeenCalled(); }); - it('should reload target upon node deletion', () => { - spyOn(documentListService, 'deleteNode').and.returnValue(Observable.of(true)); - - let target = jasmine.createSpyObj('obj', ['reload']); - let permission = 'delete'; - let file: any = new FileNode(); - file.entry.allowableOperations = ['delete']; - service.getHandler('delete')(file, target, permission); - - expect(documentListService.deleteNode).toHaveBeenCalled(); - expect(target.reload).toHaveBeenCalled(); - }); - it('should emit success event upon node deletion', (done) => { service.success.subscribe((nodeId) => { expect(nodeId).not.toBeNull(); diff --git a/lib/content-services/document-list/services/document-actions.service.ts b/lib/content-services/document-list/services/document-actions.service.ts index 21810c589d..838c8e5241 100644 --- a/lib/content-services/document-list/services/document-actions.service.ts +++ b/lib/content-services/document-list/services/document-actions.service.ts @@ -101,10 +101,7 @@ export class DocumentActionsService { private prepareHandlers(actionObservable, type: string, action: string, target?: any, permission?: string): void { actionObservable.subscribe( (fileOperationMessage) => { - if (target && typeof target.reload === 'function') { - target.reload(); - } - this.success.next(fileOperationMessage); + this.success.next(fileOperationMessage); }, this.error.next.bind(this.error) ); @@ -117,9 +114,6 @@ export class DocumentActionsService { if (this.contentService.hasPermission(node.entry, permission)) { handlerObservable = this.documentListService.deleteNode(node.entry.id); handlerObservable.subscribe(() => { - if (target && typeof target.reload === 'function') { - target.reload(); - } this.success.next(node.entry.id); }); return handlerObservable;