<commit_before>import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Form, Button } from 'antd';
const FormItem = Form.Item;

const formItemLayout = {
  labelCol: {
    lg: { span: 3 },
    xs: { span: 24 },
    sm: { span: 4 },
  },
  wrapperCol: {
    lg: { span: 6 },
    xs: { span: 24 },
    sm: { span: 12 },
  },
};

const buttonLayout = {
  wrapperCol: {
    lg: { span: 6, offset: 3, },
    xs: { span: 24, offset: 0, },
    sm: { span: 12, offset: 4, },
  },
};

class SimpleForm extends Component {

  handleSubmit = (e) => {
    e.preventDefault();
    const { save } = this.props;
    this.props.form.validateFieldsAndScroll((error, values) => {
      if (!error) {
        save(values);
      }
    });

  };

  render() {

    const { children, model, translate, form: { getFieldDecorator } } = this.props;

    return (
      <Form
        onSubmit={this.handleSubmit}>
        {React.Children.map(children, ({ props: { source, input, options } }, index) => (
          <FormItem key={index} {...formItemLayout} label={translate(`models.${model}.fields.${source}`)} colon={false}>
            {getFieldDecorator(source, options)(input)}
          </FormItem>
        ))}
        <FormItem {...buttonLayout}>
          <Button type="primary" htmlType="submit">
            {translate('actions.create')}
          </Button>
        </FormItem>
      </Form>
    );
  }

}

SimpleForm.propTypes = {
  model: PropTypes.string.isRequired,
  save: PropTypes.func,
};

export default Form.create()(SimpleForm);<commit_msg>支持初始数据<commit_after>import React, { Component } from 'react';
import PropTypes from 'prop-types';
import mapValues from 'lodash/mapValues';
import { Form, Button } from 'antd';
const FormItem = Form.Item;

const formItemLayout = {
  labelCol: {
    lg: { span: 3 },
    xs: { span: 24 },
    sm: { span: 4 },
  },
  wrapperCol: {
    lg: { span: 6 },
    xs: { span: 24 },
    sm: { span: 12 },
  },
};

const buttonLayout = {
  wrapperCol: {
    lg: { span: 6, offset: 3, },
    xs: { span: 24, offset: 0, },
    sm: { span: 12, offset: 4, },
  },
};

class SimpleForm extends Component {

  handleSubmit = (e) => {
    e.preventDefault();
    const { save } = this.props;
    this.props.form.validateFieldsAndScroll((error, values) => {
      if (!error) {
        save(values);
      }
    });

  };

  render() {

    const { children, model, translate, form: { getFieldDecorator } } = this.props;

    return (
      <Form
        onSubmit={this.handleSubmit}>
        {React.Children.map(children, ({ props: { source, input, options } }, index) => (
          <FormItem key={index} {...formItemLayout} label={translate(`models.${model}.fields.${source}`)} colon={false}>
            {getFieldDecorator(source, options)(input)}
          </FormItem>
        ))}
        <FormItem {...buttonLayout}>
          <Button type="primary" htmlType="submit">
            {translate('actions.save')}
          </Button>
        </FormItem>
      </Form>
    );
  }

}

SimpleForm.propTypes = {
  model: PropTypes.string.isRequired,
  save: PropTypes.func,
  record: PropTypes.object,
};

export default Form.create({
  mapPropsToFields(props) {
    return mapValues(props.record || {}, value => ({ value }));
  },
})(SimpleForm);
{'fraction_non_alphanumeric': 0.1723928245667376, 'fraction_numerical': 0.010337488598358164, 'mean_word_length': 2.556756756756757, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '809201', 'n_tokens_mistral': 1111, 'n_tokens_neox': 1066, 'n_words': 239}