<commit_before>import React, {Component, PropTypes} from 'react';
import CategoriesActions from './../../actions/categories/categories.actions.js';
import DialogActions from './../../actions/dialog/dialog.actions.js';
import serialize from 'form-serialize';
import {Form, Input, Select, Button} from 'react-validation';
import PureRenderMixin from 'react-addons-pure-render-mixin';

export class CategoriesEditUnwrapped extends Component {
    constructor(props) {
        super(props);

        this.onClick = this.onClick.bind(this);
        this.onSubmit = this.onSubmit.bind(this);
        this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
    }

    onClick(event) {
        event.preventDefault();

        CategoriesActions.delete(this.props.category);
        DialogActions.close();
    }

    onSubmit(event) {
        let data = serialize(event.target, {hash: true});

        event.preventDefault();

        if (this.props.category._id) {
            CategoriesActions.put(data);
        } else {
            CategoriesActions.post(data);
        }

        DialogActions.close();
    }

    render() {
        let id = this.props.category._id ? <input type='hidden' name='_id' value={this.props.category._id}/> : null;
        let deleteButton = this.props.category._id ? <div className='medium-6 columns'>
            <div>Remove category</div>
            <button onClick={this.onClick} className='button alert'>Delete</button>
        </div> : null;

        return <div>
            <h3>Add Product</h3>
            <Form className='category__upsert' onSubmit={this.onSubmit}>
                {id}
                <div className='row'>
                    <div className='medium-6 columns'>
                        <label>Title
                            <Input className='ui-input' value={this.props.category.title} name='title' type='text' placeholder='Title'/>
                        </label>
                    </div>
                    {deleteButton}
                </div>
                <div className='row'>
                    <div className='medium-6 columns'>
                        <div className='button-group'>
                            <Button className='success button' type='submit' value='Submit'/>
                            <button className='alert button' type='reset' onClick={DialogActions.close}>Cancel</button>
                        </div>
                    </div>
                </div>
            </Form>
            <button className='close-button' type='button' onClick={DialogActions.close}>
                <span aria-hidden='true'>&times;</span>
            </button>
        </div>;
    }
}

CategoriesEditUnwrapped.propTypes = {
    category: PropTypes.shape({
        _id: PropTypes.string,
        title: PropTypes.string
    }),
    categories: PropTypes.array
};

CategoriesEditUnwrapped.defaultProps = {
    category: {},
    categories: []
};

const CategoriesEdit = CategoriesEditUnwrapped;

export default CategoriesEdit;<commit_msg>Minor style fix<commit_after>import React, {Component, PropTypes} from 'react';
import CategoriesActions from './../../actions/categories/categories.actions.js';
import DialogActions from './../../actions/dialog/dialog.actions.js';
import serialize from 'form-serialize';
import {Form, Input, Select, Button} from 'react-validation';
import PureRenderMixin from 'react-addons-pure-render-mixin';

export class CategoriesEditUnwrapped extends Component {
    constructor(props) {
        super(props);

        this.onClick = this.onClick.bind(this);
        this.onSubmit = this.onSubmit.bind(this);
        this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
    }

    onClick(event) {
        event.preventDefault();

        CategoriesActions.delete(this.props.category);
        DialogActions.close();
    }

    onSubmit(event) {
        let data = serialize(event.target, {hash: true});

        event.preventDefault();

        if (this.props.category._id) {
            CategoriesActions.put(data);
        } else {
            CategoriesActions.post(data);
        }

        DialogActions.close();
    }

    render() {
        let id = this.props.category._id ? <input type='hidden' name='_id' value={this.props.category._id}/> : null;
        let deleteButton = this.props.category._id ? <div className='medium-6 columns'>
            <label>Remove category</label>
            <button onClick={this.onClick} className='button alert'>Delete</button>
        </div> : null;

        return <div>
            <h3>Add Product</h3>
            <Form className='category__upsert' onSubmit={this.onSubmit}>
                {id}
                <div className='row'>
                    <div className='medium-6 columns'>
                        <label>Title
                            <Input className='ui-input' value={this.props.category.title} name='title' type='text' placeholder='Title'/>
                        </label>
                    </div>
                    {deleteButton}
                </div>
                <div className='row'>
                    <div className='medium-6 columns'>
                        <div className='button-group'>
                            <Button className='success button' type='submit' value='Submit'/>
                            <button className='alert button' type='reset' onClick={DialogActions.close}>Cancel</button>
                        </div>
                    </div>
                </div>
            </Form>
            <button className='close-button' type='button' onClick={DialogActions.close}>
                <span aria-hidden='true'>&times;</span>
            </button>
        </div>;
    }
}

CategoriesEditUnwrapped.propTypes = {
    category: PropTypes.shape({
        _id: PropTypes.string,
        title: PropTypes.string
    }),
    categories: PropTypes.array
};

CategoriesEditUnwrapped.defaultProps = {
    category: {},
    categories: []
};

const CategoriesEdit = CategoriesEditUnwrapped;

export default CategoriesEdit;
{'fraction_non_alphanumeric': 0.1283739302172482, 'fraction_numerical': 0.0016458196181698486, 'mean_word_length': 2.049172102358254, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 69, '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': '3433160', 'n_tokens_mistral': 1596, 'n_tokens_neox': 1546, 'n_words': 307}