Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate Fieldset component from jsx to tsx #17474

Merged
merged 3 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>;
Damans227 marked this conversation as resolved.
Show resolved Hide resolved
title: React.ReactNode;
compact: boolean;
}

type fieldKeyType = string | number;

export default class Fieldset extends React.PureComponent<FieldsetProps> {
static defaultProps = {
compact: false,
title: null,
};

export default class Fieldset extends React.PureComponent {
constructor(props) {
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,
Expand All @@ -50,7 +52,7 @@ 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,
Expand All @@ -63,5 +65,3 @@ export default class Fieldset extends React.PureComponent {
);
}
}
Fieldset.propTypes = propTypes;
Fieldset.defaultProps = defaultProps;
2 changes: 1 addition & 1 deletion superset-frontend/src/components/Form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const StyledForm = styled(AntDForm)`
}
`;

export default function Form(props: FormProps) {
export default function Form(props: any) {
Damans227 marked this conversation as resolved.
Show resolved Hide resolved
return <StyledForm {...props} />;
}

Expand Down