<commit_before>import React from 'react';
import ActionInsertItem from './actionInsertItem.jsx';

class ActionInsert extends React.Component {
    constructor(props) {
        super(props);

        //Set initial state
        this.state = {
            isDisabled: true,
            numItems: 1
        };

        //Bind functions to this context 
        this.onSubmit = this.onSubmit.bind(this);
        this.handleChange = this.handleChange.bind(this);
        this.addItem = this.addItem.bind(this);
        this.removeItem = this.removeItem.bind(this);

        this.insertKeys = [];
        this.insertVals = [];
    }

    onSubmit(e) {
        e.preventDefault();

        let insertStr = '{';
        
        for(let x = 0; x < this.state.numItems; x++) {
            let insertValStr = encodeURIComponent(this.insertVals[x].value);
        
            if(this.insertKeys[x].value) {
                //If the insert value is a string, make sure it satrts and end with double quotes
                if(isNaN(insertValStr) && insertValStr[0] !== '"' && insertValStr[insertValStr.length - 1] !== '"') {
                    //If single quotes were used replace them with double quotes, else just add double quotes 
                    if(insertValStr[0] === "'" && insertValStr[insertValStr.length - 1] === "'") {
                        insertValStr = insertValStr.replace("'" , '"');
                        insertValStr = insertValStr.replace("'" , '"');
                    } else {
                        insertValStr = '"' + insertValStr + '"';
                    }
                }

                insertStr += '"' + encodeURIComponent(this.insertKeys[x].value) + '": ' + insertValStr + ','; 
            }
        }
        insertStr += '}';
        insertStr = insertStr.replace(',}', '}');

        this.props.onInsert(insertStr);
    }

    handleChange(index, insertKey, insertVal) {
        //Store keys and values to be insertted on form submit 
        this.insertKeys[index] = insertKey;
        this.insertVals[index] = insertVal;

        //Determine whether to enable button or not 
        if(insertKey && insertVal && insertKey.value.toString().trim() !== '' && insertVal.value.toString().trim() !== '') {
            this.setState({ isDisabled: false });
        } else {
            this.setState({ isDisabled: true });
        }
    }

    addItem() {
        this.setState({ numItems: this.state.numItems + 1 });
    }
<commit_msg>Added ability to insert a boolean value<commit_after>import React from 'react';
import ActionInsertItem from './actionInsertItem.jsx';

class ActionInsert extends React.Component {
    constructor(props) {
        super(props);

        //Set initial state
        this.state = {
            isDisabled: true,
            numItems: 1
        };

        //Bind functions to this context 
        this.onSubmit = this.onSubmit.bind(this);
        this.handleChange = this.handleChange.bind(this);
        this.addItem = this.addItem.bind(this);
        this.removeItem = this.removeItem.bind(this);

        this.insertKeys = [];
        this.insertVals = [];
    }

    onSubmit(e) {
        e.preventDefault();

        let insertStr = '{';
        
        for(let x = 0; x < this.state.numItems; x++) {
            let insertValStr = encodeURIComponent(this.insertVals[x].value);
        
            if(this.insertKeys[x].value) {
                //If the insert value is a string, make sure it satrts and end with double quotes
                if(isNaN(insertValStr) && insertValStr[0] !== '"' && insertValStr[insertValStr.length - 1] !== '"') {
                    //If single quotes were used replace them with double quotes, else just add double quotes 
                    if(insertValStr[0] === "'" && insertValStr[insertValStr.length - 1] === "'") {
                        insertValStr = insertValStr.replace("'" , '"');
                        insertValStr = insertValStr.replace("'" , '"');
                    } else if(insertValStr.trim() !== 'true' && insertValStr.trim() !== 'false') { //Else, its a string and not a bool value
                        insertValStr = '"' + insertValStr + '"';
                    }
                }

                insertStr += '"' + encodeURIComponent(this.insertKeys[x].value) + '": ' + insertValStr + ','; 
            }
        }
        insertStr += '}';
        insertStr = insertStr.replace(',}', '}');

        this.props.onInsert(insertStr);
    }

    handleChange(index, insertKey, insertVal) {
        //Store keys and values to be insertted on form submit 
        this.insertKeys[index] = insertKey;
        this.insertVals[index] = insertVal;

        //Determine whether to enable button or not 
        if(insertKey && insertVal && insertKey.value.toString().trim() !== '' && insertVal.value.toString().trim() !== '') {
            this.setState({ isDisabled: false });
        } else {
            this.setState({ isDisabled: true });
        }
    }

    addItem() {
        this.setState({ numItems: this.state.numItems + 1 });
    }

{'fraction_non_alphanumeric': 0.13731284475965327, 'fraction_numerical': 0.0027580772261623326, 'mean_word_length': 1.879750425411231, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, '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': '102858', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1374, 'n_words': 305}