<commit_before>"use strict";

import React, { Component, PropTypes } from "react";

import CheckBox from 'metabase/components/CheckBox.react';

import { capitalize } from "metabase/lib/formatting";

import cx from "classnames";

export default class SelectPicker extends Component {
    selectValue(key, selected) {
        let values;
        if (this.props.multi) {
            values = this.props.values.slice().filter(v => v != null);
        } else {
            values = []
        }
        if (selected) {
            values.push(key);
        } else {
            values = values.filter(v => v !== key);
        }
        this.props.onValuesChange(values);
    }

    nameForOption(option) {
        if (option.name === "") {
            return "Empty";
        } else if (typeof option.name === "string") {
            return option.name;
        } else {
            return capitalize(String(option.name));
        }
    }

    render() {
        let { values, options, placeholder, multi } = this.props;

        let checked = {};
        for (let value of values) {
            checked[value] = true;
        }

        return (
            <div className="px1 pt1" style={{maxHeight: '400px', overflowY: 'scroll'}}>
                { placeholder ?
                    <h5>{placeholder}</h5>
                : null }
                { multi && false ?
                    <ul>
                        {options.map((option, index) =>
                            <li key={index}>
                                <label className="flex align-center cursor-pointer p1" onClick={() => this.selectValue(option.key, !checked[option.key])}>
                                    <CheckBox checked={checked[option.key]} />
                                    <h4 className="ml1">{this.nameForOption(option)}</h4>
                                </label>
                            </li>
                        )}
                    </ul>
                :
                    <div className="flex flex-wrap py1">
                        {options.map((option, index) =>
                            <div className="half" style={{ padding: "0.15em" }}>
                                <button
                                    style={{ height: "95px" }}
                                    className={cx("full rounded bordered border-purple text-centered text-bold", {
                                        "text-purple bg-white": values[0] !== option.key,
                                        "text-white bg-purple-light": values[0] === option.key
                                    })}
                                    onClick={() => this.selectValue(option.key, true)}
                                >
                                    {this.nameForOption(option)}
                                </button>
                            </div>
                        )}
                    </div>
                }

            </div>
        );<commit_msg>Reenable accidentally disabled multi select<commit_after>"use strict";

import React, { Component, PropTypes } from "react";

import CheckBox from 'metabase/components/CheckBox.react';

import { capitalize } from "metabase/lib/formatting";

import cx from "classnames";

export default class SelectPicker extends Component {
    selectValue(key, selected) {
        let values;
        if (this.props.multi) {
            values = this.props.values.slice().filter(v => v != null);
        } else {
            values = []
        }
        if (selected) {
            values.push(key);
        } else {
            values = values.filter(v => v !== key);
        }
        this.props.onValuesChange(values);
    }

    nameForOption(option) {
        if (option.name === "") {
            return "Empty";
        } else if (typeof option.name === "string") {
            return option.name;
        } else {
            return capitalize(String(option.name));
        }
    }

    render() {
        let { values, options, placeholder, multi } = this.props;

        let checked = {};
        for (let value of values) {
            checked[value] = true;
        }

        return (
            <div className="px1 pt1" style={{maxHeight: '400px', overflowY: 'scroll'}}>
                { placeholder ?
                    <h5>{placeholder}</h5>
                : null }
                { multi ?
                    <ul>
                        {options.map((option, index) =>
                            <li key={index}>
                                <label className="flex align-center cursor-pointer p1" onClick={() => this.selectValue(option.key, !checked[option.key])}>
                                    <CheckBox checked={checked[option.key]} />
                                    <h4 className="ml1">{this.nameForOption(option)}</h4>
                                </label>
                            </li>
                        )}
                    </ul>
                :
                    <div className="flex flex-wrap py1">
                        {options.map((option, index) =>
                            <div className="half" style={{ padding: "0.15em" }}>
                                <button
                                    style={{ height: "95px" }}
                                    className={cx("full rounded bordered border-purple text-centered text-bold", {
                                        "text-purple bg-white": values[0] !== option.key,
                                        "text-white bg-purple-light": values[0] === option.key
                                    })}
                                    onClick={() => this.selectValue(option.key, true)}
                                >
                                    {this.nameForOption(option)}
                                </button>
                            </div>
                        )}
                    </div>
                }

            </div>
        );
{'fraction_non_alphanumeric': 0.12024786467928321, 'fraction_numerical': 0.006364093116730866, 'mean_word_length': 1.0671512634129456, 'pattern_counts': {'":': 4, '<': 41, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4630708', 'n_tokens_mistral': 1456, 'n_tokens_neox': 1393, 'n_words': 299}