Skip to content

Commit 632d8fb

Browse files
committed
MAGETWO-53852: Event update works incorrectly
1 parent 0548f22 commit 632d8fb

File tree

2 files changed

+42
-21
lines changed

2 files changed

+42
-21
lines changed

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

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ define([
160160
startIndex: 0
161161
},
162162

163+
/**
164+
* Sets record data to cache
165+
*/
163166
setRecordDataToCache: function (data) {
164167
this.recordDataCache = this.recordDataCache && data.length > this.recordDataCache.length ?
165168
data : this.recordDataCache;
@@ -177,7 +180,9 @@ define([
177180
'processingDeleteRecord',
178181
'onChildrenUpdate',
179182
'checkDefaultState',
180-
'renderColumnsHeader'
183+
'renderColumnsHeader',
184+
'deleteHandler',
185+
'setDefaultState'
181186
);
182187

183188
this._super()
@@ -247,15 +252,9 @@ define([
247252
initElement: function (elem) {
248253
this._super();
249254
elem.on({
250-
'deleteRecord': function (index, id) {
251-
this.deleteHandler(index, id);
252-
}.bind(this),
253-
'update': function (state) {
254-
this.onChildrenUpdate(state);
255-
}.bind(this),
256-
'addChild': function () {
257-
this.setDefaultState();
258-
}.bind(this)
255+
'deleteRecord': this.deleteHandler,
256+
'update': this.onChildrenUpdate,
257+
'addChild': this.setDefaultState
259258
});
260259

261260
return this;
@@ -270,7 +269,8 @@ define([
270269
deleteHandler: function (index, id) {
271270
this.setDefaultState();
272271
this.processingDeleteRecord(index, id);
273-
this.pagesChanged[this.currentPage()] = !compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems()));
272+
this.pagesChanged[this.currentPage()] =
273+
!compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems()));
274274
this.changed(_.some(this.pagesChanged));
275275
},
276276

@@ -307,19 +307,20 @@ define([
307307
changed.forEach(function (elem) {
308308
changedElemDataScope = elem.dataScope.split('.');
309309
changedElemDataScope.splice(0, dataScope.length);
310-
changedElemDataScope[0] = (parseInt(changedElemDataScope[0], 10) - this.pageSize * (this.currentPage() - 1)).toString();
311-
this.setValueByPath(this.defaultPagesState[this.currentPage()], changedElemDataScope, elem.initialValue);
310+
changedElemDataScope[0] =
311+
(parseInt(changedElemDataScope[0], 10) - this.pageSize * (this.currentPage() - 1)).toString();
312+
this.setValueByPath(
313+
this.defaultPagesState[this.currentPage()],
314+
changedElemDataScope, elem.initialValue
315+
);
312316
}, this);
313317
}
314318

315-
this.pagesChanged[this.currentPage()] = !compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems()));
319+
this.pagesChanged[this.currentPage()] =
320+
!compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems()));
316321
this.changed(_.some(this.pagesChanged));
317322
},
318323

319-
compare: function (a1,a2) {
320-
return compareArrays(a1,a2)
321-
},
322-
323324
/**
324325
* Set default dynamic-rows state
325326
*
@@ -426,10 +427,12 @@ define([
426427
return initialize;
427428
}));
428429

429-
this.pagesChanged[this.currentPage()] = !compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems()));
430+
this.pagesChanged[this.currentPage()] =
431+
!compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems()));
430432
this.changed(_.some(this.pagesChanged));
431433
} else if (this.hasInitialPagesState[this.currentPage()]) {
432-
this.pagesChanged[this.currentPage()] = !compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems()));
434+
this.pagesChanged[this.currentPage()] =
435+
!compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems()));
433436
this.changed(_.some(this.pagesChanged));
434437
}
435438
},
@@ -438,6 +441,7 @@ define([
438441
* Filters out deleted items from array
439442
*
440443
* @param {Array} data
444+
*
441445
* @returns {Array} filtered array
442446
*/
443447
arrayFilter: function (data) {

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,31 @@ define([
3535
}
3636
},
3737

38+
/**
39+
* Extends instance with default config, calls initialize of parent
40+
* class, calls initChildren method, set observe variable.
41+
* Use parent "track" method - wrapper observe array
42+
*
43+
* @returns {Object} Chainable.
44+
*/
3845
initialize: function () {
3946
var self = this;
4047

4148
this._super();
4249

43-
registry.async(this.name + '.' + this.positionProvider)(function(component){
50+
registry.async(this.name + '.' + this.positionProvider)(function (component) {
51+
52+
/**
53+
* Overwrite hasChanged method
54+
*
55+
* @returns {Boolean}
56+
*/
4457
component.hasChanged = function () {
58+
59+
/* eslint-disable eqeqeq */
4560
return this.value().toString() != this.initialValue.toString();
61+
62+
/* eslint-enable eqeqeq */
4663
};
4764

4865
if (!component.initialValue) {

0 commit comments

Comments
 (0)