Skip to content

Commit

Permalink
[explore] force control validation before runQuery (#2544)
Browse files Browse the repository at this point in the history
* [explore] force control validation before runQuery

* Addressing comments
  • Loading branch information
mistercrunch committed Apr 11, 2017
1 parent 493ba18 commit 75a358c
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class ChartContainer extends React.PureComponent {

componentDidUpdate(prevProps) {
if (
this.props.queryResponse &&
(
prevProps.queryResponse !== this.props.queryResponse ||
prevProps.height !== this.props.height ||
Expand Down
4 changes: 4 additions & 0 deletions superset/assets/javascripts/explorev2/components/Control.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ export default class Control extends React.PureComponent {
super(props);
this.validate = this.validate.bind(this);
this.onChange = this.onChange.bind(this);
this.validateAndSetValue(props.value, []);
}
onChange(value, errors) {
this.validateAndSetValue(value, errors);
}
validateAndSetValue(value, errors) {
let validationErrors = this.validate(value);
if (errors && errors.length > 0) {
validationErrors = validationErrors.concat(errors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ExploreViewContainer extends React.Component {
}

componentDidUpdate() {
if (this.props.triggerQuery) {
if (this.props.triggerQuery && !this.hasErrors()) {
this.runQuery();
}
}
Expand Down Expand Up @@ -95,6 +95,10 @@ class ExploreViewContainer extends React.Component {
toggleModal() {
this.setState({ showModal: !this.state.showModal });
}
hasErrors() {
const ctrls = this.props.controls;
return Object.keys(ctrls).some(k => ctrls[k].validationErrors.length > 0);
}
renderErrorMessage() {
// Returns an error message as a node if any errors are in the store
const errors = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const propTypes = {
onSave: PropTypes.func,
onStop: PropTypes.func,
loading: PropTypes.bool,
errorMessage: PropTypes.string,
errorMessage: PropTypes.node,
};

const defaultProps = {
Expand Down Expand Up @@ -37,6 +37,7 @@ export default function QueryAndSaveBtns(
className="query"
onClick={onQuery}
bsStyle={qryButtonStyle}
disabled={!!errorMessage}
>
<i className="fa fa-bolt" /> Query
</Button>
Expand Down
2 changes: 1 addition & 1 deletion superset/assets/javascripts/explorev2/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { exploreReducer } from './reducers/exploreReducer';
// Initial state
const bootstrappedState = Object.assign(
bootstrapData, {
chartStatus: 'loading',
chartStatus: null,
chartUpdateEndTime: null,
chartUpdateStartTime: now(),
dashboards: [],
Expand Down
4 changes: 0 additions & 4 deletions superset/assets/javascripts/explorev2/stores/visTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,6 @@ const visTypes = {
},
],
controlOverrides: {
metrics: {
default: null,
validators: null,
},
time_grain_sqla: {
default: null,
},
Expand Down
2 changes: 1 addition & 1 deletion superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def query_obj(self):
"""Building a query object"""
form_data = self.form_data
groupby = form_data.get("groupby") or []
metrics = form_data.get("metrics") or ['count']
metrics = form_data.get("metrics") or []

# extra_filters are temporary/contextual filters that are external
# to the slice definition. We use those for dynamic interactive
Expand Down

0 comments on commit 75a358c

Please sign in to comment.