Files
superset2/superset/assets/javascripts/explorev2/components/FieldSet.jsx
Maxime Beauchemin 7aab8b0ae3 Simplifying the Fields (Controls) interface (#1868)
* Simplifying the Field interface / logic

* Moving ControlLabelWithTooltip where it belongs

* Progress

* Rename FieldClass->FieldType
2017-01-04 15:46:52 -08:00

51 lines
1.2 KiB
JavaScript

import React, { PropTypes } from 'react';
import TextField from './TextField';
import CheckboxField from './CheckboxField';
import TextAreaField from './TextAreaField';
import SelectField from './SelectField';
import ControlLabelWithTooltip from './ControlLabelWithTooltip';
const fieldMap = {
TextField,
CheckboxField,
TextAreaField,
SelectField,
};
const fieldTypes = Object.keys(fieldMap);
const propTypes = {
name: PropTypes.string.isRequired,
type: PropTypes.oneOf(fieldTypes).isRequired,
label: PropTypes.string.isRequired,
choices: PropTypes.arrayOf(PropTypes.array),
description: PropTypes.string,
places: PropTypes.number,
validators: PropTypes.any,
onChange: React.PropTypes.func,
value: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
PropTypes.bool,
PropTypes.array]),
};
const defaultProps = {
onChange: () => {},
};
export default class FieldSet extends React.PureComponent {
render() {
const FieldType = fieldMap[this.props.type];
return (
<div>
<ControlLabelWithTooltip label={this.props.label} description={this.props.description} />
<FieldType {...this.props} />
</div>
);
}
}
FieldSet.propTypes = propTypes;
FieldSet.defaultProps = defaultProps;