@@ -2,6 +2,7 @@ import PropTypes from 'prop-types';
22import React , { cloneElement , Component } from 'react' ;
33import SidebarGroup from './sidebar/SidebarGroup' ;
44import { bem } from 'lib' ;
5+ import SingleSidebarItem from './containers/SingleSidebarItem' ;
56
67class PanelsWithSidebar extends Component {
78 constructor ( props ) {
@@ -15,57 +16,59 @@ class PanelsWithSidebar extends Component {
1516 } ;
1617
1718 this . setPanel = this . setPanel . bind ( this ) ;
18- this . renderGroup = this . renderGroup . bind ( this ) ;
19+ this . renderSection = this . renderSection . bind ( this ) ;
1920 }
2021
2122 setPanel ( group , panel ) {
2223 this . setState ( { group, panel} ) ;
2324 }
2425
25- renderGroup ( group , i ) {
26+ renderSection ( section , i ) {
27+ if ( section . type && section . type === SingleSidebarItem ) {
28+ const sectionWithKey = cloneElement ( section , { key : i } ) ;
29+ return < div > { sectionWithKey } </ div > ;
30+ }
2631 return (
2732 < SidebarGroup
2833 key = { i }
2934 selectedGroup = { this . state . group }
3035 selectedPanel = { this . state . panel }
31- group = { group . name }
32- panels = { group . panels }
36+ group = { section . name }
37+ panels = { section . panels }
3338 onChangeGroup = { this . setPanel }
3439 />
3540 ) ;
3641 }
3742
3843 computeMenuOptions ( props ) {
39- let obj , child , group , name ;
40-
41- let { children} = props ;
42-
43- if ( ! Array . isArray ( children ) ) {
44- children = [ children ] ;
45- }
46-
44+ const { children} = props ;
45+ const sections = [ ] ;
4746 const groupLookup = { } ;
4847 let groupIndex ;
49- const groups = [ ] ;
50-
51- for ( let i = 0 ; i < children . length ; i ++ ) {
52- child = children [ i ] ;
53- group = child . props . group ;
54- name = child . props . name ;
55-
56- if ( groupLookup . hasOwnProperty ( group ) ) {
57- groupIndex = groupLookup [ group ] ;
58- obj = groups [ groupIndex ] ;
59- } else {
60- groupLookup [ group ] = groups . length ;
61- obj = { name : group , panels : [ ] } ;
62- groups . push ( obj ) ;
48+
49+ React . Children . forEach ( children , child => {
50+ const group = child . props . group ;
51+ const name = child . props . name ;
52+
53+ if ( group && name ) {
54+ let obj ;
55+ if ( groupLookup . hasOwnProperty ( group ) ) {
56+ groupIndex = groupLookup [ group ] ;
57+ obj = sections [ groupIndex ] ;
58+ } else {
59+ groupLookup [ group ] = sections . length ;
60+ obj = { name : group , panels : [ ] } ;
61+ sections . push ( obj ) ;
62+ }
63+ obj . panels . push ( name ) ;
6364 }
6465
65- obj . panels . push ( name ) ;
66- }
66+ if ( child . type === SingleSidebarItem ) {
67+ sections . push ( child ) ;
68+ }
69+ } ) ;
6770
68- return groups ;
71+ return sections ;
6972 }
7073
7174 render ( ) {
@@ -77,7 +80,7 @@ class PanelsWithSidebar extends Component {
7780
7881 return (
7982 < div className = { bem ( 'plotly-editor' , 'wrapper' ) } >
80- < div className = { bem ( 'sidebar' ) } > { menuOpts . map ( this . renderGroup ) } </ div >
83+ < div className = { bem ( 'sidebar' ) } > { menuOpts . map ( this . renderSection ) } </ div >
8184 { children . map ( ( child , i ) =>
8285 cloneElement ( child , {
8386 key : i ,
0 commit comments