Skip to content

Commit

Permalink
Merge pull request #1664 from danielsneijers/1588-fix-leftpanel-init-…
Browse files Browse the repository at this point in the history
…proptype-warning

Don’t render leftpanel stories tree if stories are empty
  • Loading branch information
ndelangen authored Aug 16, 2017
2 parents d486e17 + 6b3cd3e commit d2be2c8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/ui/src/modules/ui/components/left_panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const storyProps = [
'sidebarAnimations',
];

function hierarchyContainsStories(storiesHierarchy) {
return storiesHierarchy && storiesHierarchy.map.size
}

// eslint-disable-next-line react/prefer-stateless-function
class LeftPanel extends Component {
render() {
Expand All @@ -46,7 +50,9 @@ class LeftPanel extends Component {
onChange={text => onStoryFilter(text)}
/>
<div style={scrollStyle}>
{storiesHierarchy ? <Stories {...pick(this.props, storyProps)} /> : null}
{hierarchyContainsStories(storiesHierarchy)
? <Stories {...pick(this.props, storyProps)} />
: null}
</div>
</div>
);
Expand Down
7 changes: 7 additions & 0 deletions lib/ui/src/modules/ui/components/left_panel/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ describe('manager.ui.components.left_panel.index', () => {
});
});

test('should not render stories if storiesHierarchy exists but is empty', () => {
const storiesHierarchy = createHierarchy([]);
const wrap = shallow(<LeftPanel storiesHierarchy={storiesHierarchy} />);

expect(wrap.find(Stories).exists()).toBe(false);
});

describe('onStoryFilter prop', () => {
test('should set filter as an empty text on TextFilter.onClear', () => {
const onStoryFilter = jest.fn();
Expand Down

0 comments on commit d2be2c8

Please sign in to comment.