diff --git a/go.mod b/go.mod index 7f545033b..c78af29d0 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/getfider/fider -go 1.22.0 +go 1.22 require ( github.com/aws/aws-sdk-go v1.41.14 diff --git a/public/components/common/form/Select.tsx b/public/components/common/form/Select.tsx index a45323a96..e864e68bc 100644 --- a/public/components/common/form/Select.tsx +++ b/public/components/common/form/Select.tsx @@ -19,75 +19,58 @@ interface SelectProps { onChange?: (option?: SelectOption) => void } -interface SelectState { - selected?: SelectOption -} - -export class Select extends React.Component { - constructor(props: SelectProps) { - super(props) - this.state = { - selected: this.getOption(props.defaultValue), - } - } - - private getOption(value?: string): SelectOption | undefined { - if (value && this.props.options) { - const filtered = this.props.options.filter((x) => x.value === value) +export const Select: React.FunctionComponent = (props) => { + const getOption = (value?: string) => { + if (value && props.options) { + const filtered = props.options.filter((x) => x.value === value) if (filtered && filtered.length > 0) { return filtered[0] } } } - - private onChange = (e: React.FormEvent) => { + const [selected, setSelected] = React.useState(getOption(props.defaultValue)) + const onChange = (e: React.FormEvent) => { let selected: SelectOption | undefined if (e.currentTarget.value) { - const options = this.props.options.filter((o) => o.value === e.currentTarget.value) + const options = props.options.filter((o) => o.value === e.currentTarget.value) if (options && options.length > 0) { selected = options[0] } } - this.setState({ selected }, () => { - if (this.props.onChange) { - this.props.onChange(this.state.selected) - } - }) + setSelected(selected) + if (props.onChange) { + props.onChange(selected) + } } - public render() { - const options = this.props.options.map((option) => { - return ( - - ) - }) - - return ( - - {(ctx) => ( - <> -
- {!!this.props.label && } - - - {this.props.children} -
- - )} -
- ) - } + return ( + + {(ctx) => ( + <> +
+ {!!props.label && } + + + {props.children} +
+ + )} +
+ ) }