[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.queryResponse.error
&& this.props.chartStatus !== 'failed' && this.props.chartStatus !== 'failed'
&& this.props.chartStatus !== 'stopped' && this.props.chartStatus !== 'stopped'
&& this.props.chartStatus !== 'loading'
) { ) {
this.renderViz(); this.renderViz();
} }

View File

@@ -51,17 +51,26 @@ export default class Control extends React.PureComponent {
super(props); super(props);
this.validate = this.validate.bind(this); this.validate = this.validate.bind(this);
this.onChange = this.onChange.bind(this); this.onChange = this.onChange.bind(this);
this.validateAndSetValue(props.value, []); }
componentDidMount() {
this.validateAndSetValue(this.props.value, []);
} }
onChange(value, errors) { onChange(value, errors) {
this.validateAndSetValue(value, errors); this.validateAndSetValue(value, errors);
} }
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) { 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) { validate(value) {
const validators = this.props.validators; const validators = this.props.validators;

View File

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

View File

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