<commit_before>import React from 'react';
import Menu, {Item as MenuItem} from 'rc-menu';
import WorkingstepList from './workingstepslist';
import WorkplanList from './workplanlist';
import ToolList from './toollist';
import ToleranceList from './tolerancelist';
import PropertiesPane from './propertiespane';
import ReactTooltip from 'react-tooltip';
import cadManager from '../../models/cad_manager';

export default class SidebarView extends React.Component {
    constructor(props) {
        super(props);
      
        this.state = {scrolled: false};

        let disabledView = (name) => {
          return (() => {
            this.props.cbMode("disabled");
            this.props.cbAltMenu(name);
          }).bind(this);
        };

        let self = this;
        let updateWorkingstep = (state) => {
            self.props.cbWS(state);
            return;
        };

        this.selectMenuItem = this.selectMenuItem.bind(this);

        this.props.actionManager.on('change-workingstep', updateWorkingstep);
    }

    componentDidUpdate() {
      if((!this.state.scrolled) && (this.props.ws > -1))
      {
        let currElem=$('.running-node');
        if((currElem !== null) && (typeof currElem !== 'undefined') && (this.props.mode !== 'tolerance'))
        {
          console.log(currElem);
          let tree = $('.m-tree,.sidebar ul.sidebar-menu-tabs + ul');
          tree.animate({
            scrollTop: currElem.offset().top-tree.offset().top
            }, 1000);
          this.setState({'scrolled': true});//dont want to scroll for the first working step but keep it here so we dont scroll on a rerender
        }
      }
    }

    selectMenuItem (info) {
      this.props.cbMode(info.key);
      this.setState({'scrolled': false});
    }
    
    
    render() {
      // TODO currently mode menu can only have two layers
      let nested = this.props.mode != "tree";
        
      let properties = <PropertiesPane 
              entity={this.props.selectedEntity}
              pid={this.props.pid}
              ws={this.props.ws}
              propertiesCb = {this.props.openProperties}
              tools = {this.props.toolCache}
          />;
        
      const modeMenu = (
          <Menu onSelect={this.selectMenuItem}<commit_msg>Change scrolling code to only scroll as far as needed when needed<commit_after>import React from 'react';
import Menu, {Item as MenuItem} from 'rc-menu';
import WorkingstepList from './workingstepslist';
import WorkplanList from './workplanlist';
import ToolList from './toollist';
import ToleranceList from './tolerancelist';
import PropertiesPane from './propertiespane';
import ReactTooltip from 'react-tooltip';
import cadManager from '../../models/cad_manager';

export default class SidebarView extends React.Component {
    constructor(props) {
        super(props);
      
        this.state = {scrolled: false};

        let disabledView = (name) => {
          return (() => {
            this.props.cbMode("disabled");
            this.props.cbAltMenu(name);
          }).bind(this);
        };

        let self = this;
        let updateWorkingstep = (state) => {
            self.props.cbWS(state);
            return;
        };

        this.selectMenuItem = this.selectMenuItem.bind(this);

        this.props.actionManager.on('change-workingstep', updateWorkingstep);
    }

    componentDidUpdate() {
      if((!this.state.scrolled) && (this.props.ws > -1))
      {
        let currElem=$('.running-node');
        if((currElem !== null) && (typeof currElem !== 'undefined') && (this.props.mode !== 'tolerance'))
        {
          let tree = $('.m-tree,.sidebar ul.sidebar-menu-tabs + ul');

          if (tree.offset().top + tree.innerHeight() < currElem.offset().top + currElem.outerHeight()) {
            tree.animate({
              scrollTop: (currElem.offset().top + currElem.outerHeight())
                  - (tree.offset().top + tree.innerHeight())
            }, 1000);
          }
          //dont want to scroll for the first working step but keep it here so we dont scroll on a rerender
          this.setState({'scrolled': true});
        }
      }
    }

    selectMenuItem (info) {
      this.props.cbMode(info.key);
      this.setState({'scrolled': false});
    }
    
    
    render() {
      // TODO currently mode menu can only have two layers
      let nested = this.props.mode != "tree";
        
      let properties = <PropertiesPane 
              entity={this.props.selectedEntity}
              pid={this.props.pid}
              ws={this.props.ws}
              propertiesCb = {this.props.openProperties}
              tools = {this.props.toolCache}
          />;
        
      const modeMenu = (
          <Menu onSelect={this.selectMenuItem}
{'fraction_non_alphanumeric': 0.13485738255033558, 'fraction_numerical': 0.0020973154362416107, 'mean_word_length': 2.1375, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 13, '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': '7640431', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1299, 'n_words': 310}