Skip to content

Commit be9f29c

Browse files
committed
Merge branch 'ACP2E-3076' of https://github.com/adobe-commerce-tier-4/magento2ce into PR-VK-2024-06-10-CE
2 parents 89adeba + 0ca06dc commit be9f29c

File tree

3 files changed

+56
-14
lines changed

3 files changed

+56
-14
lines changed

app/code/Magento/Bundle/view/adminhtml/web/js/components/bundle-dynamic-rows.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,19 @@ define([
7171
* @param {Number|String} index - element index
7272
*/
7373
removeBundleItemsFromOption: function (index) {
74-
var bundleSelections = registry.get(this.name + '.' + index + '.' + this.bundleSelectionsName),
75-
bundleSelectionsLength = (bundleSelections.elems() || []).length,
76-
i;
74+
let bundleSelections = registry.get(this.name + '.' + index + '.' + this.bundleSelectionsName);
7775

78-
if (bundleSelectionsLength) {
79-
for (i = 0; i < bundleSelectionsLength; i++) {
80-
bundleSelections.elems()[0].destroy();
81-
}
82-
}
76+
bundleSelections.destroyChildren();
8377
},
8478

8579
/**
8680
* {@inheritdoc}
8781
*/
8882
processingAddChild: function (ctx, index, prop) {
8983
var recordIds = _.map(this.recordData(), function (rec) {
90-
return parseInt(rec['record_id'], 10);
91-
}),
92-
maxRecordId = _.max(recordIds);
84+
return parseInt(rec['record_id'], 10);
85+
}),
86+
maxRecordId = _.max(recordIds);
9387

9488
prop = maxRecordId > -1 ? maxRecordId + 1 : prop;
9589
this._super(ctx, index, prop);

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,8 @@ define([
584584
updatedCollection;
585585

586586
if (this.elems().filter(function (el) {
587-
return el.position || el.position === 0;
588-
}).length !== this.getChildItems().length) {
587+
return el.position || el.position === 0;
588+
}).length !== this.getChildItems().length) {
589589

590590
return false;
591591
}
@@ -655,7 +655,10 @@ define([
655655

656656
startIndex = page || this.startIndex;
657657

658-
return dataRecord.slice(startIndex, this.startIndex + parseInt(this.pageSize, 10));
658+
if (dataRecord.length) {
659+
return dataRecord.slice(startIndex, this.startIndex + parseInt(this.pageSize, 10));
660+
}
661+
return [];
659662
},
660663

661664
/**
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/************************************************************************
2+
*
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*
6+
* ************************************************************************
7+
*/
8+
9+
/*eslint max-nested-callbacks: 0*/
10+
define(['Magento_Bundle/js/components/bundle-dynamic-rows', 'uiRegistry', 'uiCollection'],
11+
function (BundleDynamicRows, registry, uiCollection) {
12+
'use strict';
13+
14+
describe('Magento_Bundle/js/components/bundle-dynamic-rows', function () {
15+
let unit;
16+
17+
beforeEach(function () {
18+
unit = new BundleDynamicRows({
19+
dataScope: 'bundle-dynamic-rows',
20+
label: 'Dynamic Rows',
21+
collapsibleHeader: true,
22+
columnsHeader: false,
23+
deleteProperty: false,
24+
addButton: false,
25+
name: 'dynamic',
26+
bundleSelectionsName: 'bundle_selections'
27+
});
28+
});
29+
30+
describe('test removeBundleItemsFromOption method', function () {
31+
it('Check if bundle items are removed from option', function () {
32+
let bundleSelections = new uiCollection;
33+
34+
spyOn(bundleSelections, 'destroyChildren').and.callThrough();
35+
spyOn(registry, 'get').and.returnValue(bundleSelections);
36+
spyOn(unit, 'removeBundleItemsFromOption').and.callThrough();
37+
38+
unit.removeBundleItemsFromOption(1);
39+
40+
expect(registry.get).toHaveBeenCalledWith('dynamic.1.bundle_selections');
41+
expect(bundleSelections.destroyChildren).toHaveBeenCalled();
42+
});
43+
});
44+
});
45+
});

0 commit comments

Comments
 (0)