mirror of
https://github.com/apache/superset.git
synced 2026-04-20 00:24:38 +00:00
[explorev2] adding support for client side validators on controls (#1920)
* Adding support for client side validators on controls * Applying validators to more fields * Addressing comments
This commit is contained in:
committed by
GitHub
parent
fc74fbeeaa
commit
470a6e9d76
@@ -15,6 +15,7 @@ const propTypes = {
|
||||
actions: React.PropTypes.object.isRequired,
|
||||
datasource_type: React.PropTypes.string.isRequired,
|
||||
chartStatus: React.PropTypes.string.isRequired,
|
||||
fields: React.PropTypes.object.isRequired,
|
||||
};
|
||||
|
||||
|
||||
@@ -72,6 +73,28 @@ class ExploreViewContainer extends React.Component {
|
||||
toggleModal() {
|
||||
this.setState({ showModal: !this.state.showModal });
|
||||
}
|
||||
renderErrorMessage() {
|
||||
// Returns an error message as a node if any errors are in the store
|
||||
const errors = [];
|
||||
for (const fieldName in this.props.fields) {
|
||||
const field = this.props.fields[fieldName];
|
||||
if (field.validationErrors && field.validationErrors.length > 0) {
|
||||
errors.push(
|
||||
<div key={fieldName}>
|
||||
<strong>{`[ ${field.label} ] `}</strong>
|
||||
{field.validationErrors.join('. ')}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
let errorMessage;
|
||||
if (errors.length > 0) {
|
||||
errorMessage = (
|
||||
<div style={{ textAlign: 'left' }}>{errors}</div>
|
||||
);
|
||||
}
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
@@ -98,8 +121,9 @@ class ExploreViewContainer extends React.Component {
|
||||
onQuery={this.onQuery.bind(this, this.props.form_data)}
|
||||
onSave={this.toggleModal.bind(this)}
|
||||
disabled={this.props.chartStatus === 'loading'}
|
||||
errorMessage={this.renderErrorMessage()}
|
||||
/>
|
||||
<br /><br />
|
||||
<br />
|
||||
<ControlPanelsContainer
|
||||
actions={this.props.actions}
|
||||
form_data={this.props.form_data}
|
||||
@@ -126,6 +150,7 @@ function mapStateToProps(state) {
|
||||
datasource_type: state.datasource_type,
|
||||
form_data: state.viz.form_data,
|
||||
chartStatus: state.chartStatus,
|
||||
fields: state.fields,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user