@@ -9,8 +9,35 @@ const prettier = require("prettier/standalone");
9
9
const plugins = [ require ( "prettier/parser-babylon" ) ] ;
10
10
11
11
const dashboardComponents = `
12
- import { Row, Col, Card } from 'antd';
12
+ import { Row, Col, Card, Layout } from 'antd';
13
13
import 'antd/dist/antd.css';
14
+ import './index.css'
15
+
16
+ const AppLayout = ({ children }) => (
17
+ <Layout>
18
+ <Layout.Header>
19
+ <div style={{ float: 'left' }}>
20
+ <h2
21
+ style={{
22
+ color: "#fff",
23
+ margin: 0,
24
+ marginRight: '1em'
25
+ }}
26
+ >
27
+ My Dashboard
28
+ </h2>
29
+ </div>
30
+ </Layout.Header>
31
+ <Layout.Content
32
+ style={{
33
+ padding: "0 25px 25px 25px",
34
+ margin: "25px"
35
+ }}
36
+ >
37
+ {children}
38
+ </Layout.Content>
39
+ </Layout>
40
+ )
14
41
15
42
const Dashboard = ({ children }) => (
16
43
<Row type="flex" justify="space-around" align="top" gutter={24}>{children}</Row>
@@ -25,6 +52,12 @@ const DashboardItem = ({ children, title }) => (
25
52
)
26
53
` ;
27
54
55
+ const indexCss = `
56
+ body {
57
+ background-color: #f0f2f5 !important;
58
+ }
59
+ ` ;
60
+
28
61
const fetchWithRetry = ( url , options , retries ) => fetch ( url , { ...options , retries } ) ;
29
62
30
63
class DashboardSource {
@@ -43,15 +76,21 @@ class DashboardSource {
43
76
}
44
77
45
78
async persist ( ) {
79
+ const updateIndexCss = this . appLayoutAdded ? [
80
+ { ...this . indexCssFile , content : this . indexCssFile . content + indexCss }
81
+ ] : [ ] ;
46
82
await fetchWithRetry ( '/playground/dashboard-app-files' , {
47
83
method : 'POST' ,
48
84
headers : {
49
85
'Content-Type' : 'application/json'
50
86
} ,
51
87
body : JSON . stringify ( {
52
- files : [ { ...this . appFile , content : prettier . format ( this . dashboardAppCode ( ) , { parser : "babylon" , plugins } ) } ]
88
+ files : [
89
+ { ...this . appFile , content : prettier . format ( this . dashboardAppCode ( ) , { parser : "babylon" , plugins } ) }
90
+ ] . concat ( updateIndexCss )
53
91
} )
54
92
} , 5 ) ;
93
+ this . appLayoutAdded = false ;
55
94
const dependencies = this . imports
56
95
. filter ( i => i . get ( 'source' ) . node . value . indexOf ( '.' ) !== 0 )
57
96
. map ( i => {
@@ -75,6 +114,7 @@ class DashboardSource {
75
114
if ( ! this . appFile ) {
76
115
throw new Error ( `src/App.js file not found. Can't parse dashboard app. Please delete dashboard-app directory and try to create it again.` ) ;
77
116
}
117
+ this . indexCssFile = sourceFiles . find ( f => f . fileName . indexOf ( 'src/index.css' ) !== - 1 ) ;
78
118
this . appAst = parse ( this . appFile . content , {
79
119
sourceFilename : this . appFile . fileName ,
80
120
sourceType : 'module' ,
@@ -150,11 +190,16 @@ class DashboardSource {
150
190
}
151
191
} ) ;
152
192
if ( ! dashboardAdded && headerElement ) {
193
+ this . appLayoutAdded = true ;
153
194
headerElement . parentPath . replaceWith (
154
195
t . JSXElement (
155
- t . JSXOpeningElement ( t . JSXIdentifier ( 'Dashboard' ) , [ ] ) ,
156
- t . JSXClosingElement ( t . JSXIdentifier ( 'Dashboard' ) ) ,
157
- [ ]
196
+ t . JSXOpeningElement ( t . JSXIdentifier ( 'AppLayout' ) , [ ] ) ,
197
+ t . JSXClosingElement ( t . JSXIdentifier ( 'AppLayout' ) ) ,
198
+ [ t . JSXElement (
199
+ t . JSXOpeningElement ( t . JSXIdentifier ( 'Dashboard' ) , [ ] ) ,
200
+ t . JSXClosingElement ( t . JSXIdentifier ( 'Dashboard' ) ) ,
201
+ [ ]
202
+ ) ]
158
203
)
159
204
) ;
160
205
}
0 commit comments