From 7addf9f69d45231c7513274269e945e8ac19167c Mon Sep 17 00:00:00 2001 From: Daniel Sneijers Date: Tue, 15 Aug 2017 11:49:51 +0200 Subject: [PATCH 1/2] =?UTF-8?q?don=E2=80=99t=20render=20leftpanel=20storie?= =?UTF-8?q?s=20tree=20if=20stories=20are=20empty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ui/src/modules/ui/components/left_panel/index.js | 4 +++- lib/ui/src/modules/ui/components/left_panel/index.test.js | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/ui/src/modules/ui/components/left_panel/index.js b/lib/ui/src/modules/ui/components/left_panel/index.js index 78b7f11da6d..16edae1b050 100755 --- a/lib/ui/src/modules/ui/components/left_panel/index.js +++ b/lib/ui/src/modules/ui/components/left_panel/index.js @@ -46,7 +46,9 @@ class LeftPanel extends Component { onChange={text => onStoryFilter(text)} />
- {storiesHierarchy ? : null} + {storiesHierarchy && storiesHierarchy.map.size + ? + : null}
); diff --git a/lib/ui/src/modules/ui/components/left_panel/index.test.js b/lib/ui/src/modules/ui/components/left_panel/index.test.js index 3a2e4b219ed..03c3e2da6aa 100755 --- a/lib/ui/src/modules/ui/components/left_panel/index.test.js +++ b/lib/ui/src/modules/ui/components/left_panel/index.test.js @@ -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(); + + 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(); From 4806e8b83cbc1b2e65ab74d7296535bc3e953d4f Mon Sep 17 00:00:00 2001 From: Daniel Sneijers Date: Tue, 15 Aug 2017 13:29:25 +0200 Subject: [PATCH 2/2] extract empty stories tree check to seperate function --- lib/ui/src/modules/ui/components/left_panel/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/ui/src/modules/ui/components/left_panel/index.js b/lib/ui/src/modules/ui/components/left_panel/index.js index 16edae1b050..2529ed4238c 100755 --- a/lib/ui/src/modules/ui/components/left_panel/index.js +++ b/lib/ui/src/modules/ui/components/left_panel/index.js @@ -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() { @@ -46,7 +50,7 @@ class LeftPanel extends Component { onChange={text => onStoryFilter(text)} />
- {storiesHierarchy && storiesHierarchy.map.size + {hierarchyContainsStories(storiesHierarchy) ? : null}