<commit_before>import React from 'react';
import ReactFireMixin from 'reactfire';
import Select from 'react-select';
import {Input, Button} from 'react-bootstrap';

var GroupSelect = React.createClass({
  mixins: [ReactFireMixin],

  getInitialState: function() {
    return {
      groupList: [],
      groupNameToAdd: ''
    };
  },

  componentWillMount: function() {
	this.bindAsArray(this.props.model.firebaseRef.child('userGroups').orderByChild('name'), 'groupList');
  },
  
  onGroupSelect: function(option) {
    var groupId = option.value;
  	this.props.onGroupSelect(null);
  },

  onGroupNameChange: function(e) {
    this.setState({groupNameToAdd: e.target.value})
  },

  onGroupAdd: function(e) {
    var users = {};
    users[this.props.model.uid] = true;
    this.props.model.firebaseRef.child('userGroups').push({
      name: this.state.groupNameToAdd,
      users: users
    });
  },

  render: function() {
    var _this = this;
    function createGroupItem(item, index){
      return <li key={index} onClick={_this.onGroupSelect.bind(null, item['.key'])}><a href="#">{item.name}</a></li>
    }
    var groupList = [];
    for(var gid in this.state.groupList){
      var group = this.state.groupList[gid];
      groupList.push({value: group['.key'], label: group.name});
    }
    return <div>
      <div className="input-group pull-left col-xs-5">
        <Select
          name="groupSelect"
          value={this.props.model.groupId}
          options={groupList}
          placeholder="Select a Group"
          onChange={this.onGroupSelect}
          />
      </div>
      <div className="input-group pull-right col-xs-4 input-sm"><commit_msg>Fixed group selection<commit_after>import React from 'react';
import ReactFireMixin from 'reactfire';
import {Input, Button, Select} from 'react-bootstrap';

var GroupSelect = React.createClass({
  mixins: [ReactFireMixin],

  getInitialState: function() {
    return {
      groupList: [],
      groupNameToAdd: ''
    };
  },

  componentWillMount: function() {
	this.bindAsArray(this.props.model.firebaseRef.child('userGroups').orderByChild('name'), 'groupList');
  },
  
  onGroupSelect: function(event) {
    var groupId = event.target.value;
  	this.props.onGroupSelect(groupId);
  },

  onGroupNameChange: function(e) {
    this.setState({groupNameToAdd: e.target.value})
  },

  onGroupAdd: function(e) {
    var users = {};
    users[this.props.model.uid] = true;
    this.props.model.firebaseRef.child('userGroups').push({
      name: this.state.groupNameToAdd,
      users: users
    });
  },

  render: function() {
    var _this = this;
    function createGroupOption(item, index){
      return <option key={index} value={item['.key']}>{item.name}</option>
    }
    var groupList = [];
    for(var gid in this.state.groupList){
      var group = this.state.groupList[gid];
      groupList.push({value: group['.key'], label: group.name});
    }
    return <div>
      <div className="input-group pull-left col-xs-5">
        <select value={this.props.model.groupId || ""} className="form-control" onChange={this.onGroupSelect}>
          {this.state.groupList.map(createGroupOption)}
        </select>
      </div>
      <div className="input-group pull-right col-xs-4 input-sm">
{'fraction_non_alphanumeric': 0.1539877300613497, 'fraction_numerical': 0.001226993865030675, 'mean_word_length': 3.268324607329843, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, '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': '734554', 'n_tokens_mistral': 1040, 'n_tokens_neox': 1029, 'n_words': 192}