@@ -32,6 +32,31 @@ export default class ExplorerActiveChartButton extends React.Component {
32
32
this . node = ReactDOM . findDOMNode ( this ) ;
33
33
}
34
34
35
+ componentWillMount ( ) {
36
+ // Used to close query picker
37
+ document . addEventListener ( 'mousedown' , this . handleClick . bind ( this ) , false )
38
+ }
39
+
40
+ componentWillUnmount ( ) {
41
+ // Used to close query picker
42
+ document . removeEventListener ( 'mousedown' , this . handleClick . bind ( this ) , false )
43
+ }
44
+
45
+ // Intercept all click events
46
+ handleClick ( e ) {
47
+ // Verify if the click is outside the picker
48
+ if ( this . state . open && this . parentNode && ! this . parentNode . contains ( e . target ) ) {
49
+ // Click target is not inside the configuration dropdown
50
+ if ( e . target . parentNode && ! e . target . parentNode . className . match ( 'menu' ) )
51
+ this . handleClosePopover ( ) // Close picker
52
+ }
53
+ }
54
+
55
+ // Set parent node
56
+ setParentNode ( node ) {
57
+ this . parentNode = node
58
+ }
59
+
35
60
handleCheckbox ( ) {
36
61
let nextActiveState = ! this . state . active ;
37
62
this . props . onToggle ( nextActiveState ) ;
@@ -40,16 +65,36 @@ export default class ExplorerActiveChartButton extends React.Component {
40
65
} ) ;
41
66
}
42
67
43
- handleSave ( query ) {
68
+ handleSave ( query , saveOnDatabase ) {
44
69
this . setState ( { open : false } ) ;
45
- this . props . onSave ( query ) ;
70
+ this . props . onSave ( query , saveOnDatabase ) ;
46
71
}
47
72
48
73
handleDismiss ( ) {
49
74
this . setState ( { open : false } ) ;
50
75
this . props . onDismiss ( ) ;
51
76
}
52
77
78
+ handleOpenPopover ( ) {
79
+ let position = Position . inDocument ( this . node ) ;
80
+ let align = Directions . LEFT ;
81
+ if ( position . x > 700 ) {
82
+ position . x += this . node . clientWidth ;
83
+ align = Directions . RIGHT ;
84
+ }
85
+ // Add the button height to the picker appear on the bottom
86
+ position . y += this . node . clientHeight
87
+ this . setState ( {
88
+ open : ! this . state . open ,
89
+ position,
90
+ align
91
+ } ) ;
92
+ }
93
+
94
+ handleClosePopover ( ) {
95
+ this . setState ( { open : false } ) ;
96
+ }
97
+
53
98
renderButton ( ) {
54
99
let checkMark = null ;
55
100
let color = '#343445' ;
@@ -63,19 +108,7 @@ export default class ExplorerActiveChartButton extends React.Component {
63
108
dropdown = (
64
109
< div
65
110
className = { [ styles . rightArrow , verticalCenter ] . join ( ' ' ) }
66
- onClick = { ( ) => {
67
- let position = Position . inDocument ( this . node ) ;
68
- let align = Directions . LEFT ;
69
- if ( position . x > 700 ) {
70
- position . x += this . node . clientWidth ;
71
- align = Directions . RIGHT ;
72
- }
73
- this . setState ( {
74
- open : ! this . state . open ,
75
- position,
76
- align
77
- } ) ;
78
- } } />
111
+ onClick = { this . handleOpenPopover . bind ( this ) } />
79
112
) ;
80
113
}
81
114
@@ -90,7 +123,11 @@ export default class ExplorerActiveChartButton extends React.Component {
90
123
} } >
91
124
{ checkMark }
92
125
</ div >
93
- < div className = { styles . label } > { this . props . query . name } </ div >
126
+ < div
127
+ className = { styles . label }
128
+ onClick = { this . handleOpenPopover . bind ( this ) } >
129
+ { this . props . query . name }
130
+ </ div >
94
131
{ dropdown }
95
132
</ div >
96
133
) ;
@@ -110,12 +147,17 @@ export default class ExplorerActiveChartButton extends React.Component {
110
147
111
148
popover = (
112
149
< Popover
113
- fixed = { false }
150
+ fixed = { true }
114
151
position = { this . state . position } >
115
- < div className = { classes . join ( ' ' ) } >
116
- { content }
117
- < div className = { styles . callout } style = { calloutStyle } > </ div >
152
+ < div
153
+ ref = { this . setParentNode . bind ( this ) }
154
+ className = { classes . join ( ' ' ) } >
155
+ < div
156
+ className = { styles . callout }
157
+ style = { calloutStyle } >
158
+ </ div >
118
159
< ExplorerQueryComposer
160
+ index = { this . props . index || 0 }
119
161
isNew = { false }
120
162
query = { this . props . query }
121
163
isTimeSeries = { this . props . isTimeSeries }
0 commit comments