Skip to content

Commit 0ae2fbc

Browse files
author
Dobromir Hristov
authored
fix: make sure toggling deep trees takes groupMarkers into consideration and does not add extra space. (#429)
closes rdar://99748634
1 parent 7cf76ef commit 0ae2fbc

File tree

2 files changed

+57
-38
lines changed

2 files changed

+57
-38
lines changed

src/components/Navigator/NavigatorCard.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ export default {
650650
* @return {NavigatorFlatItem[]}
651651
*/
652652
getAllChildren(uid) {
653-
const arr = [];
653+
const collection = new Set([]);
654654
const stack = [uid];
655655
let current = null;
656656
@@ -660,13 +660,13 @@ export default {
660660
current = stack.shift();
661661
// find the object
662662
const obj = this.childrenMap[current];
663-
// add it's uid
664-
arr.push(obj);
663+
// add it to the collection
664+
collection.add(obj);
665665
// add all if it's children to the front of the stack
666666
stack.unshift(...obj.childUIDs);
667667
}
668668
669-
return arr;
669+
return [...collection];
670670
},
671671
/**
672672
* Get all the parents of a node, up to the root.

tests/unit/components/Navigator/NavigatorCard.spec.js

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,22 @@ const root1 = {
113113
childUIDs: [],
114114
};
115115

116+
const groupMarker = {
117+
type: TopicTypes.groupMarker,
118+
title: 'First Child Group Marker',
119+
uid: 22,
120+
parent: root0.uid,
121+
depth: 1,
122+
index: 4,
123+
childUIDs: [root0Child0.uid, root0Child1.uid],
124+
deprecatedChildrenCount: 0,
125+
};
126+
127+
const root0WithGroupMarker = {
128+
...root0,
129+
childUIDs: [groupMarker.uid].concat(root0.childUIDs),
130+
};
131+
116132
const children = [
117133
root0,
118134
root0Child0,
@@ -121,6 +137,15 @@ const children = [
121137
root1,
122138
];
123139

140+
const childrenWithGroupMarker = [
141+
root0WithGroupMarker,
142+
groupMarker,
143+
root0Child0,
144+
root0Child1,
145+
root0Child1GrandChild0,
146+
root1,
147+
];
148+
124149
const activePath = [root0.path, root0Child0.path];
125150

126151
const defaultProps = {
@@ -550,6 +575,23 @@ describe('NavigatorCard', () => {
550575
expect(all.at(1).props('item')).toEqual(root0Child1);
551576
expect(all.at(2).props('item')).toEqual(root0Child1GrandChild0);
552577
});
578+
579+
it('keeps groupMarkers in mind, when `@toggle-full` is handled', async () => {
580+
const wrapper = createWrapper({
581+
propsData: {
582+
// make sure no items are open
583+
activePath: [],
584+
children: childrenWithGroupMarker,
585+
},
586+
});
587+
await flushPromises();
588+
wrapper.find(NavigatorCardItem).vm.$emit('toggle-full', root0);
589+
await flushPromises();
590+
expect(wrapper.findAll(NavigatorCardItem)).toHaveLength(6);
591+
wrapper.find(NavigatorCardItem).vm.$emit('toggle-full', root0);
592+
await flushPromises();
593+
expect(wrapper.findAll(NavigatorCardItem)).toHaveLength(2);
594+
});
553595
});
554596

555597
describe('toggles all siblings on @toggle-siblings', () => {
@@ -1534,22 +1576,6 @@ describe('NavigatorCard', () => {
15341576
});
15351577

15361578
describe('with groupMarker', () => {
1537-
const groupMarker = {
1538-
type: TopicTypes.groupMarker,
1539-
title: 'First Child Group Marker',
1540-
uid: 22,
1541-
parent: root0.uid,
1542-
depth: 1,
1543-
index: 4,
1544-
childUIDs: [root0Child0.uid, root0Child1.uid],
1545-
deprecatedChildrenCount: 0,
1546-
};
1547-
1548-
const root0Updated = {
1549-
...root0,
1550-
childUIDs: [groupMarker.uid].concat(root0.childUIDs),
1551-
};
1552-
15531579
it('shows "Hide Deprecated" tag, if there are deprecated items', async () => {
15541580
const updatedChild = {
15551581
...root0Child0,
@@ -1559,7 +1585,8 @@ describe('NavigatorCard', () => {
15591585
const wrapper = createWrapper({
15601586
propsData: {
15611587
children: [
1562-
root0Updated, groupMarker, updatedChild, root0Child1, root0Child1GrandChild0, root1,
1588+
root0WithGroupMarker, groupMarker, updatedChild, root0Child1, root0Child1GrandChild0,
1589+
root1,
15631590
],
15641591
activePath: [root0.path],
15651592
},
@@ -1577,7 +1604,7 @@ describe('NavigatorCard', () => {
15771604
// assert the deprecated item is filtered out
15781605
expect(allItems).toHaveLength(4);
15791606
// assert root is rendered
1580-
expect(allItems.at(0).props('item')).toEqual(root0Updated);
1607+
expect(allItems.at(0).props('item')).toEqual(root0WithGroupMarker);
15811608
// assert the group marker is rendered
15821609
expect(allItems.at(1).props('item')).toEqual(groupMarker);
15831610
// assert the none-deprecated child is rendered, but its not expanded
@@ -1592,7 +1619,7 @@ describe('NavigatorCard', () => {
15921619
allItems = wrapper.findAll(NavigatorCardItem);
15931620
// assert that filtering opens everything as usual, showing groupMarkers as well
15941621
expect(allItems).toHaveLength(4);
1595-
expect(allItems.at(0).props('item')).toEqual(root0Updated);
1622+
expect(allItems.at(0).props('item')).toEqual(root0WithGroupMarker);
15961623
expect(allItems.at(1).props('item')).toEqual(groupMarker);
15971624
expect(allItems.at(2).props('item')).toEqual(root0Child1);
15981625
expect(allItems.at(3).props('item')).toEqual(root0Child1GrandChild0);
@@ -1602,7 +1629,8 @@ describe('NavigatorCard', () => {
16021629
const wrapper = createWrapper({
16031630
propsData: {
16041631
children: [
1605-
root0Updated, groupMarker, root0Child0, root0Child1, root0Child1GrandChild0, root1,
1632+
root0WithGroupMarker, groupMarker, root0Child0, root0Child1, root0Child1GrandChild0,
1633+
root1,
16061634
],
16071635
activePath: [root0.path],
16081636
},
@@ -1614,7 +1642,7 @@ describe('NavigatorCard', () => {
16141642
let items = wrapper.findAll(NavigatorCardItem);
16151643
// parent + group and 2 siblings
16161644
expect(items).toHaveLength(4);
1617-
expect(items.at(0).props('item')).toEqual(root0Updated);
1645+
expect(items.at(0).props('item')).toEqual(root0WithGroupMarker);
16181646
expect(items.at(1).props('item')).toEqual(groupMarker);
16191647
expect(items.at(2).props('item')).toEqual(root0Child0);
16201648
expect(items.at(3).props('item')).toEqual(root0Child1);
@@ -1629,7 +1657,7 @@ describe('NavigatorCard', () => {
16291657
await flushPromises();
16301658
items = wrapper.findAll(NavigatorCardItem);
16311659
expect(items).toHaveLength(5);
1632-
expect(items.at(0).props('item')).toEqual(root0Updated);
1660+
expect(items.at(0).props('item')).toEqual(root0WithGroupMarker);
16331661
expect(items.at(1).props('item')).toEqual(groupMarker);
16341662
expect(items.at(2).props('item')).toEqual(root0Child0);
16351663
expect(items.at(3).props('item')).toEqual(root0Child1);
@@ -1642,7 +1670,7 @@ describe('NavigatorCard', () => {
16421670
const wrapper = createWrapper({
16431671
propsData: {
16441672
children: [
1645-
root0Updated, groupMarker, root0Child0Clone,
1673+
root0WithGroupMarker, groupMarker, root0Child0Clone,
16461674
root0Child1Clone, root0Child1GrandChild0, root1,
16471675
],
16481676
activePath: [root0.path],
@@ -1656,7 +1684,7 @@ describe('NavigatorCard', () => {
16561684
const items = wrapper.findAll(NavigatorCardItem);
16571685
// parent + group and 1 item
16581686
expect(items).toHaveLength(3);
1659-
expect(items.at(0).props('item')).toEqual(root0Updated);
1687+
expect(items.at(0).props('item')).toEqual(root0WithGroupMarker);
16601688
expect(items.at(1).props('item')).toEqual(groupMarker);
16611689
expect(items.at(2).props('item')).toEqual(root0Child1Clone);
16621690
});
@@ -1674,7 +1702,7 @@ describe('NavigatorCard', () => {
16741702
childUIDs: [],
16751703
};
16761704
const groupMarkerClone = { ...groupMarker, deprecatedChildrenCount: 2 };
1677-
const root0Clone = { ...root0Updated, deprecated: true };
1705+
const root0Clone = { ...root0WithGroupMarker, deprecated: true };
16781706
const wrapper = createWrapper({
16791707
propsData: {
16801708
children: [
@@ -1713,15 +1741,6 @@ describe('NavigatorCard', () => {
17131741
...root0Child0,
17141742
deprecated: true,
17151743
};
1716-
const groupMarker = {
1717-
type: TopicTypes.groupMarker,
1718-
title: 'First Child Group Marker',
1719-
uid: 22,
1720-
parent: root0.uid,
1721-
depth: 1,
1722-
index: 4,
1723-
childUIDs: [],
1724-
};
17251744
const root0Updated = {
17261745
...root0,
17271746
childUIDs: root0.childUIDs.concat(groupMarker.uid),

0 commit comments

Comments
 (0)