<commit_before>/*
 * This file is part of the Kreta package.
 *
 * (c) <NAME> <<EMAIL>>
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

import AddIcon from './../../../svg/add';
import ListIcon from './../../../svg/list';

import React from 'react';
import {Link} from 'react-router';
import {connect} from 'react-redux';
import {routeActions} from 'react-router-redux';
import classNames from 'classnames';

import Button from './../../component/Button';
import Icon from './../../component/Icon';
import NavigableList from './../../component/NavigableList';
import ResourcePreview from './../../component/ResourcePreview';
import ShortcutHelp from './../../component/ShortcutHelp';
import {Row, RowColumn} from './../../component/Grid';

@connect(state => ({projects: state.projects.projects}))
class List extends React.Component {
  static propTypes = {
    onProjectSelected: React.PropTypes.func
  };

  state = {
    selectedProject: 0,
    selectedShortcut: 0,
    filter: '',
    filteredProjects: []
  };

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

  onKeyUp(ev) {
    if (ev.which === 13) { // Enter
      this.goToShortcutLink(this.state.selectedShortcut);
    } else if (ev.which < 37 || ev.which > 40) { // Filter
      this.filterProjects(ev.currentTarget.value);
    } else {
      this.refs.navigableList.handleNavigation(ev);
    }

    ev.stopPropagation();
  }

  filterProjects(value) {
    const filteredProjects = this.props.projects.filter(project => (
      value.length === 0 || project.node.name.indexOf(value) > -1
    ));
    this.setState({
      filteredProjects,
      selectedProject: 0
    });
  }

  changeSelectedRow(index) {
    this.setState({selectedProject: index});
  }

  changeSelectedShortcut(index) {
    this.setState({selectedShortcut: index});
  }

  goToShortcutLink(index) {
    const shortcutLinks = ['/', '/issue/new'];
    this.props.dispatch(
      routeActions.push(
        `/project/${this.state.filteredProjects[this.state.selectedProject].id}${shortcutLinks[index]}`
      )
    );
    this.triggerOnProjectSelected();
  }

  triggerOnProjectSelected() {<commit_msg>Fixed bug related with projects load inside modal<commit_after>/*
 * This file is part of the Kreta package.
 *
 * (c) <NAME> <<EMAIL>>
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

import AddIcon from './../../../svg/add';
import ListIcon from './../../../svg/list';

import React from 'react';
import {Link} from 'react-router';
import {connect} from 'react-redux';
import {routeActions} from 'react-router-redux';
import classNames from 'classnames';

import Button from './../../component/Button';
import Icon from './../../component/Icon';
import NavigableList from './../../component/NavigableList';
import ResourcePreview from './../../component/ResourcePreview';
import ShortcutHelp from './../../component/ShortcutHelp';
import {Row, RowColumn} from './../../component/Grid';

@connect(state => ({projects: state.projects.projects}))
class List extends React.Component {
  static propTypes = {
    onProjectSelected: React.PropTypes.func
  };

  state = {
    selectedProject: 0,
    selectedShortcut: 0,
    filter: '',
    filteredProjects: []
  };

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

  onKeyUp(ev) {
    if (ev.which === 13) { // Enter
      this.goToShortcutLink(this.state.selectedShortcut);
    } else if (ev.which < 37 || ev.which > 40) { // Filter
      this.filterProjects(ev.currentTarget.value);
    } else {
      this.refs.navigableList.handleNavigation(ev);
    }

    ev.stopPropagation();
  }

  filterProjects(value) {
    const filteredProjects = this.props.projects.filter(project => (
      value.length === 0 || project.node.name.indexOf(value) > -1
    ));
    this.setState({
      filteredProjects,
      selectedProject: 0
    });
  }

  changeSelectedRow(index) {
    this.setState({selectedProject: index});
  }

  changeSelectedShortcut(index) {
    this.setState({selectedShortcut: index});
  }

  goToShortcutLink(index) {
    const shortcutLinks = ['/', '/issue/new'];
    this.props.dispatch(
      routeActions.push(
        `/project/${this.state.filteredProjects[this.state.selectedProject].node.id}${shortcutLinks[index]}`
      )
    );
    this.triggerOnProjectSelected();
  }

  triggerOnProjectSelected() {
{'fraction_non_alphanumeric': 0.1617873651771957, 'fraction_numerical': 0.004842615012106538, 'mean_word_length': 3.2191272051996287, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, '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': '3508321', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1349, 'n_words': 309}