Skip to content

Commit aa44cf0

Browse files
author
Stanislav Idolov
authored
ENGCOM-2774: [Forwardport] Refactor: remove some code duplication #17571
2 parents c1dd5a9 + ce9993c commit aa44cf0

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

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

+20-12
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,7 @@ define([
330330
}
331331

332332
if (this.defaultPagesState[this.currentPage()]) {
333-
this.pagesChanged[this.currentPage()] =
334-
!compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems()));
335-
this.changed(_.some(this.pagesChanged));
333+
this.setChangedForCurrentPage();
336334
}
337335
},
338336

@@ -442,13 +440,9 @@ define([
442440
return initialize;
443441
}));
444442

445-
this.pagesChanged[this.currentPage()] =
446-
!compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems()));
447-
this.changed(_.some(this.pagesChanged));
443+
this.setChangedForCurrentPage();
448444
} else if (this.hasInitialPagesState[this.currentPage()]) {
449-
this.pagesChanged[this.currentPage()] =
450-
!compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems()));
451-
this.changed(_.some(this.pagesChanged));
445+
this.setChangedForCurrentPage();
452446
}
453447
},
454448

@@ -848,7 +842,8 @@ define([
848842
deleteRecord: function (index, recordId) {
849843
var recordInstance,
850844
lastRecord,
851-
recordsData;
845+
recordsData,
846+
lastRecordIndex;
852847

853848
if (this.deleteProperty) {
854849
recordsData = this.recordData();
@@ -867,12 +862,13 @@ define([
867862
this.update = true;
868863

869864
if (~~this.currentPage() === this.pages()) {
865+
lastRecordIndex = (this.startIndex + this.getChildItems().length - 1);
870866
lastRecord =
871867
_.findWhere(this.elems(), {
872-
index: this.startIndex + this.getChildItems().length - 1
868+
index: lastRecordIndex
873869
}) ||
874870
_.findWhere(this.elems(), {
875-
index: (this.startIndex + this.getChildItems().length - 1).toString()
871+
index: lastRecordIndex.toString()
876872
});
877873

878874
lastRecord.destroy();
@@ -1133,6 +1129,18 @@ define([
11331129
});
11341130

11351131
this.isDifferedFromDefault(!_.isEqual(recordData, this.default));
1132+
},
1133+
1134+
/**
1135+
* Set the changed property if the current page is different
1136+
* than the default state
1137+
*
1138+
* @return void
1139+
*/
1140+
setChangedForCurrentPage: function () {
1141+
this.pagesChanged[this.currentPage()] =
1142+
!compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems()));
1143+
this.changed(_.some(this.pagesChanged));
11361144
}
11371145
});
11381146
});

0 commit comments

Comments
 (0)