@@ -12,11 +12,29 @@ import PropTypes from 'prop-types';
12
12
import PrismCode from './PrismCode' ;
13
13
import { playgroundAction } from './events' ;
14
14
15
+ const frameworks = [ {
16
+ id : 'vanilla' ,
17
+ title : 'Vanilla JavaScript' ,
18
+ docsLink : 'https://cube.dev/docs/@cubejs-client-core'
19
+ } , {
20
+ id : 'angular' ,
21
+ title : 'Angular' ,
22
+ docsLink : 'https://cube.dev/docs/@cubejs-client-ngx'
23
+ } , {
24
+ id : 'react' ,
25
+ title : 'React'
26
+ } , {
27
+ id : 'vue' ,
28
+ title : 'Vue.js' ,
29
+ docsLink : 'https://cube.dev/docs/@cubejs-client-vue'
30
+ } ] ;
31
+
15
32
class ChartContainer extends React . Component {
16
33
constructor ( props ) {
17
34
super ( props ) ;
18
35
this . state = {
19
- showCode : false
36
+ showCode : false ,
37
+ framework : 'react'
20
38
} ;
21
39
}
22
40
@@ -60,7 +78,7 @@ class ChartContainer extends React.Component {
60
78
61
79
render ( ) {
62
80
const {
63
- redirectToDashboard, showCode, sandboxId, addingToDashboard
81
+ redirectToDashboard, showCode, sandboxId, addingToDashboard, framework
64
82
} = this . state ;
65
83
const {
66
84
resultSet,
@@ -99,7 +117,20 @@ class ChartContainer extends React.Component {
99
117
</ Menu >
100
118
) ;
101
119
120
+ const frameworkMenu = (
121
+ < Menu onClick = { ( e ) => this . setState ( { framework : e . key } ) } >
122
+ {
123
+ frameworks . map ( f => (
124
+ < Menu . Item key = { f . id } >
125
+ { f . title }
126
+ </ Menu . Item >
127
+ ) )
128
+ }
129
+ </ Menu >
130
+ ) ;
131
+
102
132
const currentLibraryItem = chartLibraries . find ( m => m . value === chartLibrary ) ;
133
+ const frameworkItem = frameworks . find ( m => m . id === framework ) ;
103
134
const extra = (
104
135
< form action = "https://codesandbox.io/api/v1/sandboxes/define" method = "POST" target = "_blank" >
105
136
< input type = "hidden" name = "parameters" value = { parameters } />
@@ -119,6 +150,12 @@ class ChartContainer extends React.Component {
119
150
{ addingToDashboard ? 'Creating app and installing modules...' : 'Add to Dashboard' }
120
151
</ Button >
121
152
) }
153
+ < Dropdown overlay = { frameworkMenu } >
154
+ < Button size = "small" >
155
+ { frameworkItem && frameworkItem . title }
156
+ < Icon type = "down" />
157
+ </ Button >
158
+ </ Dropdown >
122
159
< Dropdown overlay = { chartLibrariesMenu } >
123
160
< Button size = "small" >
124
161
{ currentLibraryItem && currentLibraryItem . title }
@@ -159,8 +196,23 @@ class ChartContainer extends React.Component {
159
196
</ form >
160
197
) ;
161
198
162
- const code = ( ) => {
163
- if ( showCode === 'code' ) {
199
+ const renderChart = ( ) => {
200
+ if ( frameworkItem && frameworkItem . docsLink ) {
201
+ return (
202
+ < h2 style = { { padding : 24 , textAlign : 'center' } } >
203
+ We do not support
204
+ { frameworkItem . title }
205
+ code generation here yet.
206
+ < br />
207
+ Please refer to
208
+ < a href = { frameworkItem . docsLink } target = "_blank" >
209
+ { frameworkItem . title }
210
+ docs
211
+ </ a >
212
+ to see on how to use it with Cube.js.
213
+ </ h2 >
214
+ ) ;
215
+ } else if ( showCode === 'code' ) {
164
216
return < PrismCode code = { codeExample } /> ;
165
217
} else if ( showCode === 'sql' ) {
166
218
return (
@@ -172,7 +224,7 @@ class ChartContainer extends React.Component {
172
224
/>
173
225
) ;
174
226
}
175
- return null ;
227
+ return render ( { resultSet , error , sandboxId } ) ;
176
228
} ;
177
229
178
230
return hideActions ? render ( { resultSet, error, sandboxId } ) : (
@@ -181,7 +233,7 @@ class ChartContainer extends React.Component {
181
233
style = { { minHeight : 420 } }
182
234
extra = { extra }
183
235
>
184
- { showCode ? code ( ) : render ( { resultSet , error , sandboxId } ) }
236
+ { renderChart ( ) }
185
237
</ Card >
186
238
) ;
187
239
}
0 commit comments