@@ -5,33 +5,26 @@ import PropTypes from 'prop-types';
5
5
import unpackPlotProps from '../../lib/unpackPlotProps' ;
6
6
import { containerConnectedContextTypes } from '../../lib/connectToContainer' ;
7
7
8
- function childIsVisible ( child ) {
9
- const attrVisible = Boolean ( ( child . props . plotProps || { } ) . isVisible ) ;
10
- const sectionVisible = Boolean ( child . props [ 'data-section-child-visible' ] ) ;
11
- return attrVisible || sectionVisible ;
12
- }
13
-
14
8
export default class Section extends Component {
15
9
constructor ( props , context ) {
16
10
super ( props , context ) ;
17
11
18
12
this . children = null ;
19
13
this . menuPanel = null ;
14
+ this . sectionVisible = false ;
20
15
21
- this . processAndSetChildren ( context ) ;
16
+ this . processAndSetChildren ( props , context ) ;
22
17
}
23
18
24
19
componentWillReceiveProps ( nextProps , nextContext ) {
25
- this . processAndSetChildren ( nextContext ) ;
20
+ this . processAndSetChildren ( nextProps , nextContext ) ;
26
21
}
27
22
28
- processAndSetChildren ( context ) {
29
- let children = this . props . children ;
30
- if ( ! Array . isArray ( children ) ) {
31
- children = [ children ] ;
32
- }
23
+ processAndSetChildren ( nextProps , nextContext ) {
24
+ this . sectionVisible = false ;
33
25
34
- const attrChildren = [ ] ;
26
+ const children = React . Children . toArray ( nextProps . children ) ;
27
+ this . children = [ ] ;
35
28
let menuPanel = null ;
36
29
37
30
for ( let i = 0 ; i < children . length ; i ++ ) {
@@ -40,7 +33,8 @@ export default class Section extends Component {
40
33
continue ;
41
34
}
42
35
if ( child . type === MenuPanel ) {
43
- // Process the first menuPanel. Ignore the rest.
36
+ // Process the first menuPanel. Ignore the rest. MenuPanel does
37
+ // not affect visibility.
44
38
if ( menuPanel ) {
45
39
continue ;
46
40
}
@@ -55,38 +49,34 @@ export default class Section extends Component {
55
49
plotProps = child . plotProps ;
56
50
} else if ( isAttr ) {
57
51
if ( child . type . supplyPlotProps ) {
58
- plotProps = child . type . supplyPlotProps ( child . props , context ) ;
52
+ plotProps = child . type . supplyPlotProps ( child . props , nextContext ) ;
59
53
if ( child . type . modifyPlotProps ) {
60
- child . type . modifyPlotProps ( child . props , context , plotProps ) ;
54
+ child . type . modifyPlotProps ( child . props , nextContext , plotProps ) ;
61
55
}
62
56
} else {
63
- plotProps = unpackPlotProps ( child . props , context ) ;
57
+ plotProps = unpackPlotProps ( child . props , nextContext ) ;
64
58
}
65
59
66
60
// assign plotProps as a prop of children. If they are connectedToContainer
67
61
// it will see plotProps and skip recomputing them.
68
- newProps = { plotProps, key : i } ;
62
+ newProps = { plotProps} ;
63
+ this . sectionVisible = this . sectionVisible || plotProps . isVisible ;
64
+ this . children . push ( cloneElement ( child , newProps ) ) ;
69
65
} else if ( child . type === Info ) {
70
66
// Info panels do not change section visibility.
71
- newProps = { key : i , 'data-section- child-visible' : false } ;
67
+ this . children . push ( child ) ;
72
68
} else {
73
69
// custom UI currently forces section visibility.
74
- newProps = { key : i , 'data-section-child-visible' : true } ;
70
+ this . sectionVisible = true ;
71
+ this . children . push ( child ) ;
75
72
}
76
-
77
- const childProps = Object . assign ( newProps , child . props ) ;
78
- attrChildren . push ( cloneElement ( child , childProps ) ) ;
79
73
}
80
74
81
- this . children = attrChildren . length ? attrChildren : null ;
82
75
this . menuPanel = menuPanel ;
83
76
}
84
77
85
78
render ( ) {
86
- const hasVisibleChildren =
87
- this . children && this . children . some ( childIsVisible ) ;
88
-
89
- return hasVisibleChildren ? (
79
+ return this . sectionVisible ? (
90
80
< div className = "section" >
91
81
< div className = "section__heading" >
92
82
{ this . props . name }
0 commit comments