Skip to content

Commit f5578dd

Browse files
committed
feat(playground): App layout for dashboard
1 parent fd3ca21 commit f5578dd

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed

packages/cubejs-playground/src/DashboardSource.js

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,35 @@ const prettier = require("prettier/standalone");
99
const plugins = [require("prettier/parser-babylon")];
1010

1111
const dashboardComponents = `
12-
import { Row, Col, Card } from 'antd';
12+
import { Row, Col, Card, Layout } from 'antd';
1313
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+
)
1441
1542
const Dashboard = ({ children }) => (
1643
<Row type="flex" justify="space-around" align="top" gutter={24}>{children}</Row>
@@ -25,6 +52,12 @@ const DashboardItem = ({ children, title }) => (
2552
)
2653
`;
2754

55+
const indexCss = `
56+
body {
57+
background-color: #f0f2f5 !important;
58+
}
59+
`;
60+
2861
const fetchWithRetry = (url, options, retries) => fetch(url, { ...options, retries });
2962

3063
class DashboardSource {
@@ -43,15 +76,21 @@ class DashboardSource {
4376
}
4477

4578
async persist() {
79+
const updateIndexCss = this.appLayoutAdded ? [
80+
{ ...this.indexCssFile, content: this.indexCssFile.content + indexCss }
81+
] : [];
4682
await fetchWithRetry('/playground/dashboard-app-files', {
4783
method: 'POST',
4884
headers: {
4985
'Content-Type': 'application/json'
5086
},
5187
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)
5391
})
5492
}, 5);
93+
this.appLayoutAdded = false;
5594
const dependencies = this.imports
5695
.filter(i => i.get('source').node.value.indexOf('.') !== 0)
5796
.map(i => {
@@ -75,6 +114,7 @@ class DashboardSource {
75114
if (!this.appFile) {
76115
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.`);
77116
}
117+
this.indexCssFile = sourceFiles.find(f => f.fileName.indexOf('src/index.css') !== -1);
78118
this.appAst = parse(this.appFile.content, {
79119
sourceFilename: this.appFile.fileName,
80120
sourceType: 'module',
@@ -150,11 +190,16 @@ class DashboardSource {
150190
}
151191
});
152192
if (!dashboardAdded && headerElement) {
193+
this.appLayoutAdded = true;
153194
headerElement.parentPath.replaceWith(
154195
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+
)]
158203
)
159204
);
160205
}

0 commit comments

Comments
 (0)