Skip to content

Commit 19918da

Browse files
committed
Merge remote-tracking branch '39694/fix-for-issue-39640' into commpr-10131-1706
2 parents 27ab0b7 + 9e58f2f commit 19918da

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* Copyright © Magento, Inc. All rights reserved.
3-
* See COPYING.txt for license details.
2+
* Copyright 2016 Adobe
3+
* All Rights Reserved.
44
*/
55

66
/**
@@ -689,14 +689,16 @@ define([
689689
* @param {Number|String} prop - additional property to element
690690
*/
691691
processingAddChild: function (ctx, index, prop) {
692+
var newTotal,
693+
newPages;
694+
692695
this.bubble('addChild', false);
693696

694-
if (this.relatedData.length && this.relatedData.length % this.pageSize === 0) {
695-
this.pages(this.pages() + 1);
696-
this.nextPage();
697-
} else if (~~this.currentPage() !== this.pages()) {
698-
this.currentPage(this.pages());
699-
}
697+
newTotal = this.relatedData.length + 1;
698+
newPages = Math.ceil(newTotal / this.pageSize);
699+
700+
this.pages(newPages);
701+
this.currentPage(newPages);
700702

701703
this.addChild(ctx, index, prop);
702704
},

dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/dynamic-rows/dynamic-rows.test.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* Copyright © Magento, Inc. All rights reserved.
3-
* See COPYING.txt for license details.
2+
* Copyright 2017 Adobe
3+
* All Rights Reserved.
44
*/
55

66
/* eslint-disable max-nested-callbacks */
@@ -204,5 +204,37 @@ define([
204204
expect(model.pages()).toEqual(2);
205205
expect(model.currentPage()).toEqual(2);
206206
});
207+
208+
it('should process pages before addChild', function () {
209+
var ctx = {},
210+
index = 5,
211+
prop = 'someProp';
212+
213+
model.pageSize = 2;
214+
model.relatedData = [
215+
{
216+
name: 'first'
217+
},
218+
{
219+
name: 'second'
220+
},
221+
{
222+
name: 'third'
223+
},
224+
{
225+
name: 'fourth'
226+
},
227+
{
228+
name: 'fifth'
229+
}
230+
];
231+
model.bubble = jasmine.createSpy();
232+
model.addChild = jasmine.createSpy();
233+
model.processingAddChild(ctx, index, prop);
234+
expect(model.bubble).toHaveBeenCalledWith('addChild', false);
235+
expect(model.pages()).toEqual(3);
236+
expect(model.currentPage()).toEqual(3);
237+
expect(model.addChild).toHaveBeenCalledWith(ctx, index, prop);
238+
});
207239
});
208240
});

0 commit comments

Comments
 (0)