[explore] force control validation before runQuery (#2544)

* [explore] force control validation before runQuery

* Addressing comments
This commit is contained in:
Maxime Beauchemin
2017-04-10 21:45:44 -07:00
committed by GitHub
parent 493ba18362
commit 75a358c616
7 changed files with 14 additions and 8 deletions

View File

@@ -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 ||

View File

@@ -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);

View File

@@ -47,7 +47,7 @@ class ExploreViewContainer extends React.Component {
}
componentDidUpdate() {
if (this.props.triggerQuery) {
if (this.props.triggerQuery && !this.hasErrors()) {
this.runQuery();
}
}
@@ -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 = [];

View File

@@ -9,7 +9,7 @@ const propTypes = {
onSave: PropTypes.func,
onStop: PropTypes.func,
loading: PropTypes.bool,
errorMessage: PropTypes.string,
errorMessage: PropTypes.node,
};
const defaultProps = {
@@ -37,6 +37,7 @@ export default function QueryAndSaveBtns(
className="query"
onClick={onQuery}
bsStyle={qryButtonStyle}
disabled={!!errorMessage}
>
<i className="fa fa-bolt" /> Query
</Button>