Skip to content

Commit 2015870

Browse files
committed
Add isFromIncludedArchive flag to references.
1 parent d909887 commit 2015870

File tree

5 files changed

+113
-4
lines changed

5 files changed

+113
-4
lines changed

src/components/ContentNode.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ function renderNode(createElement, references) {
470470
url: reference.url,
471471
kind: reference.kind,
472472
role: reference.role,
473-
isActive: node.isActive,
473+
isActive: reference.isFromIncludedArchive && node.isActive,
474474
ideTitle: reference.ideTitle,
475475
titleStyle: reference.titleStyle,
476476
hasInlineFormatting: !!titleInlineContent,

src/components/DocumentationTopic/PrimaryContent/DeclarationToken/LinkableToken.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default {
1919
render(createElement) {
2020
const reference = this.references[this.identifier];
2121
// internal and external link
22-
if (reference && reference.url) {
22+
if (reference && reference.isFromIncludedArchive && reference.url) {
2323
return createElement(Reference, {
2424
props: {
2525
url: reference.url,

src/mixins/referencesProvider.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* See https://swift.org/LICENSE.txt for license information
88
* See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
10+
import AppStore from 'docc-render/stores/AppStore';
1011

1112
export default {
1213
// inject the `store`
@@ -21,8 +22,37 @@ export default {
2122
}),
2223
},
2324
},
25+
data: () => ({ appState: AppStore.state }),
2426
computed: {
2527
// exposes the references for the current page
26-
references: ({ store }) => store.state.references,
28+
references() {
29+
const {
30+
isFromIncludedArchive,
31+
store: {
32+
state: { references: originalRefs = {} },
33+
},
34+
} = this;
35+
// if present, use `includedArchiveIdentifiers` data to determine which
36+
// references should still be considered active or not
37+
return Object.keys(originalRefs).reduce((newRefs, id) => ({
38+
...newRefs,
39+
[id]: {
40+
...originalRefs[id],
41+
isFromIncludedArchive: isFromIncludedArchive(id),
42+
},
43+
}), {});
44+
},
45+
},
46+
methods: {
47+
isFromIncludedArchive(id) {
48+
const { includedArchiveIdentifiers = [] } = this.appState;
49+
if (!includedArchiveIdentifiers.length) {
50+
return true;
51+
}
52+
53+
return includedArchiveIdentifiers.some(archiveId => (
54+
id?.startsWith(`doc://${archiveId}`)
55+
));
56+
},
2757
},
2858
};

tests/unit/components/ContentNode.spec.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
import { shallowMount, mount } from '@vue/test-utils';
12+
import AppStore from 'docc-render/stores/AppStore';
1213
import Aside from 'docc-render/components/ContentNode/Aside.vue';
1314
import CodeListing from 'docc-render/components/ContentNode/CodeListing.vue';
1415
import CodeVoice from 'docc-render/components/ContentNode/CodeVoice.vue';
@@ -1297,6 +1298,43 @@ describe('ContentNode', () => {
12971298
const reference = wrapper.find('.content');
12981299
expect(reference.isEmpty()).toBe(true);
12991300
});
1301+
1302+
it('sets `isActive` for included archive content', () => {
1303+
const foo = {
1304+
identifier: 'doc://Foo/documentation/foo',
1305+
title: 'Foo',
1306+
url: '/documentation/foo',
1307+
};
1308+
const mountRef = (props = {}) => mountWithItem({
1309+
type: 'reference',
1310+
identifier: foo.identifier,
1311+
...props,
1312+
}, {
1313+
[foo.identifier]: foo,
1314+
});
1315+
1316+
const wrapper1 = mountRef();
1317+
const ref1 = wrapper1.find('.content').find(Reference);
1318+
expect(ref1.exists()).toBe(true);
1319+
expect(ref1.props('isActive')).toBe(true);
1320+
1321+
AppStore.setIncludedArchiveIdentifiers(['Bar']);
1322+
const wrapper2 = mountRef();
1323+
const ref2 = wrapper2.find('.content').find(Reference);
1324+
expect(ref2.exists()).toBe(true);
1325+
expect(ref2.props('isActive')).toBe(false);
1326+
1327+
AppStore.setIncludedArchiveIdentifiers(['Bar', 'Foo']);
1328+
const wrapper3 = mountRef();
1329+
const ref3 = wrapper3.find('.content').find(Reference);
1330+
expect(ref3.exists()).toBe(true);
1331+
expect(ref3.props('isActive')).toBe(true);
1332+
1333+
const wrapper4 = mountRef({ isActive: false });
1334+
const ref4 = wrapper4.find('.content').find(Reference);
1335+
expect(ref4.exists()).toBe(true);
1336+
expect(ref4.props('isActive')).toBe(false);
1337+
});
13001338
});
13011339

13021340
describe('with type="strong"', () => {

tests/unit/components/DocumentationTopic/PrimaryContent/DeclarationToken/LinkableToken.spec.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
*/
1010

1111
import { shallowMount } from '@vue/test-utils';
12+
import AppStore from 'docc-render/stores/AppStore';
1213
import LinkableToken
1314
from 'docc-render/components/DocumentationTopic/PrimaryContent/DeclarationToken/LinkableToken.vue';
1415
import Reference from 'docc-render/components/ContentNode/Reference.vue';
1516

1617
describe('LinkableToken', () => {
1718
const foo = {
18-
identifier: 'foo',
19+
identifier: 'doc://Foo/documentation/foo',
1920
title: 'Foo',
2021
url: '/documentation/foo',
2122
};
@@ -70,4 +71,44 @@ describe('LinkableToken', () => {
7071
expect(link.props('url')).toBe(foo.url);
7172
expect(link.text()).toBe(foo.title);
7273
});
74+
75+
it('renders a link for references to included archive content', () => {
76+
AppStore.setIncludedArchiveIdentifiers(['Foo']);
77+
const wrapper = shallowMount(LinkableToken, {
78+
...defaultOpts,
79+
provide: {
80+
store: {
81+
state: {
82+
references: {
83+
[foo.identifier]: foo,
84+
},
85+
},
86+
},
87+
},
88+
});
89+
90+
const link = wrapper.find(Reference);
91+
expect(link.exists()).toBe(true);
92+
expect(link.props('url')).toBe(foo.url);
93+
expect(link.text()).toBe(foo.title);
94+
});
95+
96+
it('renders a span for references to non-included archive content', () => {
97+
AppStore.setIncludedArchiveIdentifiers(['Bar']);
98+
const wrapper = shallowMount(LinkableToken, {
99+
...defaultOpts,
100+
provide: {
101+
store: {
102+
state: {
103+
references: {
104+
[foo.identifier]: foo,
105+
},
106+
},
107+
},
108+
},
109+
});
110+
111+
expect(wrapper.is('span')).toBe(true);
112+
expect(wrapper.text()).toBe(foo.title);
113+
});
73114
});

0 commit comments

Comments
 (0)