Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don’t render leftpanel stories tree if stories are empty #1664

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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