<commit_before>import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import * as formatActions from '../../actions/formatActions';
import FormatForm from './FormatForm';

class ManageFormatPage extends React.Component {
    constructor(props, context) {
        super(props, context);

        this.state = {
            format: Object.assign({}, props.format),
            errors: {}
        };
        
        
        this.updateFormatState = this.updateFormatState.bind(this);
        this.save = this.save.bind(this);
    }

    updateFormatState(event) {
        let field = event.target.name;
        let format = Object.assign({}, this.state.format);
        format[field] = event.target.value;
        return this.setState({format: format});
    }

    save(event) {
        event.preventDefault();
        this.props.actions
            .saveFormat(this.state.format)
            .then(() => this.redirectToFormatsPage());
    }

    redirectToFormatsPage() {
        this.context.router.history.push("/formats");
    }

    render() {
        return (
            <FormatForm
                format={this.state.format}
                errors={this.state.errors}
                onChange={this.updateFormatState}
                onSave={this.save} />
        );
    }
}

ManageFormatPage.propTypes = {
    format: PropTypes.object.isRequired,
    actions: PropTypes.object.isRequired
};

ManageFormatPage.contextTypes = {
    router: PropTypes.object
};

function mapStateToProps(state, ownProps) {
    let id = ownProps.match.params.id;
    let format;
    if (id) {<commit_msg>Format Page Show button 'save' disabled when saving in progress and indicate saving progress Close #3<commit_after>import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import * as formatActions from '../../actions/formatActions';
import FormatForm from './FormatForm';

class ManageFormatPage extends React.Component {
    constructor(props, context) {
        super(props, context);

        this.state = {
            format: Object.assign({}, props.format),
            saving: false,
            errors: {}
        };
        

        this.updateFormatState = this.updateFormatState.bind(this);
        this.save = this.save.bind(this);
    }

    updateFormatState(event) {
        let field = event.target.name;
        let format = Object.assign({}, this.state.format);
        format[field] = event.target.value;
        return this.setState({format: format});
    }

    save(event) {
        event.preventDefault();
        this.setState({ saving: true })
        this.props.actions
            .saveFormat(this.state.format)
            .then(() => {
                this.setState({ saving: false });
                this.redirectToFormatsPage();
            });
    }

    redirectToFormatsPage() {
        this.context.router.history.push("/formats");
    }

    render() {
        return (
            <FormatForm
                format={this.state.format}
                errors={this.state.errors}
                onChange={this.updateFormatState}
                onSave={this.save}
                saving={this.state.saving} />
        );
    }
}

ManageFormatPage.propTypes = {
    format: PropTypes.object.isRequired,
    actions: PropTypes.object.isRequired
};

ManageFormatPage.contextTypes = {
    router: PropTypes.object
};

function mapStateToProps(state, ownProps) {
    let id = ownProps.match.params.id;
    let format;
    if (id) {
{'fraction_non_alphanumeric': 0.12317844377233984, 'fraction_numerical': 0.00027495188342040145, 'mean_word_length': 2.2223206377325067, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5044', 'n_tokens_mistral': 1004, 'n_tokens_neox': 998, 'n_words': 200}