@@ -7,19 +7,22 @@ import {traceTypeToPlotlyInitFigure, renderTraceIcon, plotlyTraceToCustomTrace}
77
88const renderActionItems = ( actionItems , item ) =>
99 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+ )
2326 : null ;
2427
2528const Item = ( { item, active, handleClick, actions, showActions, complex} ) => {
@@ -28,10 +31,7 @@ const Item = ({item, active, handleClick, actions, showActions, complex}) => {
2831 const ComplexIcon = renderTraceIcon ( icon ? icon : value , 'TraceType' ) ;
2932
3033 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 } >
3535 < div className = "trace-item__actions" >
3636 { actions && showActions ? renderActionItems ( actions , item ) : null }
3737 </ div >
@@ -52,7 +52,29 @@ const Item = ({item, active, handleClick, actions, showActions, complex}) => {
5252 ) ;
5353} ;
5454
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+
5567class 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+
5678 selectAndClose ( value ) {
5779 const {
5880 updateContainer,
@@ -72,21 +94,38 @@ class TraceTypeSelector extends Component {
7294 }
7395
7496 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+
76105 return [
77106 {
78107 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+ ) ) ,
80117 icon : < SearchIcon /> ,
81118 } ,
82119 {
83120 label : _ ( 'View tutorials on this chart type.' ) ,
84- href : '#' ,
121+ onClick :
122+ chartHelp [ value ] &&
123+ ( e => onClick ( e , ( ) => window . open ( chartHelp [ value ] . helpDoc , '_blank' ) ) ) ,
85124 icon : < ThumnailViewIcon /> ,
86125 } ,
87126 {
88127 label : _ ( 'See a basic example.' ) ,
89- href : '#' ,
128+ onClick : chartHelp [ value ] && ( e => onClick ( e , chartHelp [ value ] . examplePlot ) ) ,
90129 icon : < GraphIcon /> ,
91130 } ,
92131 ] ;
@@ -98,6 +137,7 @@ class TraceTypeSelector extends Component {
98137 traceTypesConfig : { traces, categories, complex} ,
99138 mapBoxAccess,
100139 localize : _ ,
140+ chartHelp,
101141 } = this . context ;
102142
103143 return categories ( _ ) . map ( ( category , i ) => {
@@ -131,8 +171,8 @@ class TraceTypeSelector extends Component {
131171 active = { fullValue === item . value }
132172 item = { item }
133173 actions = { this . actions }
134- showActions = { false }
135174 handleClick = { ( ) => this . selectAndClose ( item . value ) }
175+ showActions = { Boolean ( chartHelp ) }
136176 />
137177 ) ) }
138178 </ div >
@@ -193,6 +233,20 @@ class TraceTypeSelector extends Component {
193233 }
194234}
195235
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+
196250export class TraceTypeSelectorButton extends Component {
197251 render ( ) {
198252 const {
@@ -209,7 +263,7 @@ export class TraceTypeSelectorButton extends Component {
209263 const Icon = renderTraceIcon ( icon ? icon : value ) ;
210264
211265 return (
212- < div className = "trace-type-select-button" onClick = { handleClick ? ( ) => handleClick ( ) : null } >
266+ < div className = "trace-type-select-button" onClick = { handleClick ? handleClick : null } >
213267 < div className = "trace-type-select-button__icon" >
214268 < Icon />
215269 </ div >
@@ -219,18 +273,6 @@ export class TraceTypeSelectorButton extends Component {
219273 }
220274}
221275
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- } ;
234276TraceTypeSelectorButton . propTypes = {
235277 handleClick : PropTypes . func . isRequired ,
236278 container : PropTypes . object ,
@@ -239,16 +281,5 @@ TraceTypeSelectorButton.propTypes = {
239281TraceTypeSelectorButton . contextTypes = {
240282 localize : PropTypes . func ,
241283} ;
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- } ;
253284
254285export default TraceTypeSelector ;
0 commit comments