Skip to content

Commit e205771

Browse files
author
Dobromir Hristov
authored
if "Hide Deprecated" chosen, hide labels when all children are deprecated (#397)
closes rdar://93506254
1 parent 70ff602 commit e205771

File tree

5 files changed

+245
-7
lines changed

5 files changed

+245
-7
lines changed

src/components/Navigator.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ import { getSetting } from 'docc-render/utils/theme-settings';
5757
* @property {array} abstract - symbol abstract
5858
* @property {string} path - path to page, used in navigation
5959
* @property {number} parent - parent UID
60+
* @property {number} groupMarkerUID - UID of the groupMarker that labels this
61+
* @property {number} deprecatedChildrenCount - number of children that are deprecated.
62+
* Used for filtering
6063
* @property {number} depth - depth of symbol in original tree
6164
* @property {number} index - index of item in siblings
6265
* @property {number} siblingsCount - number of siblings
@@ -198,10 +201,17 @@ export default {
198201
node.parent = parentUID;
199202
// store the current groupMarker reference
200203
if (node.type === TopicTypes.groupMarker) {
204+
node.deprecatedChildrenCount = 0;
201205
groupMarkerNode = node;
202206
} else if (groupMarkerNode) {
203207
// push the current node to the group marker before it
204208
groupMarkerNode.childUIDs.push(node.uid);
209+
// store the groupMarker UID for each item
210+
node.groupMarkerUID = groupMarkerNode.uid;
211+
if (node.deprecated) {
212+
// count deprecated children, so we can hide the entire group when filtering
213+
groupMarkerNode.deprecatedChildrenCount += 1;
214+
}
205215
}
206216
// store which item it is
207217
node.index = index;

src/components/Navigator/NavigatorCard.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,10 @@ export default {
383383
const tagsSet = new Set(selectedTags);
384384
// find children that match current filters
385385
return children.filter(({
386-
title, path, type, deprecated,
386+
title, path, type, deprecated, deprecatedChildrenCount, childUIDs,
387387
}) => {
388+
// groupMarkers know how many children they have and how many are deprecated
389+
const isDeprecated = deprecated || deprecatedChildrenCount === childUIDs.length;
388390
// check if `title` matches the pattern, if provided
389391
const titleMatch = filterPattern ? filterPattern.test(title) : true;
390392
// check if `type` matches any of the selected tags
@@ -395,7 +397,7 @@ export default {
395397
if (apiChanges && !tagMatch) {
396398
tagMatch = tagsSet.has(apiChangesObject[path]);
397399
}
398-
if (!deprecated && tagsSet.has(HIDE_DEPRECATED_TAG)) {
400+
if (!isDeprecated && tagsSet.has(HIDE_DEPRECATED_TAG)) {
399401
tagMatch = true;
400402
}
401403
}
@@ -409,8 +411,9 @@ export default {
409411
* Returns a Set of all nodes that match a filter, along with their parents.
410412
* @returns Set<NavigatorFlatItem>
411413
*/
412-
filteredChildrenUpToRootSet: ({ filteredChildren, getParents }) => new Set(
413-
filteredChildren.flatMap(({ uid }) => getParents(uid)),
414+
filteredChildrenUpToRootSet: ({ filteredChildren, getParents, childrenMap }) => new Set(
415+
filteredChildren.flatMap(({ uid, groupMarkerUID }) => getParents(uid)
416+
.concat(childrenMap[groupMarkerUID] || [])),
414417
),
415418
/**
416419
* This generates a map of all the nodes we are allowed to render at a certain time.

tests/unit/components/Navigator.spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ describe('Navigator', () => {
299299
551503844,
300300
-97593391,
301301
],
302+
deprecatedChildrenCount: 0,
302303
depth: 0,
303304
index: 0,
304305
parent: INDEX_ROOT_KEY,
@@ -315,6 +316,7 @@ describe('Navigator', () => {
315316
1440072939,
316317
],
317318
depth: 0,
319+
groupMarkerUID: -196255993,
318320
index: 1,
319321
parent: INDEX_ROOT_KEY,
320322
path: '/foo/child0',
@@ -329,6 +331,7 @@ describe('Navigator', () => {
329331
1439149417,
330332
1440072939,
331333
],
334+
deprecatedChildrenCount: 0,
332335
depth: 1,
333336
index: 0,
334337
parent: 551503844,
@@ -340,6 +343,7 @@ describe('Navigator', () => {
340343
{
341344
childUIDs: [],
342345
depth: 1,
346+
groupMarkerUID: -361407047,
343347
index: 1,
344348
parent: 551503844,
345349
path: '/foo/child0/grandchild0',
@@ -353,6 +357,7 @@ describe('Navigator', () => {
353357
305326087,
354358
],
355359
depth: 1,
360+
groupMarkerUID: -361407047,
356361
index: 2,
357362
parent: 551503844,
358363
path: '/foo/child0/grandchild1',
@@ -375,6 +380,7 @@ describe('Navigator', () => {
375380
{
376381
childUIDs: [],
377382
depth: 1,
383+
groupMarkerUID: -361407047,
378384
index: 3,
379385
parent: 551503844,
380386
path: '/foo/child0/grandchild2',
@@ -388,6 +394,7 @@ describe('Navigator', () => {
388394
-827353283,
389395
],
390396
depth: 0,
397+
groupMarkerUID: -196255993,
391398
index: 2,
392399
parent: INDEX_ROOT_KEY,
393400
path: '/foo/child1/',
@@ -410,6 +417,21 @@ describe('Navigator', () => {
410417
]);
411418
});
412419

420+
it('counts the amount of deprecated items a groupMarker has', () => {
421+
const technologyClone = clone(technology);
422+
technologyClone.children[1].deprecated = true;
423+
technologyClone.children[2].deprecated = true;
424+
technologyClone.children[1].children[1].deprecated = true;
425+
const wrapper = createWrapper({
426+
propsData: {
427+
technology: technologyClone,
428+
},
429+
});
430+
const children = wrapper.find(NavigatorCard).props('children');
431+
expect(children[0]).toHaveProperty('deprecatedChildrenCount', 2);
432+
expect(children).toMatchSnapshot();
433+
});
434+
413435
it('removes the `beta` flag from children, if the technology is a `beta`', () => {
414436
const technologyClone = clone(technology);
415437
technologyClone.beta = true;

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

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,6 +1523,7 @@ describe('NavigatorCard', () => {
15231523
depth: 1,
15241524
index: 4,
15251525
childUIDs: [root0Child0.uid, root0Child1.uid],
1526+
deprecatedChildrenCount: 0,
15261527
};
15271528

15281529
const root0Updated = {
@@ -1578,7 +1579,7 @@ describe('NavigatorCard', () => {
15781579
expect(allItems.at(3).props('item')).toEqual(root0Child1GrandChild0);
15791580
});
15801581

1581-
it('shows groupMarkers in results, showing children that match if any or all if none', async () => {
1582+
it('matches groupMarkers in results, showing children that match if any or all if none', async () => {
15821583
const wrapper = createWrapper({
15831584
propsData: {
15841585
children: [
@@ -1588,7 +1589,8 @@ describe('NavigatorCard', () => {
15881589
},
15891590
});
15901591
await flushPromises();
1591-
wrapper.find(FilterInput).vm.$emit('input', groupMarker.title);
1592+
const input = wrapper.find(FilterInput);
1593+
input.vm.$emit('input', groupMarker.title);
15921594
await flushPromises();
15931595
let items = wrapper.findAll(NavigatorCardItem);
15941596
// parent + group and 2 siblings
@@ -1604,7 +1606,7 @@ describe('NavigatorCard', () => {
16041606
expect(items).toHaveLength(5);
16051607
expect(items.at(4).props('item')).toEqual(root0Child1GrandChild0);
16061608
// assert that partial matches of group and children show only those that match
1607-
wrapper.find(FilterInput).vm.$emit('input', 'First Child');
1609+
input.vm.$emit('input', 'First Child');
16081610
await flushPromises();
16091611
items = wrapper.findAll(NavigatorCardItem);
16101612
expect(items).toHaveLength(5);
@@ -1614,6 +1616,65 @@ describe('NavigatorCard', () => {
16141616
expect(items.at(3).props('item')).toEqual(root0Child1);
16151617
expect(items.at(4).props('item')).toEqual(root0Child1GrandChild0);
16161618
});
1619+
1620+
it('renders the `groupMarker`, that is connected to a search result', async () => {
1621+
const root0Child0Clone = { ...root0Child0, groupMarkerUID: groupMarker.uid };
1622+
const root0Child1Clone = { ...root0Child1, groupMarkerUID: groupMarker.uid };
1623+
const wrapper = createWrapper({
1624+
propsData: {
1625+
children: [
1626+
root0Updated, groupMarker, root0Child0Clone,
1627+
root0Child1Clone, root0Child1GrandChild0, root1,
1628+
],
1629+
activePath: [root0.path],
1630+
},
1631+
});
1632+
await flushPromises();
1633+
const filter = wrapper.find(FilterInput);
1634+
// apply a filter that matches an element
1635+
filter.vm.$emit('input', root0Child1Clone.title);
1636+
await flushPromises();
1637+
const items = wrapper.findAll(NavigatorCardItem);
1638+
// parent + group and 1 item
1639+
expect(items).toHaveLength(3);
1640+
expect(items.at(0).props('item')).toEqual(root0Updated);
1641+
expect(items.at(1).props('item')).toEqual(groupMarker);
1642+
expect(items.at(2).props('item')).toEqual(root0Child1Clone);
1643+
});
1644+
1645+
it('does not render a `groupMarker`, if all of its children are deprecated, and `HideDeprecated` is ON', async () => {
1646+
const root0Child0Clone = {
1647+
...root0Child0,
1648+
groupMarkerUID: groupMarker.uid,
1649+
deprecated: true,
1650+
};
1651+
const root0Child1Clone = {
1652+
...root0Child1,
1653+
groupMarkerUID: groupMarker.uid,
1654+
deprecated: true,
1655+
childUIDs: [],
1656+
};
1657+
const groupMarkerClone = { ...groupMarker, deprecatedChildrenCount: 2 };
1658+
const root0Clone = { ...root0Updated, deprecated: true };
1659+
const wrapper = createWrapper({
1660+
propsData: {
1661+
children: [
1662+
root0Clone, groupMarkerClone, root0Child0Clone,
1663+
root0Child1Clone, root1,
1664+
],
1665+
activePath: [root0Clone.path],
1666+
},
1667+
});
1668+
await flushPromises();
1669+
const filter = wrapper.find(FilterInput);
1670+
// apply a filter that matches an element
1671+
filter.vm.$emit('update:selectedTags', [HIDE_DEPRECATED_TAG]);
1672+
await flushPromises();
1673+
const items = wrapper.findAll(NavigatorCardItem);
1674+
// parent
1675+
expect(items).toHaveLength(1);
1676+
expect(items.at(0).props('item')).toEqual(root1);
1677+
});
16171678
});
16181679

16191680
it('renders a Beta badge in the header', async () => {

0 commit comments

Comments
 (0)