<commit_before>// @flow
import React from 'react';
import { IProject } from '../../types';

type Props = {
  projects: IProject[],
  parentID: string,
  disableItself?: boolean,
  itselfID?: string,
  disableDefault: boolean,
  changeSelect: (e: SyntheticEvent<HTMLSelectElement>) => void,
  myClass: string,
  defaultOption?: string
};

class ProjectsSelect extends React.Component<Props> {
  static defaultProps = {
    parentID: '',
    disableDefault: false,
    myClass: 'project-select'
  };

  getListOfProjects = (parentID: string = '', level: number = 1) => {
    const children = this.getAllChildren(this.props.itselfID);
    this.props.projects.forEach(project => {
      let disabled = false;
      const isChild = children.indexOf(project._id) !== -1;
      const disableItself =
        this.props.disableItself && this.props.itselfID === project._id;
      if (isChild || disableItself) {
        disabled = true;
      }
      if (parentID === project.parent_id) {
        this.projects.push(
          <option
            key={`select_project-${project._id}`}
            value={project._id}
            disabled={disabled}
            dangerouslySetInnerHTML={{
              __html: '&nbsp'.repeat(level) + project.name
            }}
          />
        );
        this.getListOfProjects(project._id, level + 3);
      }
    });
    return this.projects;
  };

  getAllChildren = (myID?: string): string[] => {
    if (myID === undefined) {
      return [];
    }
    const children = [];
    const recursive = (id: string) => {
      this.props.projects.forEach(project => {
        if (id === project.parent_id) {
          children.push(project._id);
          recursive(project._id);
        }
      });
    };
    recursive(myID);
    return children;
  };

  projects = [];

  render() {
    this.projects = [];
    const disabled = this.props.disableDefault;
    const listItems = this.getListOfProjects();
    return (
      <select
        name="parent_id"
        onChange={this.props.changeSelect}
        value={this.props.parentID}
        className={this.props.myClass}
      >
        <option disabled={disabled} value={''}>
          {this.props.defaultOption || 'None'}
        </option>
        {listItems}
      </select>
    );
  }
}

export default ProjectsSelect;
<commit_msg>dont show done projects<commit_after>// @flow
import React from 'react';
import { IProject } from '../../types';

type Props = {
  projects: IProject[],
  parentID: string,
  disableItself?: boolean,
  itselfID?: string,
  disableDefault: boolean,
  changeSelect: (e: SyntheticEvent<HTMLSelectElement>) => void,
  myClass: string,
  defaultOption?: string
};

class ProjectsSelect extends React.Component<Props> {
  static defaultProps = {
    parentID: '',
    disableDefault: false,
    myClass: 'project-select'
  };

  getListOfProjects = (parentID: string = '', level: number = 1) => {
    const children = this.getAllChildren(this.props.itselfID);
    this.props.projects.forEach(project => {
      let disabled = false;
      const isChild = children.indexOf(project._id) !== -1;
      const disableItself =
        (this.props.disableItself && this.props.itselfID === project._id);
      if (isChild || disableItself) {
        disabled = true;
      }
      if (parentID === project.parent_id && !project.done) {
        this.projects.push(
          <option
            key={`select_project-${project._id}`}
            value={project._id}
            disabled={disabled}
            dangerouslySetInnerHTML={{
              __html: '&nbsp'.repeat(level) + project.name
            }}
          />
        );
        this.getListOfProjects(project._id, level + 3);
      }
    });
    return this.projects;
  };

  getAllChildren = (myID?: string): string[] => {
    if (myID === undefined) {
      return [];
    }
    const children = [];
    const recursive = (id: string) => {
      this.props.projects.forEach(project => {
        if (id === project.parent_id) {
          children.push(project._id);
          recursive(project._id);
        }
      });
    };
    recursive(myID);
    return children;
  };

  projects = [];

  render() {
    this.projects = [];
    const disabled = this.props.disableDefault;
    const listItems = this.getListOfProjects();
    return (
      <select
        name="parent_id"
        onChange={this.props.changeSelect}
        value={this.props.parentID}
        className={this.props.myClass}
      >
        <option disabled={disabled} value={''}>
          {this.props.defaultOption || 'None'}
        </option>
        {listItems}
      </select>
    );
  }
}

export default ProjectsSelect;

{'fraction_non_alphanumeric': 0.14227555174630382, 'fraction_numerical': 0.0012856224555388902, 'mean_word_length': 2.341445955619184, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 29, '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': '2055', 'n_tokens_mistral': 1385, 'n_tokens_neox': 1376, 'n_words': 272}