<commit_before>import React from 'react';
import { createContainer } from 'meteor/react-meteor-data';
import { Button } from 'react-bootstrap';
import Elements from '../../api/elements.js';
import AddElementButton from './add-element-button.jsx';
import ElementName from './element-name.jsx';

class Element extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      childrenVisible: true,
      buttonsVisible: false,
    };
    this.removeElement = this.removeElement.bind(this);
  }

  removeElement() {
    Elements.remove(this.props.data._id, this.props.data.parentId);
  }

  render() {
    const toggleButton = () => {
      const togglerClasses = () => {
        if (this.props.data.childIds && this.props.data.childIds.length === 0) {
          return '';
        } else {
          if (this.state.childrenVisible) {
            return 'glyphicon glyphicon-chevron-down';
          } else {
            return 'glyphicon glyphicon-chevron-right';
          }
        }
      };
      const toggleChildrenVisible = () => {
        this.setState({ childrenVisible: !this.state.childrenVisible });
      };
      return (
        <span
          className={togglerClasses()}
          onClick={toggleChildrenVisible}
          style={{ paddingRight: '10px' }}
        ></span>
      );
    };

    const children = () => {
      const subElementsListStyle = {
        marginBottom: '0px',
        paddingLeft: '20px',
      };

      const getChildren = (childIds) => {
        return Elements.collection.find({ _id: { $in: childIds } }).fetch();
      };

      if (this.state.childrenVisible === true) {
        return (
          <div className="list-group sub-elements-list" style={subElementsListStyle}>
            {getChildren(this.props.data.childIds).map(function (element) {
              return <Element key={element._id} data={element} />;
            })}
          </div >
        );
      }
    };

    const buttons = () => {
      const buttonsStyle = {
        display: 'inline',
        float: 'right',
      };

      const removeButtonStyle = {
        border: 'none',
        padding: '0px',
        paddingTop: '1px',
        paddingLeft: '2px',
      };

      const possibleChildTypes = () => {
        const currentType = Elements.types.find((element) => element.name === this.props.data.typeName);
        return Elements.types.filter((type) => {
          if (currentType.possibleChildren.indexOf(type.name) === -1) {
            return false;
          }
          return true;
        });
      };

      if (this.state.buttonsVisible) {
        return (
          <div className="buttons" style={buttonsStyle}>
            <AddElementButton
              elementId={this.props.data._id}
              possibleTypes={possibleChildTypes()}
            />
            <Button
              className="glyphicon glyphicon-remove remove-element-button"
              onClick={this.removeElement}
              style={removeButtonStyle}
            />
          </div>
        );
      }<commit_msg>Enfore coding style<commit_after>import React from 'react';
import { createContainer } from 'meteor/react-meteor-data';
import { Button } from 'react-bootstrap';
import Elements from '../../api/elements.js';
import AddElementButton from './add-element-button.jsx';
import ElementName from './element-name.jsx';

class Element extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      childrenVisible: true,
      buttonsVisible: false,
    };
    this.removeElement = this.removeElement.bind(this);
  }

  removeElement() {
    Elements.remove(this.props.data._id, this.props.data.parentId);
  }

  render() {
    const toggleButton = () => {
      const togglerClasses = () => {
        if (this.props.data.childIds && this.props.data.childIds.length === 0) {
          return '';
        }
        if (this.state.childrenVisible) {
          return 'glyphicon glyphicon-chevron-down';
        }
        return 'glyphicon glyphicon-chevron-right';
      };
      const toggleChildrenVisible = () => {
        this.setState({ childrenVisible: !this.state.childrenVisible });
      };
      return (
        <span
          className={togglerClasses()}
          onClick={toggleChildrenVisible}
          style={{ paddingRight: '10px' }}
        ></span>
      );
    };

    const children = () => {
      const subElementsListStyle = {
        marginBottom: '0px',
        paddingLeft: '20px',
      };

      const getChildren = (childIds) => {
        return Elements.collection.find({ _id: { $in: childIds } }).fetch();
      };

      if (this.state.childrenVisible === true) {
        return (
          <div className="list-group sub-elements-list" style={subElementsListStyle}>
            {getChildren(this.props.data.childIds).map((element) => {
              return <Element key={element._id} data={element} />;
            })}
          </div >
        );
      }
    };

    const buttons = () => {
      const buttonsStyle = {
        display: 'inline',
        float: 'right',
      };

      const removeButtonStyle = {
        border: 'none',
        padding: '0px',
        paddingTop: '1px',
        paddingLeft: '2px',
      };

      const possibleChildTypes = () => {
        const currentType =
          Elements.types.find((element) => element.name === this.props.data.typeName);
        return Elements.types.filter((type) => {
          if (currentType.possibleChildren.indexOf(type.name) === -1) {
            return false;
          }
          return true;
        });
      };

      if (this.state.buttonsVisible) {
        return (
          <div className="buttons" style={buttonsStyle}>
            <AddElementButton
              elementId={this.props.data._id}
              possibleTypes={possibleChildTypes()}
            />
            <Button
              className="glyphicon glyphicon-remove remove-element-button"
              onClick={this.removeElement}
              style={removeButtonStyle}
            />
          </div>
        );
      }
{'fraction_non_alphanumeric': 0.13731931668856767, 'fraction_numerical': 0.0032851511169513796, 'mean_word_length': 1.95726080621661, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 40, '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': '6514980', 'n_tokens_mistral': 1695, 'n_tokens_neox': 1651, 'n_words': 309}