diff --git a/superset-frontend/src/CRUD/Fieldset.jsx b/superset-frontend/src/CRUD/Fieldset.tsx similarity index 72% rename from superset-frontend/src/CRUD/Fieldset.jsx rename to superset-frontend/src/CRUD/Fieldset.tsx index 3964af5c20..239898e296 100644 --- a/superset-frontend/src/CRUD/Fieldset.jsx +++ b/superset-frontend/src/CRUD/Fieldset.tsx @@ -17,31 +17,33 @@ * under the License. */ import React from 'react'; -import PropTypes from 'prop-types'; import { Form } from 'src/components/Form'; import { recurseReactClone } from './utils'; import Field from './Field'; -const propTypes = { - children: PropTypes.node.isRequired, - onChange: PropTypes.func, - item: PropTypes.object, - title: PropTypes.node, - compact: PropTypes.bool, -}; -const defaultProps = { - compact: false, - title: null, -}; +interface FieldsetProps { + children: React.ReactNode; + onChange: Function; + item: Record; + title: React.ReactNode; + compact: boolean; +} -export default class Fieldset extends React.PureComponent { - constructor(props) { +type fieldKeyType = string | number; + +export default class Fieldset extends React.PureComponent { + static defaultProps = { + compact: false, + title: null, + }; + + constructor(props: FieldsetProps) { super(props); this.onChange = this.onChange.bind(this); } - onChange(fieldKey, val) { + onChange(fieldKey: fieldKeyType, val: any) { return this.props.onChange({ ...this.props.item, [fieldKey]: val, @@ -50,18 +52,16 @@ export default class Fieldset extends React.PureComponent { render() { const { title } = this.props; - const propExtender = field => ({ + const propExtender = (field: { props: { fieldKey: fieldKeyType } }) => ({ onChange: this.onChange, value: this.props.item[field.props.fieldKey], compact: this.props.compact, }); return ( -
+ {title && {title}} {recurseReactClone(this.props.children, Field, propExtender)}
); } } -Fieldset.propTypes = propTypes; -Fieldset.defaultProps = defaultProps;