<commit_before>import React from 'react';
import {Select} from 'antd';
import {autobind} from 'core-decorators';
import partial from '../partial';

const _ = {compact: require('lodash/compact')};

const Component = React.Component;
const Option = Select.Option;

export default class Dimensions extends Component {
    static defaultProps = {
        dimensions: [],
        selectedDimensions: [],
        onChange: function () {}
    };

    @autobind
    toggleDimension(iDimension, value) {
        const dimension = value;
        const dimensions = this.props.selectedDimensions;
        const curIdx = dimensions.indexOf(dimension);

        if (curIdx >= 0) dimensions[curIdx] = null;
        dimensions[iDimension] = dimension;

        const updatedDimensions = _.compact(dimensions);

        this.props.onChange(updatedDimensions);
    }

    @autobind
    renderDimension(selectedDimension, i) {
        return (
            <Select
              size="small"
              value={selectedDimension}
              onSelect={partial(this.toggleDimension, i)}
              key={selectedDimension} >
                {this.props.dimensions.map((dimension) => {
                    return (
                        <Option
                          value={dimension.title}
                          key={dimension.title} >
                            {dimension.title}
                        </Option>
                    );
                })}
            </Select>
        );
    }

    render() {
        const selectedDimensions = this.props.selectedDimensions;
        const nSelected = selectedDimensions.length;

        return (
            <div className="reactPivot-dimensions">
                {selectedDimensions.map(this.renderDimension)}

                <Select size="small" defaultValue="" onSelect={partial(this.toggleDimension, nSelected)}>
                    <Option value={''} disabled>Subdimensión...</Option>
                    {this.props.dimensions.map((dimension) => {
                        return <Option value={dimension.title} key={dimension.title}>{dimension.title}</Option>;
                    })}
                </Select>
            </div>
        );
    }
}<commit_msg>Improved dimensinons logic<commit_after>import React from 'react';
import {Select} from 'antd';
import {autobind} from 'core-decorators';
import partial from '../partial';

const _ = {compact: require('lodash/compact')};

const Component = React.Component;
const Option = Select.Option;

export default class Dimensions extends Component {
    static defaultProps = {
        dimensions: [],
        selectedDimensions: [],
        onChange: function () {}
    };

    @autobind
    toggleDimension(iDimension, value) {
        const dimension = value;
        const dimensions = this.props.selectedDimensions;
        const curIdx = dimensions.indexOf(dimension);

        if (curIdx >= 0) dimensions[curIdx] = null;
        dimensions[iDimension] = dimension;

        const updatedDimensions = _.compact(dimensions);

        this.props.onChange(updatedDimensions);
    }

    @autobind
    renderDimension(selectedDimension, i) {
        return (
            <Select
              size="small"
              value={selectedDimension}
              onSelect={partial(this.toggleDimension, i)}
              key={selectedDimension} >
                {this.props.dimensions.map((dimension) => {
                    return (
                        <Option
                          value={dimension.title}
                          key={dimension.title} >
                            {dimension.title}
                        </Option>
                    );
                })}
            </Select>
        );
    }

    render() {
        const selectedDimensions = this.props.selectedDimensions;
        const nSelected = selectedDimensions.length;

        if (nSelected < this.props.dimensions.length) {
            return (
                <div className="reactPivot-dimensions">
                    {selectedDimensions.map(this.renderDimension)}

                    <Select size="small" defaultValue="" onSelect={partial(this.toggleDimension, nSelected)}>
                        <Option value={''} disabled>Subdimensión...</Option>
                        {this.props.dimensions.map((dimension) => {
                            return <Option value={dimension.title} key={dimension.title}>{dimension.title}</Option>;
                        })}
                    </Select>
                </div>
            );
        }

        return (
            <div className="reactPivot-dimensions">
                {selectedDimensions.map(this.renderDimension)}
            </div>
        );
    }
}
{'fraction_non_alphanumeric': 0.11096992799661161, 'fraction_numerical': 0.00042354934349851756, 'mean_word_length': 1.7081422018348624, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 35, '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': '3012543', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1137, 'n_words': 218}