<commit_before>import React, { PropTypes } from 'react';
import { Card, CardHeader, CardText } from 'material-ui/Card';
import TextField from 'material-ui/TextField';
import SelectField from 'material-ui/SelectField';
import MenuItem from 'material-ui/MenuItem';
import RaisedButton from 'material-ui/RaisedButton';
import UploadImagePreview from './uploadImagePreview.jsx';
import ProductService from '../products/productService';
import SupplierService from '../suppliers/supplierService';
import ProducerService from '../producers/producerService';

const styles = {
  fileUploadInput: {
    cursor: 'pointer',
    position: 'absolute',
    top: 0,
    bottom: 0,
    right: 0,
    left: 0,
    width: '100%',
    opacity: 0,
  },
  uploadButton: {
    marginTop: '10px',
  },
};

const submitForm = (submitFunction, event) => {
  event.preventDefault();
  const form = event.target;
  return submitFunction(new FormData(form))
    .then(() => form.reset());
};

class Forms extends React.Component {

  componentDidMount() {
    this.props.loadProductCategories();
    this.props.loadProducers();
    this.props.loadSuppliers();
  }

  render() {
    const {
      selectedFiles,
      selectedProductCategory,
      productCategories,
      selectedProducer,
      producers,
      selectedSupplier,
      suppliers,
      onSelectFile,
      loadProductCategories,
      loadProducers,
      loadSuppliers,
      selectProductCategory,
      selectProducer,
      selectSupplier,
    } = this.props;

    return (
      <div className="content">
        <Card className="form-card">
          <CardHeader title="Products" />
          <CardText>
            <form name="products" onSubmit={event => submitForm(ProductService.saveProduct, event)}>
              <TextField floatingLabelText="Name" name="name" type="text" fullWidth />

              <SelectField
                floatingLabelText="Category"
                value={selectedProductCategory}
                onChange={(event, index, value) => selectProductCategory(value)}
                autoWidth
              >
                {productCategories.map(category => (
                  <MenuItem value={category} key={category} primaryText={category} />
                ))}
              </SelectField>

              <TextField
                floatingLabelText="Short Description"
                name="shortDescription"
                type="text"
                multiLine
                rows={3}
                fullWidth
              />

              <TextField
                floatingLabelText="Description"
                name="description"
                type="text"
                multiLine
                rows={5}
                fullWidth
              />

              <TextField floatingLabelText="Price" name="price" type="number" fullWidth />
              <TextField
                floatingLabelText="Purchase Price"
                name="purchasePrice"
                type="number"
                fullWidth
              />
              <TextField
                floatingLabelText="Purchase Package Size"
                name="purchasePackageSize"
                type="number"
                fullWidth
              />

              <TextField
                floatingLabelText="Stock"
                name="stock"
                defaultValue="0"
                type="number"
                fullWidth
              />

              <TextField
                floatingLabelText="Stock Minimum"
                name="minStock"
                defaultValue="0"
                type="number"
                fullWidth
              />

              <SelectField
                floatingLabelText="Supplier"
                value={suppliers.find(supplier => supplier._id === selectedSupplier)}
                onChange={(event, index, value) => selectSupplier(value)}
                autoWidth
              >
                {suppliers.map(supplier => (
                  <MenuItem value={supplier._id} key={supplier._id} primaryText={supplier.name} />
                ))}
              </SelectField>

              <TextField
                floatingLabelText="Supplier Product Code"
                name="supplierProductCode"
                type="text"
                fullWidth
              />

              <SelectField
                floatingLabelText="Producer"
                value={producers.find(producer => producer._id === selectedProducer)}
                onChange={(event, index, value) => selectProducer(value)}
                autoWidth
              >
                {producers.map(producer => (
                  <MenuItem value={producer._id} key={producer._id} primaryText={producer.name} />
                ))}
              </SelectField>

              <TextField
                floatingLabelText="Remarks"
                name="remarks"
                type="text"
                multiLine
                fullWidth<commit_msg>fix wrong property value of select field<commit_after>import React, { PropTypes } from 'react';
import { Card, CardHeader, CardText } from 'material-ui/Card';
import TextField from 'material-ui/TextField';
import SelectField from 'material-ui/SelectField';
import MenuItem from 'material-ui/MenuItem';
import RaisedButton from 'material-ui/RaisedButton';
import UploadImagePreview from './uploadImagePreview.jsx';
import ProductService from '../products/productService';
import SupplierService from '../suppliers/supplierService';
import ProducerService from '../producers/producerService';

const styles = {
  fileUploadInput: {
    cursor: 'pointer',
    position: 'absolute',
    top: 0,
    bottom: 0,
    right: 0,
    left: 0,
    width: '100%',
    opacity: 0,
  },
  uploadButton: {
    marginTop: '10px',
  },
};

const submitForm = (submitFunction, event) => {
  event.preventDefault();
  const form = event.target;
  return submitFunction(new FormData(form))
    .then(() => form.reset());
};

class Forms extends React.Component {

  componentDidMount() {
    this.props.loadProductCategories();
    this.props.loadProducers();
    this.props.loadSuppliers();
  }

  render() {
    const {
      selectedFiles,
      selectedProductCategory,
      productCategories,
      selectedProducer,
      producers,
      selectedSupplier,
      suppliers,
      onSelectFile,
      loadProductCategories,
      loadProducers,
      loadSuppliers,
      selectProductCategory,
      selectProducer,
      selectSupplier,
    } = this.props;

    return (
      <div className="content">
        <Card className="form-card">
          <CardHeader title="Products" />
          <CardText>
            <form name="products" onSubmit={event => submitForm(ProductService.saveProduct, event)}>
              <TextField floatingLabelText="Name" name="name" type="text" fullWidth />

              <SelectField
                floatingLabelText="Category"
                value={selectedProductCategory}
                onChange={(event, index, value) => selectProductCategory(value)}
                autoWidth
              >
                {productCategories.map(category => (
                  <MenuItem value={category} key={category} primaryText={category} />
                ))}
              </SelectField>

              <TextField
                floatingLabelText="Short Description"
                name="shortDescription"
                type="text"
                multiLine
                rows={3}
                fullWidth
              />

              <TextField
                floatingLabelText="Description"
                name="description"
                type="text"
                multiLine
                rows={5}
                fullWidth
              />

              <TextField floatingLabelText="Price" name="price" type="number" fullWidth />
              <TextField
                floatingLabelText="Purchase Price"
                name="purchasePrice"
                type="number"
                fullWidth
              />
              <TextField
                floatingLabelText="Purchase Package Size"
                name="purchasePackageSize"
                type="number"
                fullWidth
              />

              <TextField
                floatingLabelText="Stock"
                name="stock"
                defaultValue="0"
                type="number"
                fullWidth
              />

              <TextField
                floatingLabelText="Stock Minimum"
                name="minStock"
                defaultValue="0"
                type="number"
                fullWidth
              />

              <SelectField
                floatingLabelText="Supplier"
                value={(suppliers.find(supplier => supplier._id === selectedSupplier) || {})._id}
                onChange={(event, index, value) => selectSupplier(value)}
                autoWidth
              >
                {suppliers.map(supplier => (
                  <MenuItem value={supplier._id} key={supplier._id} primaryText={supplier.name} />
                ))}
              </SelectField>

              <TextField
                floatingLabelText="Supplier Product Code"
                name="supplierProductCode"
                type="text"
                fullWidth
              />

              <SelectField
                floatingLabelText="Producer"
                value={(producers.find(producer => producer._id === selectedProducer) || {})._id}
                onChange={(event, index, value) => selectProducer(value)}
                autoWidth
              >
                {producers.map(producer => (
                  <MenuItem value={producer._id} key={producer._id} primaryText={producer.name} />
                ))}
              </SelectField>

              <TextField
                floatingLabelText="Remarks"
                name="remarks"
                type="text"
                multiLine
                fullWidth
{'fraction_non_alphanumeric': 0.10059112313395452, 'fraction_numerical': 0.002805330127241759, 'mean_word_length': 1.6028683181225554, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 71, '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': '7360981', 'n_tokens_mistral': 2493, 'n_tokens_neox': 2334, 'n_words': 459}