<commit_before>import React, { Component, PropTypes } from 'react';
import { Draggable, Droppable } from './Draggable';
import ResponseSetWidget from './ResponseSetWidget';
import { responseSetsProps } from '../prop-types/response_set_props';
import _ from 'lodash';

let setData = function(){
  return {"json/responseSet": JSON.stringify(this.props.responseSet)};
};

let DraggableResponseSet = Draggable(ResponseSetWidget, setData);

let onDrop = (evt, self) => {
  let rs = JSON.parse(evt.dataTransfer.getData("json/responseSet"));
  if(!self.props.selectedResponseSets.find((r) => {
    return r.id == rs.id;
  })) {
    self.props.handleResponseSetsChange(self.props.selectedResponseSets.concat([rs]));
  }
};

class DropTarget extends Component {

  render() {
    let isValidDrop = this.props.isValidDrop;
    let selectedResponseSets = this.props.selectedResponseSets || [];

    let removeResponseSet = (id) => {
      this.props.handleResponseSetsChange(this.props.selectedResponseSets.filter((rs) => rs.id != id));
    };

    return (
      <div style={{minHeight: '40px', backgroundColor:isValidDrop?'green':'grey'}}>
        {selectedResponseSets.map((rs, i) => {
          return (
          <div key={i}>
          <i className='pull-right fa fa-close' onClick={() => removeResponseSet(rs.id)}/>
          <DraggableResponseSet responseSet={rs}/>
          </div>);
        })}
        <select readOnly={true} value={selectedResponseSets.map((rs) => rs.id )} name="linked_response_sets[]" id="linked_response_sets" size="5" multiple="multiple" className="form-control"  style={{display: 'none'}}>
          {selectedResponseSets.map((rs) => {
            return <option key={rs.id} value={rs.id}>a</option>;
          })}
        </select>
      </div>
    );
  }
}

DropTarget.propTypes = {
  handleResponseSetsChange: PropTypes.func.isRequired,
  selectedResponseSets: PropTypes.array,
  isValidDrop: PropTypes.bool
};

let DroppableTarget = Droppable(DropTarget, onDrop);

class ResponseSetDragWidget extends Component{
  render(){
    if(!this.props.responseSets){
      return (<div>Loading....</div>);
    }
    return (
      <div className="row response-set-row">
          <div className="col-md-6 question-form-group">
              <div className="fixed-height-list" name="linked_response_sets">
                {this.props.responseSets && _.values(this.props.responseSets).map((rs, i) => {
                  return <DraggableResponseSet key={i} responseSet={rs}/>;
                })}
              </div>
          </div>
          <div className="col-md-6 drop-target selected_response_sets" name="selected_response_sets">
            <DroppableTarget handleResponseSetsChange={this.props.handleResponseSetsChange} selectedResponseSets={this.props.selectedResponseSets} />
          </div>
      </div>
    );
  }
}

ResponseSetDragWidget.propTypes = {
  responseSets: responseSetsProps.isRequired,
  selectedResponseSets: PropTypes.array,
  handleResponseSetsChange: PropTypes.func.isRequired
};

export default ResponseSetDragWidget;
<commit_msg>Added ES to question edit, drag and drop broken now<commit_after>import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { Draggable, Droppable } from './Draggable';
import ResponseSetWidget from './ResponseSetWidget';
import SearchResult from './SearchResult';
import DashboardSearch from '../components/DashboardSearch';
import currentUserProps from '../prop-types/current_user_props';
import { fetchSearchResults, fetchMoreSearchResults } from '../actions/search_results_actions';
import { responseSetsProps } from '../prop-types/response_set_props';
import _ from 'lodash';

let setData = function(){
  return {"json/responseSet": JSON.stringify(this.props.responseSet)};
};

let DraggableResponseSet = Draggable(SearchResult, setData);

let onDrop = (evt, self) => {
  let rs = JSON.parse(evt.dataTransfer.getData("json/responseSet"));
  if(!self.props.selectedResponseSets.find((r) => {
    return r.id == rs.id;
  })) {
    self.props.handleResponseSetsChange(self.props.selectedResponseSets.concat([rs]));
  }
};

class DropTarget extends Component {

  render() {
    let isValidDrop = this.props.isValidDrop;
    let selectedResponseSets = this.props.selectedResponseSets || [];

    let removeResponseSet = (id) => {
      this.props.handleResponseSetsChange(this.props.selectedResponseSets.filter((rs) => rs.id != id));
    };

    return (
      <div style={{minHeight: '440px', backgroundColor:isValidDrop?'green':'grey'}}>
        {selectedResponseSets.map((rs, i) => {
          return (
          <div key={i}>
          <i className='pull-right fa fa-close' onClick={() => removeResponseSet(rs.id)}/>
          <DraggableResponseSet type='response_set' result={{Source: rs}} currentUser={{id: -1}} />
          </div>);
        })}
        <select readOnly={true} value={selectedResponseSets.map((rs) => rs.id )} name="linked_response_sets[]" id="linked_response_sets" size="5" multiple="multiple" className="form-control"  style={{display: 'none'}}>
          {selectedResponseSets.map((rs) => {
            return <option key={rs.id} value={rs.id}>a</option>;
          })}
        </select>
      </div>
    );
  }
}

DropTarget.propTypes = {
  handleResponseSetsChange: PropTypes.func.isRequired,
  selectedResponseSets: PropTypes.array,
  isValidDrop: PropTypes.bool
};

let DroppableTarget = Droppable(DropTarget, onDrop);

class ResponseSetDragWidget extends Component {
  constructor(props){
    super(props);
    this.search = this.search.bind(this);
    this.loadMore = this.loadMore.bind(this);
    this.state = {
      searchTerms: '',
      page: 1
    };
  }

  componentWillMount() {
    this.search('');
  }

  search(searchTerms) {
    if(searchTerms === ''){
      searchTerms = null;
    }
    this.setState({searchTerms: searchTerms});
    this.props.fetchSearchResults(searchTerms, 'response_set');
  }

  loadMore() {
    let searchTerms = this.state.searchTerms;
    let tempState = this.state.page + 1;
    if(this.state.searchTerms === '') {
      searchTerms = null;
    }
    this.props.fetchMoreSearchResults(searchTerms, 'response_set', tempState);
    this.setState({page: tempState});
  }

  render(){
    const searchResults = this.props.searchResults;
    return (
      <div className="row response-set-row">
        <div className="col-md-6 question-form-group">
          <DashboardSearch search={this.search} />
          <div className="fixed-height-list" name="linked_response_sets">
            {searchResults.hits && searchResults.hits.hits.map((rs, i) => {
              return <DraggableResponseSet key={i} type={rs.Type} result={rs}
                      currentUser={this.props.currentUser} />;
            })}
          </div>
        </div>
        <div className="col-md-6 drop-target selected_response_sets" name="selected_response_sets">
          <DroppableTarget handleResponseSetsChange={this.props.handleResponseSetsChange} selectedResponseSets={this.props.selectedResponseSets} />
        </div>
      </div>
    );
  }
}

function mapStateToProps(state) {
  return {
    searchResults: state.searchResults,
    currentUser: state.currentUser
  };
}

function mapDispatchToProps(dispatch) {
  return bindActionCreators({fetchSearchResults, fetchMoreSearchResults}, dispatch);
}

ResponseSetDragWidget.propTypes = {
  responseSets: responseSetsProps.isRequired,
  selectedResponseSets: PropTypes.array,
  fetchSearchResults: PropTypes.func,
  fetchMoreSearchResults: PropTypes.func,
  currentUser: currentUserProps,
  searchResults: PropTypes.object,
  handleResponseSetsChange: PropTypes.func.isRequired
};

export default connect(mapStateToProps, mapDispatchToProps)(ResponseSetDragWidget);

{'fraction_non_alphanumeric': 0.14150702426564496, 'fraction_numerical': 0.0017879948914431673, 'mean_word_length': 3.65576694411415, 'pattern_counts': {'":': 2, '<': 46, '<?xml version=': 0, '>': 64, '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': '3943986', 'n_tokens_mistral': 2317, 'n_tokens_neox': 2313, 'n_words': 412}