Skip to content

Commit

Permalink
Added action buttons to Chart Container of explore V2 (#1562)
Browse files Browse the repository at this point in the history
  • Loading branch information
vera-liu authored Nov 8, 2016
1 parent 1bf83c3 commit 4530047
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import EmbedCodeButton from './EmbedCodeButton';
import DisplayQueryButton from './DisplayQueryButton';

const propTypes = {
canDownload: PropTypes.string.isRequired,
canDownload: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]).isRequired,
slice: PropTypes.object.isRequired,
};

Expand Down
34 changes: 31 additions & 3 deletions caravel/assets/javascripts/explorev2/components/ChartContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,34 @@ import { connect } from 'react-redux';
import { Panel } from 'react-bootstrap';
import visMap from '../../../visualizations/main';
import { d3format } from '../../modules/utils';
import ExploreActionButtons from '../../explore/components/ExploreActionButtons';

const propTypes = {
can_download: PropTypes.bool.isRequired,
slice_name: PropTypes.string.isRequired,
viz_type: PropTypes.string.isRequired,
height: PropTypes.string.isRequired,
containerId: PropTypes.string.isRequired,
json_endpoint: PropTypes.string.isRequired,
csv_endpoint: PropTypes.string.isRequired,
standalone_endpoint: PropTypes.string.isRequired,
query: PropTypes.string.isRequired,
column_formats: PropTypes.object,
};

class ChartContainer extends React.Component {
constructor(props) {
super(props);
this.state = {
selector: `#${this.props.containerId}`,
selector: `#${props.containerId}`,
mockSlice: {},
};
}

componentWillMount() {
this.setState({ mockSlice: this.getMockedSliceObject() });
}

componentDidMount() {
this.renderVis();
}
Expand All @@ -32,7 +42,16 @@ class ChartContainer extends React.Component {

getMockedSliceObject() {
return {
viewSqlQuery: this.props.query,

data: {
csv_endpoint: this.props.csv_endpoint,
json_endpoint: this.props.json_endpoint,
standalone_endpoint: this.props.standalone_endpoint,
},

containerId: this.props.containerId,

jsonEndpoint: () => this.props.json_endpoint,

container: {
Expand Down Expand Up @@ -110,8 +129,7 @@ class ChartContainer extends React.Component {
}

renderVis() {
const slice = this.getMockedSliceObject();
visMap[this.props.viz_type](slice).render();
visMap[this.props.viz_type](this.state.mockSlice).render();
}

render() {
Expand All @@ -125,6 +143,12 @@ class ChartContainer extends React.Component {
className="panel-title"
>
{this.props.slice_name}
<div className="pull-right">
<ExploreActionButtons
slice={this.state.mockSlice}
canDownload={this.props.can_download}
/>
</div>
</div>
}
>
Expand All @@ -146,7 +170,11 @@ function mapStateToProps(state) {
containerId: `slice-container-${state.viz.form_data.slice_id}`,
slice_name: state.viz.form_data.slice_name,
viz_type: state.viz.form_data.viz_type,
can_download: state.can_download,
csv_endpoint: state.viz.csv_endpoint,
json_endpoint: state.viz.json_endpoint,
standalone_endpoint: state.viz.standalone_endpoint,
query: state.viz.query,
column_formats: state.viz.column_formats,
};
}
Expand Down
1 change: 1 addition & 0 deletions caravel/assets/javascripts/explorev2/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const bootstrapData = JSON.parse(exploreViewContainer.getAttribute('data-bootstr
import { exploreReducer } from './reducers/exploreReducer';

const bootstrappedState = Object.assign(initialState, {
can_download: bootstrapData.can_download,
datasources: bootstrapData.datasources,
datasource_id: parseInt(bootstrapData.datasource_id, 10),
datasource_type: bootstrapData.datasource_type,
Expand Down

0 comments on commit 4530047

Please sign in to comment.