Skip to content

Commit 6d2a842

Browse files
QuietMisdreavushqhhuangmarinaaisa
authored
don't display declaration platforms if they're all the same (#717) rdar://130985928
don't display declaration platforms if they're all the same (#717) rdar://130985928 --------- Co-authored-by: Hanqing Huang <[email protected]> Co-authored-by: Marina Aísa <[email protected]>
1 parent 0cb8d7e commit 6d2a842

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

src/components/DocumentationTopic/PrimaryContent/Declaration.vue

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!--
22
This source file is part of the Swift.org open source project
33
4-
Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
4+
Copyright (c) 2021-2024 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66
77
See https://swift.org/LICENSE.txt for license information
@@ -53,6 +53,7 @@ import DeclarationSourceLink
5353
5454
import { ChangeTypes } from 'docc-render/constants/Changes';
5555
import { multipleLinesClass } from 'docc-render/constants/multipleLines';
56+
import { isEqual } from 'docc-render/utils/arrays';
5657
5758
export default {
5859
name: 'Declaration',
@@ -89,12 +90,13 @@ export default {
8990
computed: {
9091
/**
9192
* Show the captions of DeclarationGroup without changes
92-
* when there are more than one declarations
93+
* when there are multiple sets of platforms among the
94+
* declarations.
9395
* @returns {boolean}
9496
*/
95-
hasPlatformVariants() {
96-
return this.declarations.length > 1;
97-
},
97+
hasPlatformVariants: ({ declarations }) => !(declarations.every(
98+
({ platforms }) => isEqual(platforms, declarations[0].platforms),
99+
)),
98100
/**
99101
* Returns whether there are declaration changes.
100102
* @returns {boolean}
@@ -153,4 +155,8 @@ export default {
153155
.conditional-constraints {
154156
margin-top: var(--declaration-conditional-constraints-margin, 20px);
155157
}
158+
159+
.declaration-list:not(:first-child) {
160+
margin-top: var(--declaration-conditional-constraints-margin, 20px);
161+
}
156162
</style>

tests/unit/components/DocumentationTopic/PrimaryContent/Declaration.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,31 @@ describe('Declaration', () => {
161161
expect(labels.at(1).props('shouldCaption')).toBe(true);
162162
});
163163

164+
it('does not render captions when multiple declarations have the same platforms', () => {
165+
const declarations = [
166+
propsData.declarations[0],
167+
{
168+
platforms: [
169+
'macOS',
170+
],
171+
tokens: [
172+
{
173+
kind: TokenKind.keyword,
174+
text: 'let',
175+
},
176+
...propsData.declarations[0].tokens.slice(1),
177+
],
178+
},
179+
];
180+
181+
wrapper.setProps({ declarations });
182+
183+
const labels = wrapper.findAll(DeclarationList);
184+
expect(labels.length).toBe(declarations.length);
185+
expect(labels.at(0).props('shouldCaption')).toBe(false);
186+
expect(labels.at(1).props('shouldCaption')).toBe(false);
187+
});
188+
164189
it('renders a `DeclarationDiff` when there are API changes for current and previous and collapsed other declaration list', () => {
165190
// no DeclarationDiff if no changes
166191
expect(wrapper.find(DeclarationDiff).exists()).toBe(false);

0 commit comments

Comments
 (0)