Skip to content

Commit

Permalink
[explorev2] making QueryAndSaveBtns disabled while running queries
Browse files Browse the repository at this point in the history
As I altered QueryAndSaveBtns to add the `disabled` prop
I also moved it to using react-boostrap
  • Loading branch information
mistercrunch committed Dec 14, 2016
1 parent 552d464 commit c9a61f3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
30 changes: 20 additions & 10 deletions superset/assets/javascripts/explore/components/QueryAndSaveBtns.jsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,46 @@
import React, { PropTypes } from 'react';
import { Button, ButtonGroup } from 'react-bootstrap';
import classnames from 'classnames';

const propTypes = {
canAdd: PropTypes.string.isRequired,
onQuery: PropTypes.func.isRequired,
onSave: PropTypes.func,
disabled: PropTypes.bool,
};

const defaultProps = {
onSave: () => {},
disabled: false,
};

export default function QueryAndSaveBtns({ canAdd, onQuery, onSave }) {
const saveClasses = classnames('btn btn-default btn-sm', {
export default function QueryAndSaveBtns({ canAdd, onQuery, onSave, disabled }) {
const saveClasses = classnames({
'disabled disabledButton': canAdd !== 'True',
});

return (
<div className="btn-group query-and-save">
<button id="query_button" type="button" className="btn btn-primary btn-sm" onClick={onQuery}>
<i className="fa fa-bolt"></i> Query
</button>
<button
type="button"
<ButtonGroup className="query-and-save">
<Button
id="query_button"
onClick={onQuery}
bsSize="small"
disabled={disabled}
bsStyle="primary"
>
<i className="fa fa-bolt" /> Query
</Button>
<Button
className={saveClasses}
bsSize="small"
data-target="#save_modal"
data-toggle="modal"
disabled={disabled}
onClick={onSave}
>
<i className="fa fa-plus-circle"></i> Save as
</button>
</div>
</Button>
</ButtonGroup>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const propTypes = {
form_data: React.PropTypes.object.isRequired,
actions: React.PropTypes.object.isRequired,
datasource_type: React.PropTypes.string.isRequired,
chartStatus: React.PropTypes.string.isRequired,
};


Expand Down Expand Up @@ -94,6 +95,7 @@ class ExploreViewContainer extends React.Component {
canAdd="True"
onQuery={this.onQuery.bind(this, this.props.form_data)}
onSave={this.toggleModal.bind(this)}
disabled={this.props.chartStatus === 'loading'}
/>
<br /><br />
<ControlPanelsContainer
Expand Down Expand Up @@ -121,6 +123,7 @@ function mapStateToProps(state) {
return {
datasource_type: state.datasource_type,
form_data: state.viz.form_data,
chartStatus: state.chartStatus,
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { beforeEach, describe, it } from 'mocha';
import { Button } from 'react-bootstrap';
import { expect } from 'chai';
import { shallow } from 'enzyme';
import sinon from 'sinon';
Expand All @@ -26,12 +27,12 @@ describe('QueryAndSaveButtons', () => {
});

it('renders 2 buttons', () => {
expect(wrapper.find('button')).to.have.lengthOf(2);
expect(wrapper.find(Button)).to.have.lengthOf(2);
});

it('renders buttons with correct text', () => {
expect(wrapper.find('button').contains(' Query')).to.eql(true);
expect(wrapper.find('button').contains(' Save as')).to.eql(true);
expect(wrapper.find(Button).contains(' Query')).to.eql(true);
expect(wrapper.find(Button).contains(' Save as')).to.eql(true);
});

it('calls onQuery when query button is clicked', () => {
Expand Down

0 comments on commit c9a61f3

Please sign in to comment.