1
1
/* globals window */
2
2
import React , { Component } from 'react' ;
3
- import { Spin , Button , Alert } from 'antd' ;
4
- import { Link } from "react-router-dom" ;
3
+ import {
4
+ Spin , Button , Alert , Menu , Dropdown , Icon , Form
5
+ } from 'antd' ;
5
6
import DashboardSource from "./DashboardSource" ;
6
7
import fetch from './playgroundFetch' ;
8
+ import { frameworks } from "./ChartContainer" ;
9
+ import { playgroundAction } from "./events" ;
10
+ import { chartLibraries } from "./ChartRenderer" ;
7
11
8
12
const Frame = ( { children } ) => (
9
13
< div style = { { textAlign : 'center' , marginTop : 50 } } >
@@ -12,15 +16,18 @@ const Frame = ({ children }) => (
12
16
) ;
13
17
14
18
const Hint = ( ) => (
15
- < p style = { { width : 450 , margin : "20px auto" } } >
19
+ < p style = { { width : 450 , margin : "20px auto" } } >
16
20
Dashboard App is a convenient way to setup and deploy frontend app to work with Cube.js backend. You can learn more about it the < a href = "https://cube.dev/docs/dashboard-app" target = "_blankl" > Cube.js docs</ a > .
17
21
</ p >
18
22
) ;
19
23
20
24
class DashboardPage extends Component {
21
25
constructor ( props ) {
22
26
super ( props ) ;
23
- this . state = { } ;
27
+ this . state = {
28
+ chartLibrary : chartLibraries [ 0 ] . value ,
29
+ framework : 'react'
30
+ } ;
24
31
}
25
32
26
33
async componentDidMount ( ) {
@@ -29,11 +36,12 @@ class DashboardPage extends Component {
29
36
}
30
37
31
38
async loadDashboard ( createApp ) {
39
+ const { chartLibrary } = this . state ;
32
40
this . setState ( {
33
41
appCode : null ,
34
42
loadError : null
35
43
} ) ;
36
- await this . dashboardSource . load ( createApp ) ;
44
+ await this . dashboardSource . load ( createApp , { chartLibrary } ) ;
37
45
this . setState ( {
38
46
dashboardStarting : false ,
39
47
appCode : ! this . dashboardSource . loadError && this . dashboardSource . dashboardAppCode ( ) ,
@@ -59,6 +67,44 @@ class DashboardPage extends Component {
59
67
}
60
68
61
69
render ( ) {
70
+ const { chartLibrary, framework } = this . state ;
71
+ const currentLibraryItem = chartLibraries . find ( m => m . value === chartLibrary ) ;
72
+ const frameworkItem = frameworks . find ( m => m . id === framework ) ;
73
+
74
+ const chartLibrariesMenu = (
75
+ < Menu
76
+ onClick = { ( e ) => {
77
+ playgroundAction ( 'Set Chart Library' , { chartLibrary : e . key } ) ;
78
+ this . setState ( { chartLibrary : e . key } ) ;
79
+ } }
80
+ >
81
+ {
82
+ chartLibraries . map ( library => (
83
+ < Menu . Item key = { library . value } >
84
+ { library . title }
85
+ </ Menu . Item >
86
+ ) )
87
+ }
88
+ </ Menu >
89
+ ) ;
90
+
91
+ const frameworkMenu = (
92
+ < Menu
93
+ onClick = { ( e ) => {
94
+ playgroundAction ( 'Set Framework' , { framework : e . key } ) ;
95
+ this . setState ( { framework : e . key } ) ;
96
+ } }
97
+ >
98
+ {
99
+ frameworks . map ( f => (
100
+ < Menu . Item key = { f . id } >
101
+ { f . title }
102
+ </ Menu . Item >
103
+ ) )
104
+ }
105
+ </ Menu >
106
+ ) ;
107
+
62
108
const {
63
109
appCode, dashboardPort, loadError, dashboardRunning, dashboardStarting, dashboardAppPath
64
110
} = this . state ;
@@ -68,11 +114,54 @@ class DashboardPage extends Component {
68
114
< h2 >
69
115
{ loadError }
70
116
</ h2 >
71
- < p style = { { marginTop : 25 } } >
117
+ < Form layout = "inline" >
118
+ < Form . Item >
119
+ < Dropdown overlay = { frameworkMenu } >
120
+ < Button >
121
+ { frameworkItem && frameworkItem . title }
122
+ < Icon type = "down" />
123
+ </ Button >
124
+ </ Dropdown >
125
+ </ Form . Item >
126
+ < Form . Item >
127
+ < Dropdown
128
+ overlay = { chartLibrariesMenu }
129
+ disabled = { ! ! frameworkItem . docsLink }
130
+ >
131
+ < Button >
132
+ { currentLibraryItem && currentLibraryItem . title }
133
+ < Icon type = "down" />
134
+ </ Button >
135
+ </ Dropdown >
136
+ </ Form . Item >
137
+ </ Form >
138
+ {
139
+ frameworkItem && frameworkItem . docsLink && (
140
+ < h2 style = { { paddingTop : 24 , textAlign : 'center' } } >
141
+ We do not support
142
+ { frameworkItem . title }
143
+ dashboard scaffolding generation yet.
144
+ < br />
145
+ Please refer to
146
+ < a
147
+ href = { frameworkItem . docsLink }
148
+ target = "_blank"
149
+ rel = "noopener noreferrer"
150
+ onClick = { ( ) => playgroundAction ( 'Unsupported Dashboard Framework Docs' , { framework } ) }
151
+ >
152
+ { frameworkItem . title }
153
+ docs
154
+ </ a >
155
+ to see on how to use it with Cube.js.
156
+ </ h2 >
157
+ )
158
+ }
159
+ < p style = { { marginTop : 25 } } >
72
160
< Button
73
161
type = "primary"
74
162
size = "large"
75
163
onClick = { ( ) => this . loadDashboard ( true ) }
164
+ disabled = { ! ! frameworkItem . docsLink }
76
165
>
77
166
Create dashboard app template in your project directory
78
167
</ Button >
@@ -101,7 +190,10 @@ class DashboardPage extends Component {
101
190
Dashboard App is not running
102
191
</ h2 >
103
192
< h3 >
104
- Please start dashboard app or run it manually using < code class = "inline-code" > $ npm run start</ code > < br /> in
193
+ Please start dashboard app or run it manually using
194
+ < code className = "inline-code" > $ npm run start</ code >
195
+ < br />
196
+ in
105
197
< b > { dashboardAppPath } </ b >
106
198
directory.
107
199
</ h3 >
@@ -121,7 +213,11 @@ class DashboardPage extends Component {
121
213
}
122
214
const devServerUrl = `http://${ window . location . hostname } :${ dashboardPort } ` ;
123
215
return (
124
- < div style = { { height : '100%' , width : '100%' , padding : "15px 30px 30px 30px" , background : "#fff" } } >
216
+ < div
217
+ style = { {
218
+ height : '100%' , width : '100%' , padding : "15px 30px 30px 30px" , background : "#fff"
219
+ } }
220
+ >
125
221
< Alert
126
222
message = { (
127
223
< span >
@@ -131,8 +227,11 @@ class DashboardPage extends Component {
131
227
Dev server is running at
132
228
< a href = { devServerUrl } target = "_blank" rel = "noopener noreferrer" > { devServerUrl } </ a >
133
229
.
134
- Learn more how to customize and deploy it at < a href = "https://cube.dev/docs/dashboard-app" > Cube.js docs</ a > .
135
- < a onClick = { ( ) => window . location . reload ( ) } style = { { cursor : 'pointer' } } > Refresh page</ a > if it is empty.
230
+ Learn more how to customize and deploy it at
231
+ < a href = "https://cube.dev/docs/dashboard-app" > Cube.js docs</ a >
232
+ .
233
+ < a onClick = { ( ) => window . location . reload ( ) } style = { { cursor : 'pointer' } } > Refresh page</ a >
234
+ if it is empty.
136
235
</ span >
137
236
) }
138
237
type = "info"
0 commit comments