From d731cc651cccfebc6eba053da6ea308db5740b31 Mon Sep 17 00:00:00 2001 From: suzanadirla Date: Tue, 20 Feb 2018 15:59:12 +0200 Subject: [PATCH] [ADF-2175] Document List requests are executed twice when opening the copy and move dialog (#2960) * [ADF-2175] Document List requests are executed twice when opening the dialog fixed bug * [ADF-2175] added unit tests for the change & refactored initial code --- .../components/document-list.component.spec.ts | 18 ++++++++++++++++++ .../components/document-list.component.ts | 2 ++ 2 files changed, 20 insertions(+) diff --git a/lib/content-services/document-list/components/document-list.component.spec.ts b/lib/content-services/document-list/components/document-list.component.spec.ts index d8bc919a73..888f02d572 100644 --- a/lib/content-services/document-list/components/document-list.component.spec.ts +++ b/lib/content-services/document-list/components/document-list.component.spec.ts @@ -1204,4 +1204,22 @@ describe('DocumentList', () => { expect(documentList.reload).not.toHaveBeenCalled(); }); + + it('should NOT reload data on first call of onNgChanges', () => { + spyOn(documentList, 'reload').and.stub(); + + const firstChange = true; + documentList.ngOnChanges({ skipCount: new SimpleChange(undefined, 10, firstChange) }); + + expect(documentList.reload).not.toHaveBeenCalled(); + }); + + it('should reload data on NON-first calls of onNgChanges', () => { + spyOn(documentList, 'reload').and.stub(); + + const firstChange = true; + documentList.ngOnChanges({ skipCount: new SimpleChange(undefined, 10, !firstChange) }); + + expect(documentList.reload).toHaveBeenCalled(); + }); }); diff --git a/lib/content-services/document-list/components/document-list.component.ts b/lib/content-services/document-list/components/document-list.component.ts index 9c9d00bffe..141706bf42 100644 --- a/lib/content-services/document-list/components/document-list.component.ts +++ b/lib/content-services/document-list/components/document-list.component.ts @@ -567,6 +567,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte private isSkipCountChanged(changePage: SimpleChanges) { return changePage.skipCount && + !changePage.skipCount.isFirstChange() && changePage.skipCount.currentValue !== null && changePage.skipCount.currentValue !== undefined && changePage.skipCount.currentValue !== changePage.skipCount.previousValue; @@ -574,6 +575,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte private isMaxItemsChanged(changePage: SimpleChanges) { return changePage.maxItems && + !changePage.maxItems.isFirstChange() && changePage.maxItems.currentValue && changePage.maxItems.currentValue !== changePage.maxItems.previousValue; }