Skip to content

Commit

Permalink
feat(playground): Links to Vanilla, Angular and Vue.js docs
Browse files Browse the repository at this point in the history
  • Loading branch information
paveltiunov committed Jul 5, 2019
1 parent c56fb0e commit 184495c
Showing 1 changed file with 58 additions and 6 deletions.
64 changes: 58 additions & 6 deletions packages/cubejs-playground/src/ChartContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,29 @@ import PropTypes from 'prop-types';
import PrismCode from './PrismCode';
import { playgroundAction } from './events';

const frameworks = [{
id: 'vanilla',
title: 'Vanilla JavaScript',
docsLink: 'https://cube.dev/docs/@cubejs-client-core'
}, {
id: 'angular',
title: 'Angular',
docsLink: 'https://cube.dev/docs/@cubejs-client-ngx'
}, {
id: 'react',
title: 'React'
}, {
id: 'vue',
title: 'Vue.js',
docsLink: 'https://cube.dev/docs/@cubejs-client-vue'
}];

class ChartContainer extends React.Component {
constructor(props) {
super(props);
this.state = {
showCode: false
showCode: false,
framework: 'react'
};
}

Expand Down Expand Up @@ -60,7 +78,7 @@ class ChartContainer extends React.Component {

render() {
const {
redirectToDashboard, showCode, sandboxId, addingToDashboard
redirectToDashboard, showCode, sandboxId, addingToDashboard, framework
} = this.state;
const {
resultSet,
Expand Down Expand Up @@ -99,7 +117,20 @@ class ChartContainer extends React.Component {
</Menu>
);

const frameworkMenu = (
<Menu onClick={(e) => this.setState({ framework: e.key })}>
{
frameworks.map(f => (
<Menu.Item key={f.id}>
{f.title}
</Menu.Item>
))
}
</Menu>
);

const currentLibraryItem = chartLibraries.find(m => m.value === chartLibrary);
const frameworkItem = frameworks.find(m => m.id === framework);
const extra = (
<form action="https://codesandbox.io/api/v1/sandboxes/define" method="POST" target="_blank">
<input type="hidden" name="parameters" value={parameters} />
Expand All @@ -119,6 +150,12 @@ class ChartContainer extends React.Component {
{addingToDashboard ? 'Creating app and installing modules...' : 'Add to Dashboard'}
</Button>
)}
<Dropdown overlay={frameworkMenu}>
<Button size="small">
{frameworkItem && frameworkItem.title}
<Icon type="down" />
</Button>
</Dropdown>
<Dropdown overlay={chartLibrariesMenu}>
<Button size="small">
{currentLibraryItem && currentLibraryItem.title}
Expand Down Expand Up @@ -159,8 +196,23 @@ class ChartContainer extends React.Component {
</form>
);

const code = () => {
if (showCode === 'code') {
const renderChart = () => {
if (frameworkItem && frameworkItem.docsLink) {
return (
<h2 style={{ padding: 24, textAlign: 'center' }}>
We do not support&nbsp;
{frameworkItem.title}
&nbsp;code generation here yet.
< br/>
Please refer to&nbsp;
<a href={frameworkItem.docsLink} target="_blank">
{frameworkItem.title}
&nbsp;docs
</a>
&nbsp;to see on how to use it with Cube.js.
</h2>
);
} else if (showCode === 'code') {
return <PrismCode code={codeExample} />;
} else if (showCode === 'sql') {
return (
Expand All @@ -172,7 +224,7 @@ class ChartContainer extends React.Component {
/>
);
}
return null;
return render({ resultSet, error, sandboxId });
};

return hideActions ? render({ resultSet, error, sandboxId }) : (
Expand All @@ -181,7 +233,7 @@ class ChartContainer extends React.Component {
style={{ minHeight: 420 }}
extra={extra}
>
{showCode ? code() : render({ resultSet, error, sandboxId })}
{renderChart()}
</Card>
);
}
Expand Down

0 comments on commit 184495c

Please sign in to comment.