@@ -7,19 +7,22 @@ import {traceTypeToPlotlyInitFigure, renderTraceIcon, plotlyTraceToCustomTrace}
7
7
8
8
const renderActionItems = ( actionItems , item ) =>
9
9
actionItems
10
- ? actionItems ( item ) . map ( ( action , i ) => (
11
- < a
12
- className = "trace-item__actions__item"
13
- key = { i }
14
- aria-label = { action . label }
15
- data-microtip-position = { `top-left` }
16
- role = "tooltip"
17
- href = { action . href }
18
- target = "_blank"
19
- >
20
- { action . icon }
21
- </ a >
22
- ) )
10
+ ? actionItems ( item ) . map (
11
+ ( action , i ) =>
12
+ ! action . onClick ? null : (
13
+ < a
14
+ className = "trace-item__actions__item"
15
+ key = { i }
16
+ aria-label = { action . label }
17
+ data-microtip-position = { `top-left` }
18
+ role = "tooltip"
19
+ onClick = { action . onClick }
20
+ target = "_blank"
21
+ >
22
+ { action . icon }
23
+ </ a >
24
+ )
25
+ )
23
26
: null ;
24
27
25
28
const Item = ( { item, active, handleClick, actions, showActions, complex} ) => {
@@ -28,10 +31,7 @@ const Item = ({item, active, handleClick, actions, showActions, complex}) => {
28
31
const ComplexIcon = renderTraceIcon ( icon ? icon : value , 'TraceType' ) ;
29
32
30
33
return (
31
- < div
32
- className = { `trace-item${ active ? ' trace-item--active' : '' } ` }
33
- onClick = { ( ) => handleClick ( ) }
34
- >
34
+ < div className = { `trace-item${ active ? ' trace-item--active' : '' } ` } onClick = { handleClick } >
35
35
< div className = "trace-item__actions" >
36
36
{ actions && showActions ? renderActionItems ( actions , item ) : null }
37
37
</ div >
@@ -52,7 +52,29 @@ const Item = ({item, active, handleClick, actions, showActions, complex}) => {
52
52
) ;
53
53
} ;
54
54
55
+ Item . propTypes = {
56
+ item : PropTypes . object ,
57
+ active : PropTypes . bool ,
58
+ complex : PropTypes . bool ,
59
+ handleClick : PropTypes . func ,
60
+ actions : PropTypes . func ,
61
+ showActions : PropTypes . bool ,
62
+ } ;
63
+ Item . contextTypes = {
64
+ localize : PropTypes . func ,
65
+ } ;
66
+
55
67
class TraceTypeSelector extends Component {
68
+ constructor ( props ) {
69
+ super ( props ) ;
70
+
71
+ this . selectAndClose = this . selectAndClose . bind ( this ) ;
72
+ this . actions = this . actions . bind ( this ) ;
73
+ this . renderCategories = this . renderCategories . bind ( this ) ;
74
+ this . renderGrid = this . renderGrid . bind ( this ) ;
75
+ this . renderSingleBlock = this . renderSingleBlock . bind ( this ) ;
76
+ }
77
+
56
78
selectAndClose ( value ) {
57
79
const {
58
80
updateContainer,
@@ -72,21 +94,38 @@ class TraceTypeSelector extends Component {
72
94
}
73
95
74
96
actions ( { value} ) {
75
- const { localize : _ } = this . context ;
97
+ const { localize : _ , chartHelp} = this . context ;
98
+
99
+ const onClick = ( e , func ) => {
100
+ e . stopPropagation ( ) ;
101
+ func ( ) ;
102
+ this . context . handleClose ( ) ;
103
+ } ;
104
+
76
105
return [
77
106
{
78
107
label : _ ( 'Charts like this by Plotly users.' ) ,
79
- href : `https://plot.ly/feed/?q=plottype:${ value } ` ,
108
+ onClick :
109
+ chartHelp [ value ] &&
110
+ ( e =>
111
+ onClick ( e , ( ) =>
112
+ window . open (
113
+ `https://plot.ly/feed/?q=${ chartHelp [ value ] ? chartHelp [ value ] . feedQuery : value } ` ,
114
+ '_blank'
115
+ )
116
+ ) ) ,
80
117
icon : < SearchIcon /> ,
81
118
} ,
82
119
{
83
120
label : _ ( 'View tutorials on this chart type.' ) ,
84
- href : '#' ,
121
+ onClick :
122
+ chartHelp [ value ] &&
123
+ ( e => onClick ( e , ( ) => window . open ( chartHelp [ value ] . helpDoc , '_blank' ) ) ) ,
85
124
icon : < ThumnailViewIcon /> ,
86
125
} ,
87
126
{
88
127
label : _ ( 'See a basic example.' ) ,
89
- href : '#' ,
128
+ onClick : chartHelp [ value ] && ( e => onClick ( e , chartHelp [ value ] . examplePlot ) ) ,
90
129
icon : < GraphIcon /> ,
91
130
} ,
92
131
] ;
@@ -98,6 +137,7 @@ class TraceTypeSelector extends Component {
98
137
traceTypesConfig : { traces, categories, complex} ,
99
138
mapBoxAccess,
100
139
localize : _ ,
140
+ chartHelp,
101
141
} = this . context ;
102
142
103
143
return categories ( _ ) . map ( ( category , i ) => {
@@ -131,8 +171,8 @@ class TraceTypeSelector extends Component {
131
171
active = { fullValue === item . value }
132
172
item = { item }
133
173
actions = { this . actions }
134
- showActions = { false }
135
174
handleClick = { ( ) => this . selectAndClose ( item . value ) }
175
+ showActions = { Boolean ( chartHelp ) }
136
176
/>
137
177
) ) }
138
178
</ div >
@@ -193,6 +233,20 @@ class TraceTypeSelector extends Component {
193
233
}
194
234
}
195
235
236
+ TraceTypeSelector . propTypes = {
237
+ updateContainer : PropTypes . func ,
238
+ fullValue : PropTypes . string ,
239
+ fullContainer : PropTypes . object ,
240
+ glByDefault : PropTypes . bool ,
241
+ } ;
242
+ TraceTypeSelector . contextTypes = {
243
+ traceTypesConfig : PropTypes . object ,
244
+ handleClose : PropTypes . func ,
245
+ localize : PropTypes . func ,
246
+ mapBoxAccess : PropTypes . bool ,
247
+ chartHelp : PropTypes . object ,
248
+ } ;
249
+
196
250
export class TraceTypeSelectorButton extends Component {
197
251
render ( ) {
198
252
const {
@@ -209,7 +263,7 @@ export class TraceTypeSelectorButton extends Component {
209
263
const Icon = renderTraceIcon ( icon ? icon : value ) ;
210
264
211
265
return (
212
- < div className = "trace-type-select-button" onClick = { handleClick ? ( ) => handleClick ( ) : null } >
266
+ < div className = "trace-type-select-button" onClick = { handleClick ? handleClick : null } >
213
267
< div className = "trace-type-select-button__icon" >
214
268
< Icon />
215
269
</ div >
@@ -219,18 +273,6 @@ export class TraceTypeSelectorButton extends Component {
219
273
}
220
274
}
221
275
222
- TraceTypeSelector . propTypes = {
223
- updateContainer : PropTypes . func ,
224
- fullValue : PropTypes . string ,
225
- fullContainer : PropTypes . object ,
226
- glByDefault : PropTypes . bool ,
227
- } ;
228
- TraceTypeSelector . contextTypes = {
229
- traceTypesConfig : PropTypes . object ,
230
- handleClose : PropTypes . func ,
231
- localize : PropTypes . func ,
232
- mapBoxAccess : PropTypes . bool ,
233
- } ;
234
276
TraceTypeSelectorButton . propTypes = {
235
277
handleClick : PropTypes . func . isRequired ,
236
278
container : PropTypes . object ,
@@ -239,16 +281,5 @@ TraceTypeSelectorButton.propTypes = {
239
281
TraceTypeSelectorButton . contextTypes = {
240
282
localize : PropTypes . func ,
241
283
} ;
242
- Item . propTypes = {
243
- item : PropTypes . object ,
244
- active : PropTypes . bool ,
245
- complex : PropTypes . bool ,
246
- handleClick : PropTypes . func ,
247
- actions : PropTypes . func ,
248
- showActions : PropTypes . bool ,
249
- } ;
250
- Item . contextTypes = {
251
- localize : PropTypes . func ,
252
- } ;
253
284
254
285
export default TraceTypeSelector ;
0 commit comments