mirror of
https://github.com/apache/superset.git
synced 2026-04-11 04:15:33 +00:00
* Simplifying the Field interface / logic * Moving ControlLabelWithTooltip where it belongs * Progress * Rename FieldClass->FieldType
51 lines
1.2 KiB
JavaScript
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;
|