Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new slice form improvements #2928

Merged
merged 6 commits into from
Jun 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions superset/assets/javascripts/addSlice/AddSliceContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ export default class AddSliceContainer extends React.PureComponent {
const visTypeKeys = Object.keys(visTypes);
this.vizTypeOptions = visTypeKeys.map(vt => ({ label: visTypes[vt].label, value: vt }));
this.state = {
datasourceValue: this.props.datasources[0].value,
datasourceId: this.props.datasources[0].value.split('__')[0],
datasourceType: this.props.datasources[0].value.split('__')[1],
visType: 'table',
};
}
Expand All @@ -42,14 +39,14 @@ export default class AddSliceContainer extends React.PureComponent {
});
}

changeSliceName(e) {
this.setState({ sliceName: e.target.value });
}

changeVisType(e) {
this.setState({ visType: e.value });
}

isBtnDisabled() {
return !(this.state.datasourceId && this.state.visType);
}

render() {
return (
<div className="container">
Expand Down Expand Up @@ -81,7 +78,11 @@ export default class AddSliceContainer extends React.PureComponent {
/>
</div>
<br />
<Button bsStyle="primary" onClick={this.gotoSlice.bind(this)}>
<Button
bsStyle="primary"
disabled={this.isBtnDisabled()}
onClick={this.gotoSlice.bind(this)}
>
Create new slice
</Button>
<br /><br />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,27 @@ describe('AddSliceContainer', () => {
expect(wrapper.find(Button)).to.have.lengthOf(1);
});

it('renders a disabled button if no datasource is selected', () => {
expect(wrapper.find(Button).dive().find('.btn[disabled=true]')).to.have.length(1);
});

it('renders an enabled button if datasource is selected', () => {
const datasourceValue = defaultProps.datasources[0].value;
wrapper.setState({
datasourceValue,
datasourceId: datasourceValue.split('__')[0],
datasourceType: datasourceValue.split('__')[1],
});
expect(wrapper.find(Button).dive().find('.btn[disabled=false]')).to.have.length(1);
});

it('formats explore url', () => {
const datasourceValue = defaultProps.datasources[0].value;
wrapper.setState({
datasourceValue,
datasourceId: datasourceValue.split('__')[0],
datasourceType: datasourceValue.split('__')[1],
});
const formattedUrl = '/superset/explore/table/1?form_data=%7B%22viz_type%22%3A%22table%22%7D';
expect(wrapper.instance().exploreUrl()).to.equal(formattedUrl);
});
Expand Down
2 changes: 1 addition & 1 deletion superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def add(self):
return self.render_template(
"superset/add_slice.html",
bootstrap_data=json.dumps({
'datasources': datasources,
'datasources': sorted(datasources),
}),
)

Expand Down