<commit_before>import React, { Component } from "react"
import { connect } from "react-redux"
import * as modalAction from "../../ducks/ui/modal"
import Option from "./Option"

function PureOptionHelp({help}){
    return <div className="help-block small">{help}</div>;
}
const OptionHelp = connect((state, {name}) => ({
    help: state.options[name].help,
}))(PureOptionHelp);

function PureOptionError({error}){
    if(!error) return null;
    return <div className="small text-danger">{error}</div>;
}
const OptionError = connect((state, {name}) => ({
    error: state.ui.optionsEditor[name] && state.ui.optionsEditor[name].error
}))(PureOptionError);

class PureOptionModal extends Component {

    constructor(props, context) {
        super(props, context)
        this.state = { title: 'Options' }
    }

    render() {
        const { hideModal, options } = this.props
        const { title } = this.state
        return (
            <div>
                <div className="modal-header">
                    <button type="button" className="close" data-dismiss="modal" onClick={() => {
                        hideModal()
                    }}>
                        <i className="fa fa-fw fa-times"></i>
                    </button>
                    <div className="modal-title">
                        <h4>{ title }</h4>
                    </div>
                </div>

                <div className="modal-body">
                    <div className="form-horizontal">
                        {
                            options.map(name =>
                                <div key={name} className="form-group">
                                    <div className="col-xs-6">
                                        <label htmlFor={name}>{name}</label>
                                        <OptionHelp name={name}/>
                                    </div>
                                    <div className="col-xs-6">
                                        <Option name={name}/>
                                        <OptionError name={name}/>
                                    </div>
                                </div>
                            )
                        }
                    </div>
                </div>

                <div className="modal-footer">
                </div>
            </div>
        )
    }
}

export default connect(
    state => ({<commit_msg>[web] Add default value suggester in option editor.<commit_after>import React, { Component } from "react"
import { connect } from "react-redux"
import * as modalAction from "../../ducks/ui/modal"
import Option from "./Option"
import _ from "lodash"

function PureOptionHelp({help}){
    return <div className="help-block small">{help}</div>;
}
const OptionHelp = connect((state, {name}) => ({
    help: state.options[name].help,
}))(PureOptionHelp);

function PureOptionError({error}){
    if(!error) return null;
    return <div className="small text-danger">{error}</div>;
}
const OptionError = connect((state, {name}) => ({
    error: state.ui.optionsEditor[name] && state.ui.optionsEditor[name].error
}))(PureOptionError);

function PureOptionDefault({value, defaultVal}){
    if( value === defaultVal ) {
        return null
    } else {
        if (typeof(defaultVal) === 'boolean') {
            defaultVal = defaultVal ? 'true' : 'false'
        } else if (Array.isArray(defaultVal)){
            if (_.isEmpty(_.compact(value)) && // filter the empty string in array
                _.isEmpty(defaultVal)){
                return null
            }
            defaultVal = '[ ]'
        } else if (defaultVal === ''){
            defaultVal = '\"\"'
        } else if (defaultVal === null){
            defaultVal = 'null'
        }
        return <div className="small">Default: <strong> {defaultVal} </strong> </div>
    }
}
const OptionDefault = connect((state, {name}) => ({
    value: state.options[name].value,
    defaultVal: state.options[name].default
}))(PureOptionDefault)

class PureOptionModal extends Component {

    constructor(props, context) {
        super(props, context)
        this.state = { title: 'Options' }
    }

    render() {
        const { hideModal, options } = this.props
        const { title } = this.state
        return (
            <div>
                <div className="modal-header">
                    <button type="button" className="close" data-dismiss="modal" onClick={() => {
                        hideModal()
                    }}>
                        <i className="fa fa-fw fa-times"></i>
                    </button>
                    <div className="modal-title">
                        <h4>{ title }</h4>
                    </div>
                </div>

                <div className="modal-body">
                    <div className="form-horizontal">
                        {
                            options.map(name =>
                                <div key={name} className="form-group">
                                    <div className="col-xs-6">
                                        <label htmlFor={name}>{name}</label>
                                        <OptionHelp name={name}/>
                                    </div>
                                    <div className="col-xs-6">
                                        <Option name={name}/>
                                        <OptionError name={name}/>
                                        <OptionDefault name={name}/>
                                    </div>
                                </div>
                            )
                        }
                    </div>
                </div>

                <div className="modal-footer">
                </div>
            </div>
        )
    }
}

export default connect(
    state => ({
{'fraction_non_alphanumeric': 0.13297963374978608, 'fraction_numerical': 0.0013691596782474755, 'mean_word_length': 1.2730455075845974, 'pattern_counts': {'":': 0, '<': 74, '<?xml version=': 0, '>': 85, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 21, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2879683', 'n_tokens_mistral': 1449, 'n_tokens_neox': 1381, 'n_words': 313}