{"size": 1325, "ext": "js", "max_stars_repo_path": "src/public/js/containers/Configuration.js", "max_stars_repo_name": "Klakier/englishtable", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/public/js/containers/Configuration.js", "max_issues_repo_name": "Klakier/englishtable", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/public/js/containers/Configuration.js", "max_forks_repo_name": "Klakier/englishtable", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.8139534884, "max_line_length": 107, "alphanum_fraction": 0.6679245283}
import { connect } from 'react-redux';
import Table from '../components/Table';
import {toArray} from './../../../Utils/conversions';

import {configurationColumnTypeChanged, configurationColumnNameChanged} from './../reducers/configuration';

const toRows = (sourceWords, destinationWords) => {
    if(sourceWords.length !== destinationWords.length) {
        throw 'Source words collection has different size then destination words collection';
    }
    
    let result = [];
    for(let i = 0; i<sourceWords.length; i++) {
        result.push({
            no: i +1,
            sourceWord: sourceWords[i],
            destinationWord: destinationWords[i]
        });
    }
    
    return result;
};

const mapStateToProps = (state, ownProps) => {
    return {
        headers: toArray(state.configuration, 'key'),
        rows: toRows(state.dictionary.output.sourceWords,state.dictionary.output.destinationWords)
    };
};

const mapDispatchToProps = (dispatch, ownProps) => {
    return { 
        onOptionChanged: (data) => dispatch(configurationColumnTypeChanged(data.columnId, data.optionId)),
        onColumnNameChanged: (id, name) => dispatch(configurationColumnNameChanged(id, name)),
    };
};

const Configuration = connect(
    mapStateToProps,
    mapDispatchToProps
)(Table);

export default Configuration;