<commit_before>import '../styles/ContextMenuContainer.css';
import React from 'react';
import ReactDOM from 'react-dom';

export class ContextMenuItem extends React.Component {
    constructor(props) {
        super(props);
    }

    render() {
        return (
                <div
                    className={"context-menu-item"}
                    onMouseEnter={(e) => this.props.onMouseEnter ? this.props.onMouseEnter(e) : null }
                    onMouseLeave={(e) => this.props.onMouseLeave ? this.props.onMouseLeave(e) : null }
                    onClick={e => this.props.onClick(e)}
                >
                    <span className='context-menu-span'
                        style={{ whiteSpace: 'nowrap' }}
                    >
                        {this.props.children}
                    </span>
                </div>
               );
    }
}

export class ContextMenuContainer extends React.Component {
    constructor(props) {
        /**
         * A window that is opened when a user clicks on the track configuration icon.
         */
        super(props);

        this.adjusted = false;

        this.state = {
            orientation: this.props.orientation ? this.props.orientation : 'right',
            left: this.props.position.left,
            top: this.props.position.top,
            submenuShown: null
        }
    }

    componentWillReceiveProps(newProps) {
        this.adjusted = false;

        this.setState({
            left: newProps.position.left,
            top: newProps.position.top
        });
    }

    updateOrientation() {
        if (this.adjusted)
            return;

        this.adjusted = true;
        this.divDom = ReactDOM.findDOMNode(this.div);
        let bbox = this.divDom.getBoundingClientRect();

        let parentBbox = this.props.parentBbox ?  this.props.parentBbox :
            {'top': this.props.position.top,
             'left': this.props.position.left,
             'width': 0, 'height': 0};

        let orientation = this.state.orientation;

        if (this.state.orientation == 'left') {
            let leftPosition = parentBbox.left - bbox.width;
            if (leftPosition < 0)  {
                if (parentBbox.left + parentBbox.width + bbox.width > window.innerWidth) {
                    leftPosition = 0;  // goes off the side either way
                } else {
                    // switch to the right
                    leftPosition = parentBbox.left + parentBbox.width;
                    orientation = 'right';
                }
            }

            // we're fine keeping it left oriented

            this.setState({
                left: leftPosition,
                top: this.props.position.top,
                orientation: orientation
            });
        }  else {
            let leftPosition = parentBbox.left + parentBbox.width;

            if ((parentBbox.left + parentBbox.width + bbox.width) > window.innerWidth) {
                if (parentBbox.left - bbox.width < 0) {
                    // goes off both sides
                    leftPosition = 0;
                    orientation = 'right';
                } else {
                    leftPosition = parentBbox.left - bbox.width;
                    orientation = 'left';

                }
                /*
                leftPosition = leftPosition < 0 ? 0 : leftPosition;

                */
            }
            this.setState({
                left: leftPosition,
                top: this.props.position.top,
                orientation: orientation
            });
        }
    }

    componentDidUpdate() {
        this.updateOrientation();
    }

    componentDidMount() {
        this.updateOrientation();
    }

    handleItemMouseEnter(evt, series) {
        let domNode = evt.currentTarget;
        let boundingRect = domNode.getBoundingClientRect();
        //console.log('seriesMouseEnter:', domNode);
        //console.log('boundingRect:', boundingRect);

        this.setState({
            submenuShown: series,
            submenuSourceBbox: boundingRect
        });
    }

    handleMouseLeave(evt) {
        return;
    }

    handleOtherMouseEnter(evt) {
        this.setState({
            submenuShown: null
        });
    }

    /*
    handleSeriesMouseEnter(evt, uid) {
        let domNode = evt.currentTarget;

        this.setState({
            submenuShown: uid,
            submenuSourceBbox: domNode.getBoundingClientRect()
        });
    }

    handleMouseLeave(evt) {
        return;
    }

    handleOtherMouseEnter(evt) {
        this.setState({
            submenuShown: null
        });
    }
    */

    render() {
        let stylePosition = {'left': this.state.left}

        if (!this.state.left)
            stylePosition = {'right': this.state.right}

        let otherStyle = { position: 'fixed',
            top: this.state.top
        };

        let wholeStyle = Object.assign(stylePosition, otherStyle);

        return(
            <div className={'context-menu'}
                    ref={c => this.div = c}
                    style={ wholeStyle }
                >
                {this.props.children}
            </div>
        )
    }
}<commit_msg>Set indentation to 2px<commit_after>import '../styles/ContextMenuContainer.css';
import React from 'react';
import ReactDOM from 'react-dom';

export class ContextMenuItem extends React.Component {
  constructor(props) {
    super(props);
  }

  render() {
    return (
        <div
          className={"context-menu-item"}
          onMouseEnter={(e) => this.props.onMouseEnter ? this.props.onMouseEnter(e) : null }
          onMouseLeave={(e) => this.props.onMouseLeave ? this.props.onMouseLeave(e) : null }
          onClick={e => this.props.onClick(e)}
        >
          <span className='context-menu-span'
            style={{ whiteSpace: 'nowrap' }}
          >
            {this.props.children}
          </span>
        </div>
         );
  }
}

export class ContextMenuContainer extends React.Component {
  constructor(props) {
    /**
     * A window that is opened when a user clicks on the track configuration icon.
     */
    super(props);

    this.adjusted = false;

    this.state = {
      orientation: this.props.orientation ? this.props.orientation : 'right',
      left: this.props.position.left,
      top: this.props.position.top,
      submenuShown: null
    }
  }

  componentWillReceiveProps(newProps) {
    this.adjusted = false;

    this.setState({
      left: newProps.position.left,
      top: newProps.position.top
    });
  }

  updateOrientation() {
    if (this.adjusted)
      return;

    this.adjusted = true;
    this.divDom = ReactDOM.findDOMNode(this.div);
    let bbox = this.divDom.getBoundingClientRect();

    let parentBbox = this.props.parentBbox ?  this.props.parentBbox :
      {'top': this.props.position.top,
       'left': this.props.position.left,
       'width': 0, 'height': 0};

    let orientation = this.state.orientation;

    if (this.state.orientation == 'left') {
      let leftPosition = parentBbox.left - bbox.width;
      if (leftPosition < 0)  {
        if (parentBbox.left + parentBbox.width + bbox.width > window.innerWidth) {
          leftPosition = 0;  // goes off the side either way
        } else {
          // switch to the right
          leftPosition = parentBbox.left + parentBbox.width;
          orientation = 'right';
        }
      }

      // we're fine keeping it left oriented

      this.setState({
        left: leftPosition,
        top: this.props.position.top,
        orientation: orientation
      });
    }  else {
      let leftPosition = parentBbox.left + parentBbox.width;

      if ((parentBbox.left + parentBbox.width + bbox.width) > window.innerWidth) {
        if (parentBbox.left - bbox.width < 0) {
          // goes off both sides
          leftPosition = 0;
          orientation = 'right';
        } else {
          leftPosition = parentBbox.left - bbox.width;
          orientation = 'left';

        }
        /*
        leftPosition = leftPosition < 0 ? 0 : leftPosition;

        */
      }
      this.setState({
        left: leftPosition,
        top: this.props.position.top,
        orientation: orientation
      });
    }
  }

  componentDidUpdate() {
    this.updateOrientation();
  }

  componentDidMount() {
    this.updateOrientation();
  }

  handleItemMouseEnter(evt, series) {
    let domNode = evt.currentTarget;
    let boundingRect = domNode.getBoundingClientRect();
    //console.log('seriesMouseEnter:', domNode);
    //console.log('boundingRect:', boundingRect);

    this.setState({
      submenuShown: series,
      submenuSourceBbox: boundingRect
    });
  }

  handleMouseLeave(evt) {
    return;
  }

  handleOtherMouseEnter(evt) {
    this.setState({
      submenuShown: null
    });
  }

  /*
  handleSeriesMouseEnter(evt, uid) {
    let domNode = evt.currentTarget;

    this.setState({
      submenuShown: uid,
      submenuSourceBbox: domNode.getBoundingClientRect()
    });
  }

  handleMouseLeave(evt) {
    return;
  }

  handleOtherMouseEnter(evt) {
    this.setState({
      submenuShown: null
    });
  }
  */

  render() {
    let stylePosition = {'left': this.state.left}

    if (!this.state.left)
      stylePosition = {'right': this.state.right}

    let otherStyle = { position: 'fixed',
      top: this.state.top
    };

    let wholeStyle = Object.assign(stylePosition, otherStyle);

    return(
      <div className={'context-menu'}
          ref={c => this.div = c}
          style={ wholeStyle }
        >
        {this.props.children}
      </div>
    )
  }
}
{'fraction_non_alphanumeric': 0.11423823865406585, 'fraction_numerical': 0.0017655000519264722, 'mean_word_length': 1.7080989876265467, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 27, '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': '5611613', 'n_tokens_mistral': 2789, 'n_tokens_neox': 2670, 'n_words': 535}