Skip to content

Commit 83f1826

Browse files
elevatebartsapegin
authored andcommitted
Fix: Don't show empty sidebar (styleguidist#1423)
1 parent 8678c56 commit 83f1826

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

src/client/rsg-components/TableOfContents/TableOfContents.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ export default class TableOfContents extends Component {
4545
// we need to make sure not to loose the subsections.
4646
// We will treat those subsecttions as the new roots.
4747
const firstLevel =
48-
sections.length === 1 ? sections[0].sections || sections[0].components : sections;
48+
sections.length === 1
49+
? // only use subsections if there actually are subsections
50+
sections[0].sections && sections[0].sections.length
51+
? sections[0].sections
52+
: sections[0].components
53+
: sections;
4954
const filtered = filterSectionsByName(firstLevel, searchTerm);
5055

5156
return this.renderLevel(filtered, useRouterLinks);

src/client/rsg-components/TableOfContents/TableOfContents.spec.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,63 @@ it('should call a callback when input value changed', () => {
119119

120120
expect(onSearchTermChange).toBeCalledWith(newSearchTerm);
121121
});
122+
123+
it('should render content of subsections of a section that has no components', () => {
124+
const actual = shallow(
125+
<TableOfContents
126+
sections={[{ sections: [{ contents: 'intro.md' }, { contents: 'chapter.md' }] }]}
127+
/>
128+
);
129+
130+
expect(actual.find('ComponentsList').prop('items')).toMatchInlineSnapshot(`
131+
Array [
132+
Object {
133+
"components": Array [],
134+
"content": false,
135+
"contents": "intro.md",
136+
"heading": false,
137+
"sections": Array [],
138+
},
139+
Object {
140+
"components": Array [],
141+
"content": false,
142+
"contents": "chapter.md",
143+
"heading": false,
144+
"sections": Array [],
145+
},
146+
]
147+
`);
148+
});
149+
150+
it('should render components of a single top section as root', () => {
151+
const actual = shallow(<TableOfContents sections={[{ components }]} />);
152+
153+
expect(actual.find('ComponentsList').prop('items')).toMatchInlineSnapshot(`
154+
Array [
155+
Object {
156+
"components": Array [],
157+
"content": false,
158+
"heading": false,
159+
"name": "Button",
160+
"sections": Array [],
161+
"slug": "button",
162+
},
163+
Object {
164+
"components": Array [],
165+
"content": false,
166+
"heading": false,
167+
"name": "Input",
168+
"sections": Array [],
169+
"slug": "input",
170+
},
171+
Object {
172+
"components": Array [],
173+
"content": false,
174+
"heading": false,
175+
"name": "Textarea",
176+
"sections": Array [],
177+
"slug": "textarea",
178+
},
179+
]
180+
`);
181+
});

0 commit comments

Comments
 (0)