Skip to content

Commit 184495c

Browse files
committed
feat(playground): Links to Vanilla, Angular and Vue.js docs
1 parent c56fb0e commit 184495c

File tree

1 file changed

+58
-6
lines changed

1 file changed

+58
-6
lines changed

packages/cubejs-playground/src/ChartContainer.jsx

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,29 @@ import PropTypes from 'prop-types';
1212
import PrismCode from './PrismCode';
1313
import { playgroundAction } from './events';
1414

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+
1532
class ChartContainer extends React.Component {
1633
constructor(props) {
1734
super(props);
1835
this.state = {
19-
showCode: false
36+
showCode: false,
37+
framework: 'react'
2038
};
2139
}
2240

@@ -60,7 +78,7 @@ class ChartContainer extends React.Component {
6078

6179
render() {
6280
const {
63-
redirectToDashboard, showCode, sandboxId, addingToDashboard
81+
redirectToDashboard, showCode, sandboxId, addingToDashboard, framework
6482
} = this.state;
6583
const {
6684
resultSet,
@@ -99,7 +117,20 @@ class ChartContainer extends React.Component {
99117
</Menu>
100118
);
101119

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+
102132
const currentLibraryItem = chartLibraries.find(m => m.value === chartLibrary);
133+
const frameworkItem = frameworks.find(m => m.id === framework);
103134
const extra = (
104135
<form action="https://codesandbox.io/api/v1/sandboxes/define" method="POST" target="_blank">
105136
<input type="hidden" name="parameters" value={parameters} />
@@ -119,6 +150,12 @@ class ChartContainer extends React.Component {
119150
{addingToDashboard ? 'Creating app and installing modules...' : 'Add to Dashboard'}
120151
</Button>
121152
)}
153+
<Dropdown overlay={frameworkMenu}>
154+
<Button size="small">
155+
{frameworkItem && frameworkItem.title}
156+
<Icon type="down" />
157+
</Button>
158+
</Dropdown>
122159
<Dropdown overlay={chartLibrariesMenu}>
123160
<Button size="small">
124161
{currentLibraryItem && currentLibraryItem.title}
@@ -159,8 +196,23 @@ class ChartContainer extends React.Component {
159196
</form>
160197
);
161198

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&nbsp;
204+
{frameworkItem.title}
205+
&nbsp;code generation here yet.
206+
< br/>
207+
Please refer to&nbsp;
208+
<a href={frameworkItem.docsLink} target="_blank">
209+
{frameworkItem.title}
210+
&nbsp;docs
211+
</a>
212+
&nbsp;to see on how to use it with Cube.js.
213+
</h2>
214+
);
215+
} else if (showCode === 'code') {
164216
return <PrismCode code={codeExample} />;
165217
} else if (showCode === 'sql') {
166218
return (
@@ -172,7 +224,7 @@ class ChartContainer extends React.Component {
172224
/>
173225
);
174226
}
175-
return null;
227+
return render({ resultSet, error, sandboxId });
176228
};
177229

178230
return hideActions ? render({ resultSet, error, sandboxId }) : (
@@ -181,7 +233,7 @@ class ChartContainer extends React.Component {
181233
style={{ minHeight: 420 }}
182234
extra={extra}
183235
>
184-
{showCode ? code() : render({ resultSet, error, sandboxId })}
236+
{renderChart()}
185237
</Card>
186238
);
187239
}

0 commit comments

Comments
 (0)