[explore] fix empty chart when changing viz type (#2698)

* [explore] fix empty chart when changing viz type

* Lint
This commit is contained in:
Maxime Beauchemin 2017-04-30 10:58:45 -07:00 committed by GitHub
parent 3cd16cf368
commit 3e7b5df287
4 changed files with 16 additions and 4 deletions

View File

@ -60,6 +60,7 @@ class ChartContainer extends React.PureComponent {
) && !this.props.queryResponse.error
&& this.props.chartStatus !== 'failed'
&& this.props.chartStatus !== 'stopped'
&& this.props.chartStatus !== 'loading'
) {
this.renderViz();
}

View File

@ -51,17 +51,26 @@ 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, []);
}
componentDidMount() {
this.validateAndSetValue(this.props.value, []);
}
onChange(value, errors) {
this.validateAndSetValue(value, errors);
}
validateAndSetValue(value, errors) {
let validationErrors = this.validate(value);
let validationErrors = this.props.validationErrors;
let currentErrors = this.validate(value);
if (errors && errors.length > 0) {
validationErrors = validationErrors.concat(errors);
currentErrors = validationErrors.concat(errors);
}
if (validationErrors.length + currentErrors.length > 0) {
validationErrors = currentErrors;
}
if (value !== this.props.value || validationErrors !== this.props.validationErrors) {
this.props.actions.setControlValue(this.props.name, value, validationErrors);
}
this.props.actions.setControlValue(this.props.name, value, validationErrors);
}
validate(value) {
const validators = this.props.validators;

View File

@ -39,6 +39,7 @@ const bootstrappedState = Object.assign(
queryResponse: null,
triggerQuery: true,
triggerRender: false,
alert: null,
},
);

View File

@ -65,6 +65,7 @@ export function getControlsState(state, form_data) {
if (typeof control.default === 'function') {
control.default = control.default(control);
}
control.validationErrors = [];
control.value = formData[k] !== undefined ? formData[k] : control.default;
controlsState[k] = control;
});