Skip to content

Commit 49f02a0

Browse files
committed
Include parentNode in getFlatDataFromTree util
1 parent 31c320b commit 49f02a0

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/utils/tree-data-utils.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,8 @@ export function getFlatDataFromTree({ treeData, getNodeKey, ignoreCollapsed = tr
833833
treeData,
834834
getNodeKey,
835835
ignoreCollapsed,
836-
callback: ({ node, lowerSiblingCounts, path, treeIndex }) => {
837-
flattened.push({ node, lowerSiblingCounts, path, treeIndex });
836+
callback: (nodeInfo) => {
837+
flattened.push(nodeInfo);
838838
},
839839
});
840840

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

+17-5
Original file line numberDiff line numberDiff line change
@@ -446,16 +446,16 @@ describe('getFlatDataFromTree', () => {
446446
getNodeKey: keyFromTreeIndex,
447447
treeData: [ { key: 0 } ],
448448
})).toEqual([
449-
{ node: { key: 0 }, path: [0], lowerSiblingCounts: [ 0 ], treeIndex: 0 },
449+
{ node: { key: 0 }, parentNode: null, path: [0], lowerSiblingCounts: [ 0 ], treeIndex: 0 },
450450
]);
451451

452452
expect(getFlatDataFromTree({
453453
ignoreCollapsed: true,
454454
treeData: [ { key: 0 }, { key: 1 } ],
455455
getNodeKey: keyFromTreeIndex
456456
})).toEqual([
457-
{ node: { key: 0 }, path: [0], lowerSiblingCounts: [ 1 ], treeIndex: 0 },
458-
{ node: { key: 1 }, path: [1], lowerSiblingCounts: [ 0 ], treeIndex: 1 }
457+
{ node: { key: 0 }, parentNode: null, path: [0], lowerSiblingCounts: [ 1 ], treeIndex: 0 },
458+
{ node: { key: 1 }, parentNode: null, path: [1], lowerSiblingCounts: [ 0 ], treeIndex: 1 }
459459
]);
460460
});
461461

@@ -487,8 +487,8 @@ describe('getFlatDataFromTree', () => {
487487
getNodeKey: keyFromTreeIndex,
488488
treeData,
489489
})).toEqual([
490-
{ node: treeData[0], path: [0], lowerSiblingCounts: [ 1 ], treeIndex: 0 },
491-
{ node: treeData[1], path: [1], lowerSiblingCounts: [ 0 ], treeIndex: 1 }
490+
{ node: treeData[0], parentNode: null, path: [0], lowerSiblingCounts: [ 1 ], treeIndex: 0 },
491+
{ node: treeData[1], parentNode: null, path: [1], lowerSiblingCounts: [ 0 ], treeIndex: 1 }
492492
]);
493493
});
494494

@@ -524,30 +524,35 @@ describe('getFlatDataFromTree', () => {
524524
})).toEqual([
525525
{
526526
node: treeData[0],
527+
parentNode: null,
527528
path: [0],
528529
lowerSiblingCounts: [ 1 ],
529530
treeIndex: 0,
530531
},
531532
{
532533
node: treeData[0].children[0],
534+
parentNode: treeData[0],
533535
path: [0, 1],
534536
lowerSiblingCounts: [ 1, 1 ],
535537
treeIndex: 1,
536538
},
537539
{
538540
node: treeData[0].children[1],
541+
parentNode: treeData[0],
539542
path: [0, 4],
540543
lowerSiblingCounts: [ 1, 0 ],
541544
treeIndex: 2,
542545
},
543546
{
544547
node: treeData[0].children[1].children[0],
548+
parentNode: treeData[0].children[1],
545549
path: [0, 4, 5],
546550
lowerSiblingCounts: [ 1, 0, 0 ],
547551
treeIndex: 3,
548552
},
549553
{
550554
node: treeData[1],
555+
parentNode: null,
551556
path: [6],
552557
lowerSiblingCounts: [ 0 ],
553558
treeIndex: 4,
@@ -588,42 +593,49 @@ describe('getFlatDataFromTree', () => {
588593
})).toEqual([
589594
{
590595
node: treeData[0],
596+
parentNode: null,
591597
path: [0],
592598
lowerSiblingCounts: [1],
593599
treeIndex: 0,
594600
},
595601
{
596602
node: treeData[0].children[0],
603+
parentNode: treeData[0],
597604
path: [0, 1],
598605
lowerSiblingCounts: [1, 1],
599606
treeIndex: 1,
600607
},
601608
{
602609
node: treeData[0].children[0].children[0],
610+
parentNode: treeData[0].children[0],
603611
path: [0, 1, 2],
604612
lowerSiblingCounts: [1, 1, 1],
605613
treeIndex: 2,
606614
},
607615
{
608616
node: treeData[0].children[0].children[1],
617+
parentNode: treeData[0].children[0],
609618
path: [0, 1, 3],
610619
lowerSiblingCounts: [1, 1, 0],
611620
treeIndex: 3,
612621
},
613622
{
614623
node: treeData[0].children[1],
624+
parentNode: treeData[0],
615625
path: [0, 4],
616626
lowerSiblingCounts: [1, 0],
617627
treeIndex: 4,
618628
},
619629
{
620630
node: treeData[0].children[1].children[0],
631+
parentNode: treeData[0].children[1],
621632
path: [0, 4, 5],
622633
lowerSiblingCounts: [1, 0, 0],
623634
treeIndex: 5,
624635
},
625636
{
626637
node: treeData[1],
638+
parentNode: null,
627639
path: [6],
628640
lowerSiblingCounts: [0],
629641
treeIndex: 6,

0 commit comments

Comments
 (0)