import React from 'react' import { IDataParamSource, IDataParamConfig } from './Dropbox' import { decodeMetricName } from '../util' import { Radio, Button } from 'antd' const RadioGroup = Radio.Group const styles = require('./Workbench.less') interface IActOnSettingFormProps { list: IDataParamSource[] config: IDataParamConfig onSave: (config: IDataParamConfig) => void onCancel: () => void } interface IActOnSettingFormStates { actOn: string list: IDataParamSource[] } export class ActOnSettingForm extends React.PureComponent { constructor (props) { super(props) this.state = { actOn: 'all', list: [] } } public componentWillMount () { const { config } = this.props if (config.actOn) { this.setState({ actOn: config.actOn }) } } public componentWillReceiveProps (nextProps) { const { list, config } = nextProps if (list && config) { this.setState({ list: list.slice(), actOn: config.actOn || this.state.actOn }) } } private radioChange = (e) => { this.setState({ actOn: e.target.value }) } private save = () => { this.props.onSave({ actOn: this.state.actOn }) } public reset = () => { this.setState({ actOn: 'all' }) } public render () { const { onCancel } = this.props const { list, actOn } = this.state const radioList = [{ name: 'all' }].concat(list).map((l) => ( {l.name === 'all' ? l.name : decodeMetricName(l.name)} )) return (
{radioList}
) } } export default ActOnSettingForm