Skip to content

Commit 3661bc3

Browse files
author
Sergii Kovalenko
committed
MAGETWO-63321: Issue when deleting item from Product options grid containing more than 20 options
1 parent 95d8de6 commit 3661bc3

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ define([
156156
dnd: '${ $.dndConfig.name }'
157157
},
158158
pages: 1,
159-
pageSize: 20,
159+
pageSize: 2,
160160
relatedData: [],
161161
currentPage: 1,
162162
recordDataCache: [],
@@ -269,10 +269,12 @@ define([
269269
* @param {Number|String} id
270270
*/
271271
deleteHandler: function (index, id) {
272+
var defaultState;
272273
this.setDefaultState();
274+
defaultState = this.defaultPagesState[this.currentPage()];
273275
this.processingDeleteRecord(index, id);
274276
this.pagesChanged[this.currentPage()] =
275-
!compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems()));
277+
!compareArrays(defaultState, this.arrayFilter(this.getChildItems()));
276278
this.changed(_.some(this.pagesChanged));
277279
},
278280

@@ -326,7 +328,7 @@ define([
326328
},
327329

328330
/**
329-
* Set default dynamic-rows state
331+
* Set default dynamic-rows state or state before changing data
330332
*
331333
* @param {Array} data - defaultState data
332334
*/
@@ -700,11 +702,6 @@ define([
700702
*/
701703
processingDeleteRecord: function (index, recordId) {
702704
this.deleteRecord(index, recordId);
703-
704-
if (this.getChildItems().length <= 0 && this.pages() !== 1) {
705-
this.pages(this.pages() - 1);
706-
this.currentPage(this.pages());
707-
}
708705
},
709706

710707
/**
@@ -874,11 +871,14 @@ define([
874871
this.update = false;
875872
}
876873

874+
this._reducePages();
875+
this._sort();
876+
},
877+
878+
_reducePages: function() {
877879
if (this.pages() < ~~this.currentPage()) {
878880
this.currentPage(this.pages());
879881
}
880-
881-
this._sort();
882882
},
883883

884884
/**

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ define([
99
], function (DynamicRows) {
1010
'use strict';
1111

12-
var model;
12+
var model,
13+
ElementMock = function (index) {
14+
return {
15+
destroy: function () {},
16+
index: index
17+
};
18+
};
1319

1420
beforeEach(function(done) {
1521
model = new DynamicRows({});
@@ -53,11 +59,14 @@ define([
5359
});
5460

5561
it ('deleteRecord with Delete Property', function () {
56-
var elems, recordInstanceMock;
62+
var elems,
63+
recordInstanceMock = new ElementMock(1),
64+
elem2 = new ElementMock(2);
5765

66+
spyOn(recordInstanceMock, "destroy").toHaveBeenCalled();
5867
elems = [
59-
{index: 1, label: "a"},
60-
{index: 2, label: "b"}
68+
recordInstanceMock,
69+
elem2
6170
];
6271
model.elems(elems);
6372
model.deleteProperty = true;

0 commit comments

Comments
 (0)