Skip to content

Commit 1a00791

Browse files
committed
Merge remote-tracking branch 'origin/imported-magento-magento2-31492' into 2.4-develop-pr118
2 parents 7dcc880 + 14f3af2 commit 1a00791

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,15 +620,12 @@ define([
620620
* @param {Array} data
621621
*/
622622
parsePagesData: function (data) {
623-
var pages;
624-
625623
this.relatedData = this.deleteProperty ?
626624
_.filter(data, function (elem) {
627625
return elem && elem[this.deleteProperty] !== this.deleteValue;
628626
}, this) : data;
629627

630-
pages = Math.ceil(this.relatedData.length / this.pageSize) || 1;
631-
this.pages(pages);
628+
this._updatePagesQuantity();
632629
},
633630

634631
/**
@@ -885,6 +882,18 @@ define([
885882
this._sort();
886883
},
887884

885+
/**
886+
* Update number of pages.
887+
*
888+
* @private
889+
* @return void
890+
*/
891+
_updatePagesQuantity: function () {
892+
var pages = Math.ceil(this.relatedData.length / this.pageSize) || 1;
893+
894+
this.pages(pages);
895+
},
896+
888897
/**
889898
* Reduce the number of pages
890899
*
@@ -960,6 +969,7 @@ define([
960969
reload: function () {
961970
this.clear();
962971
this.initChildren(false, true);
972+
this._updatePagesQuantity();
963973

964974
/* After change page size need to check existing current page */
965975
this._reducePages();

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,5 +171,38 @@ define([
171171
};
172172
expect(JSON.stringify(model.labels())).toEqual(JSON.stringify(result));
173173
});
174+
175+
it('Check _updatePagesQuantity method call.', function () {
176+
model._updatePagesQuantity = jasmine.createSpy();
177+
178+
model.reload();
179+
180+
expect(model._updatePagesQuantity).toHaveBeenCalled();
181+
});
182+
183+
it('Check number of pages is updated after reloading dynamic-rows.', function () {
184+
model.pageSize = 1;
185+
model.relatedData = [
186+
{
187+
name: 'first'
188+
},
189+
{
190+
name: 'second'
191+
},
192+
{
193+
name: 'third'
194+
}
195+
];
196+
197+
model.reload();
198+
expect(model.pages()).toEqual(3);
199+
200+
model.currentPage(3);
201+
model.pageSize = 2;
202+
203+
model.reload();
204+
expect(model.pages()).toEqual(2);
205+
expect(model.currentPage()).toEqual(2);
206+
});
174207
});
175208
});

0 commit comments

Comments
 (0)