Skip to content

Commit 336dfcb

Browse files
committed
Strip url data from refs.
Instead of passing a new boolean flag to indicate which refs should be included or not, just strip out the URL data for refs that are not part of included archives and should not be linked to.
1 parent 2a14ae3 commit 336dfcb

File tree

16 files changed

+139
-110
lines changed

16 files changed

+139
-110
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: reference.isFromIncludedArchive && node.isActive,
473+
isActive: node.isActive,
474474
ideTitle: reference.ideTitle,
475475
titleStyle: reference.titleStyle,
476476
hasInlineFormatting: !!titleInlineContent,

src/components/ContentNode/Reference.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ export default {
5454
name: 'Reference',
5555
computed: {
5656
isInternal({ url }) {
57+
if (!url) {
58+
return false;
59+
}
5760
if (!url.startsWith('/') && !url.startsWith('#')) {
5861
// If the URL has a scheme, it's not an internal link.
5962
return false;
@@ -92,7 +95,7 @@ export default {
9295
props: {
9396
url: {
9497
type: String,
95-
required: true,
98+
required: false,
9699
},
97100
kind: {
98101
type: String,

src/components/ContentNode/ReferenceExternal.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
-->
1010

1111
<template>
12-
<a v-if="isActive" :href="url"><slot /></a>
12+
<a v-if="url && isActive" :href="url"><slot /></a>
1313
<span v-else><slot /></span>
1414
</template>
1515

@@ -19,7 +19,7 @@ export default {
1919
props: {
2020
url: {
2121
type: String,
22-
required: true,
22+
required: false,
2323
},
2424
isActive: {
2525
type: Boolean,

src/components/ContentNode/ReferenceInternal.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
-->
1010

1111
<template>
12-
<router-link v-if="isActive" :to="url"><slot /></router-link>
12+
<router-link v-if="url && isActive" :to="url"><slot /></router-link>
1313
<span v-else><slot/></span>
1414
</template>
1515

@@ -19,7 +19,7 @@ export default {
1919
props: {
2020
url: {
2121
type: String,
22-
required: true,
22+
required: false,
2323
},
2424
isActive: {
2525
type: Boolean,

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.isFromIncludedArchive && reference.url) {
22+
if (reference && reference.url) {
2323
return createElement(Reference, {
2424
props: {
2525
url: reference.url,

src/components/DocumentationTopic/RelationshipsList.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
:role="symbol.role"
2222
:kind="symbol.kind"
2323
:url="symbol.url"
24-
:isActive="symbol.isFromIncludedArchive"
2524
>{{symbol.title}}</Reference>
2625
<WordBreak v-else tag="code">{{symbol.title}}</WordBreak>
2726
<ConditionalConstraints

src/mixins/referencesProvider.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ export default {
3232
state: { references: originalRefs = {} },
3333
},
3434
} = 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-
}), {});
35+
// strip the `url` key from refs if their identifier comes from an
36+
// archive that hasn't been included by DocC
37+
return Object.keys(originalRefs).reduce((newRefs, id) => {
38+
const { url, ...refWithoutUrl } = originalRefs[id];
39+
return {
40+
...newRefs,
41+
[id]: isFromIncludedArchive(id) ? originalRefs[id] : refWithoutUrl,
42+
};
43+
}, {});
4444
},
4545
},
4646
methods: {

tests/unit/components/ContentNode.spec.js

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

1111
import { shallowMount, mount } from '@vue/test-utils';
12-
import AppStore from 'docc-render/stores/AppStore';
1312
import Aside from 'docc-render/components/ContentNode/Aside.vue';
1413
import CodeListing from 'docc-render/components/ContentNode/CodeListing.vue';
1514
import CodeVoice from 'docc-render/components/ContentNode/CodeVoice.vue';
@@ -1298,43 +1297,6 @@ describe('ContentNode', () => {
12981297
const reference = wrapper.find('.content');
12991298
expect(reference.isEmpty()).toBe(true);
13001299
});
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-
});
13381300
});
13391301

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

tests/unit/components/ContentNode/LinksBlock.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const createWrapper = ({ propsData, ...others } = {}) => shallowMount(LinksBlock
4141
describe('LinksBlock', () => {
4242
it('renders the LinksBlock', () => {
4343
const wrapper = createWrapper();
44-
expect(wrapper.find(TopicsLinkCardGrid).props()).toMatchObject({
44+
expect(wrapper.find(TopicsLinkCardGrid).props()).toEqual({
4545
items: [references.foo, references.bar],
4646
topicStyle: defaultProps.blockStyle,
4747
usePager: false,
@@ -60,7 +60,7 @@ describe('LinksBlock', () => {
6060
// they are two, because one does not have a reference object
6161
const linkBlocks = wrapper.findAll(TopicsLinkBlock);
6262
expect(linkBlocks).toHaveLength(2);
63-
expect(linkBlocks.at(0).props('topic')).toMatchObject(references.foo);
64-
expect(linkBlocks.at(1).props('topic')).toMatchObject(references.bar);
63+
expect(linkBlocks.at(0).props('topic')).toEqual(references.foo);
64+
expect(linkBlocks.at(1).props('topic')).toEqual(references.bar);
6565
});
6666
});

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

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

1111
import { shallowMount } from '@vue/test-utils';
12-
import AppStore from 'docc-render/stores/AppStore';
1312
import LinkableToken
1413
from 'docc-render/components/DocumentationTopic/PrimaryContent/DeclarationToken/LinkableToken.vue';
1514
import Reference from 'docc-render/components/ContentNode/Reference.vue';
1615

1716
describe('LinkableToken', () => {
1817
const foo = {
19-
identifier: 'doc://Foo/documentation/foo',
18+
identifier: 'foo',
2019
title: 'Foo',
2120
url: '/documentation/foo',
2221
};
@@ -71,44 +70,4 @@ describe('LinkableToken', () => {
7170
expect(link.props('url')).toBe(foo.url);
7271
expect(link.text()).toBe(foo.title);
7372
});
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-
});
11473
});

tests/unit/components/DocumentationTopic/Relationships.spec.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,18 @@ describe('Relationships', () => {
9191
expect(firstSection.props('anchor')).toBe(propsData.sections[0].anchor);
9292
const firstList = firstSection.find(List);
9393
expect(firstList.exists()).toBe(true);
94-
expect(firstList.props('symbols')[0]).toMatchObject(foo);
95-
expect(firstList.props('symbols')[1]).toMatchObject(bar);
94+
expect(firstList.props('symbols')).toEqual([
95+
foo,
96+
bar,
97+
]);
9698
expect(firstList.props('type')).toEqual('inheritsFrom');
9799

98100
const lastSection = sections.at(1);
99101
expect(lastSection.props('title')).toBe(propsData.sections[1].title);
100102
expect(lastSection.props('anchor')).toBe(null);
101103
const lastList = lastSection.find(List);
102104
expect(lastList.exists()).toBe(true);
103-
expect(lastList.props('symbols')[0]).toMatchObject(baz);
105+
expect(lastList.props('symbols')).toEqual([baz]);
104106
expect(firstList.props('type')).toEqual('inheritsFrom');
105107
});
106108
});

tests/unit/components/DocumentationTopic/TopicsLinkCardGridItem.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ describe('TopicsLinkCardGridItem', () => {
124124
},
125125
},
126126
});
127-
expect(wrapper.find(TopicTypeIcon).props('imageOverride')).toMatchObject(iconRef);
127+
expect(wrapper.find(TopicTypeIcon).props('imageOverride')).toEqual(iconRef);
128128
});
129129

130130
it('renders a TopicsLinkCardGridItem, in a none compact variant', async () => {

tests/unit/components/DocumentationTopic/TopicsTable.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ describe('TopicsTable', () => {
116116
const firstSectionBlocks = sections.at(0).findAll(TopicsLinkBlock);
117117
expect(firstSectionBlocks.length).toBe(1);
118118
expect(firstSectionBlocks.at(0).classes('topic')).toBe(true);
119-
expect(firstSectionBlocks.at(0).props()).toMatchObject({
119+
expect(firstSectionBlocks.at(0).props()).toEqual({
120120
topic: foo,
121121
isSymbolDeprecated: false,
122122
isSymbolBeta: false,
@@ -125,7 +125,7 @@ describe('TopicsTable', () => {
125125
const lastSectionBlocks = sections.at(1).findAll(TopicsLinkBlock);
126126
expect(lastSectionBlocks.length).toBe(1);
127127
expect(lastSectionBlocks.at(0).classes('topic')).toBe(true);
128-
expect(lastSectionBlocks.at(0).props()).toMatchObject({
128+
expect(lastSectionBlocks.at(0).props()).toEqual({
129129
topic: baz,
130130
isSymbolDeprecated: false,
131131
isSymbolBeta: false,
@@ -139,15 +139,15 @@ describe('TopicsTable', () => {
139139

140140
const firstGrid = sections.at(0).find(TopicsLinkCardGrid);
141141
expect(firstGrid.classes('topic')).toBe(true);
142-
expect(firstGrid.props()).toMatchObject({
142+
expect(firstGrid.props()).toEqual({
143143
topicStyle: TopicSectionsStyle.compactGrid,
144144
items: [foo],
145145
usePager: false,
146146
});
147147

148148
const secondGrid = sections.at(1).find(TopicsLinkCardGrid);
149149
expect(secondGrid.classes('topic')).toBe(true);
150-
expect(secondGrid.props()).toMatchObject({
150+
expect(secondGrid.props()).toEqual({
151151
topicStyle: TopicSectionsStyle.compactGrid,
152152
items: [baz],
153153
usePager: false,

tests/unit/components/ReferenceUrlProvider.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('ReferenceUrlProvider', () => {
5353

5454
const reference = references['doc://com.example.Test/tutorials/TechnologyX/Getting-Started'];
5555

56-
expect(assertProps).toMatchObject({
56+
expect(assertProps).toEqual({
5757
title: reference.title,
5858
url: reference.url,
5959
urlWithParams: `${reference.url}?context=foo`,

tests/unit/components/Tutorial/Hero.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe('Hero', () => {
112112
const metadata = wrapper.find(HeroMetadata);
113113
expect(metadata.props('estimatedTimeInMinutes')).toBe(estimatedTimeInMinutes);
114114
expect(metadata.props('projectFilesUrl')).toBe(projectFilesUrl);
115-
expect(metadata.props('xcodeRequirement')).toMatchObject(xcodeRequirementReference);
115+
expect(metadata.props('xcodeRequirement')).toEqual(xcodeRequirementReference);
116116
});
117117

118118
it('renders a div for the background and selects the light variant', () => {

0 commit comments

Comments
 (0)