Skip to content

Commit 20ecbc4

Browse files
committed
Merge branch 'EtixLabs-hover-bugfix'
2 parents 947b003 + d8fa03b commit 20ecbc4

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/utils/tree-data-utils.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,8 @@ function addNodeAtDepthAndIndex({
610610
}
611611

612612
// If the current position is the only possible place to add, add it
613-
if (currentIndex >= minimumTreeIndex - 1 || (isLastChild && !node.children)) {
613+
if (currentIndex >= minimumTreeIndex - 1
614+
|| (isLastChild && !(node.children && node.children.length))) {
614615
if (typeof node.children === 'function') {
615616
throw new Error('Cannot add to children defined by a function');
616617
} else {
@@ -740,7 +741,7 @@ function addNodeAtDepthAndIndex({
740741
* Insert a node into the tree at the given depth, after the minimum index
741742
*
742743
* @param {!Object[]} treeData - Tree data
743-
* @param {!number} depth - The depth to insert the node at
744+
* @param {!number} depth - The depth to insert the node at (the first level of the array being depth 0)
744745
* @param {!number} minimumTreeIndex - The lowest possible treeIndex to insert the node at
745746
* @param {!Object} newNode - The node to insert into the tree
746747
* @param {boolean=} ignoreCollapsed - Ignore children of nodes without `expanded` set to `true`

src/utils/tree-data-utils.test.js

+39
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,45 @@ describe('insertNode', () => {
13501350
path: [1, 3, 4],
13511351
});
13521352
});
1353+
1354+
it('should work with nodes with an empty children array', () => {
1355+
expect(insertNode({
1356+
treeData: [
1357+
{
1358+
expanded: true,
1359+
children: [
1360+
{
1361+
expanded: true,
1362+
children: [
1363+
{ children: [] },
1364+
],
1365+
},
1366+
],
1367+
},
1368+
],
1369+
newNode: { key: 'new' },
1370+
depth: 2,
1371+
minimumTreeIndex: 2,
1372+
getNodeKey: keyFromTreeIndex,
1373+
})).toEqual({
1374+
treeData: [
1375+
{
1376+
expanded: true,
1377+
children: [
1378+
{
1379+
expanded: true,
1380+
children: [
1381+
{ key: 'new' },
1382+
{ children: [] },
1383+
],
1384+
},
1385+
],
1386+
},
1387+
],
1388+
treeIndex: 2,
1389+
path: [0, 1, 2],
1390+
});
1391+
});
13531392
});
13541393

13551394
describe('walk', () => {

0 commit comments

Comments
 (0)