<commit_before>import React from 'react'
// import { Link } from 'react-router-dom'
import styles from './styles.scss'
import Tools from './components/Tools'
import FavoriteTools from './components/FavoriteTools'

import {
  Sidebar,
  Segment,
  Menu,
  Icon,
  Dropdown,
  Button
} from 'semantic-ui-react'

export default class SideBarOverlay extends React.Component {
  state = {
    visible: false,
    extraStyle: null
  }
  toggleVisibility = () => this.setState({ visible: !this.state.visible })

  extendMenu = (padding) => {
    this.setState({extraStyle: {
      paddingRight: padding + 'px',
      width: '210px'
    }})
  }

  closeBoards = () => {
    this.setState({extraStyle: {
      paddingRight: '0px',
      width: '150px'
    }})
    this.props.closeContextMenu()
  }

  getAuthView () {
    const auth = this.props.auth
    const authUserIcon = auth.isAuthenticated() ? 'user outline' : 'sign in'
    const authLabel = auth.isAuthenticated() ? (auth.tryGetProfile().given_name || auth.tryGetProfile().nickname) : 'Login'
    const authOnClick = auth.isAuthenticated() ? () => this.extendMenu(220) : () => this.props.auth.login()

    const trigger = (
      <span>
        <a style={{maxWidth: '150px'}} onClick={authOnClick} className='item'>
          <Icon name={authUserIcon} />
          {authLabel}
        </a>
      </span>
    )

    const options = [
      { key: 'user', text: 'Account', icon: 'user', onClick: () => this.props.openUserAccount() },
      { key: 'settings', text: 'Settings', icon: 'settings', onClick: () => this.props.openSettings() },
      { key: 'sign-out', text: 'Sign Out', icon: 'sign out', onClick: () => auth.logout() }
    ]

    return auth.isAuthenticated()
    ? <Dropdown onClose={this.closeBoards} trigger={trigger} options={options} pointing='left' icon={null} />
    : trigger
  }

  getShareViewIfAdmin = () => {
    const auth = this.props.auth
    if ((!auth.isAuthenticated() && this.props.currentBoard.id < 0) || this.props.currentBoard.userPermission === 3) {
      return (
        <a onClick={this.props.toggleShareModal} className='item'>
          <Icon name='share' />
          Share board
        </a>
      )
    }
  }

  getUsersViewIfAdmin = () => {
    if (this.props.currentBoard.userPermission === 3) {
      return (
        <a onClick={this.props.toggleUsersManagementModal} className='item'>
          <Icon name='users' />
          Users Management
        </a>
      )
    }
  }

  changeCurrentBoard = (props) => {
    const boardId = props[0]
    this.props.changeCurrentBoard(boardId)
  }

  openContextMenu = (event, boardId) => {
    event.preventDefault()
    const contextMenu = [{
      header: {icon: 'trash', text: 'Remove Board'},
      menuItems: [{
        icon: 'trash',
        text: 'Remove',
        onClick: () => {
          this.props.removeBoard(boardId)
          this.props.closeContextMenu()
        }}]
    }]

    this.props.openContextMenu(event.clientX, event.clientY, contextMenu)
  }

  render () {
    const { visible } = this.state

    return (
      <div className={styles.divsidebar}>
        <Sidebar.Pushable as={Segment} className={styles.sidebar}>
          <Sidebar as={Menu} animation='push' direction='left' width='thin' icon='labeled' visible={visible} vertical style={this.state.extraStyle} inverted className={styles.sidebarMenu}>
            {this.getAuthView()}
            {this.getShareViewIfAdmin()}
            {this.getUsersViewIfAdmin()}
            <Dropdown onClose={this.closeBoards} onClick={() => this.extendMenu(300)} item text='My Boards'>
              <Dropdown.Menu className={styles.myBoards} >
                <Dropdown.Header>Current Board</Dropdown.Header>
                <Dropdown.Item >{this.props.currentBoard.name}</Dropdown.Item>
                <Dropdown.Divider />
                <Dropdown.Header>Your Boards</Dropdown.Header>
                {this.props.userBoards
                  .filter(board => {
                    return board.userPermission === 3
                  }).map(board => {
                    return (
                      <Dropdown.Item onContextMenu={event => this.openContextMenu(event, board.id)} onClick={this.changeCurrentBoard.bind(this, [board.id])} key={board.id}>
                        {board.name}
                      </Dropdown.Item>
                    )
                  })
                }
                <Dropdown.Divider />
                <Dropdown.Header>Shared Boards</Dropdown.Header>
                {this.props.userBoards
                  .filter(board => {
                    return board.userPermission < 3
                  }).map(board => {
                    return <Dropdown.Item onClick={this.changeCurrentBoard.bind(this, [board.id])} key={board.id}>{board.name}</Dropdown.Item>
                  })<commit_msg>Fix bug onContextMenu on shared boards<commit_after>import React from 'react'
// import { Link } from 'react-router-dom'
import styles from './styles.scss'
import Tools from './components/Tools'
import FavoriteTools from './components/FavoriteTools'

import {
  Sidebar,
  Segment,
  Menu,
  Icon,
  Dropdown,
  Button
} from 'semantic-ui-react'

export default class SideBarOverlay extends React.Component {
  state = {
    visible: false,
    extraStyle: null
  }
  toggleVisibility = () => this.setState({ visible: !this.state.visible })

  extendMenu = (padding) => {
    this.setState({extraStyle: {
      paddingRight: padding + 'px',
      width: '210px'
    }})
  }

  closeBoards = () => {
    this.setState({extraStyle: {
      paddingRight: '0px',
      width: '150px'
    }})
    this.props.closeContextMenu()
  }

  getAuthView () {
    const auth = this.props.auth
    const authUserIcon = auth.isAuthenticated() ? 'user outline' : 'sign in'
    const authLabel = auth.isAuthenticated() ? (auth.tryGetProfile().given_name || auth.tryGetProfile().nickname) : 'Login'
    const authOnClick = auth.isAuthenticated() ? () => this.extendMenu(220) : () => this.props.auth.login()

    const trigger = (
      <span>
        <a style={{maxWidth: '150px'}} onClick={authOnClick} className='item'>
          <Icon name={authUserIcon} />
          {authLabel}
        </a>
      </span>
    )

    const options = [
      { key: 'user', text: 'Account', icon: 'user', onClick: () => this.props.openUserAccount() },
      { key: 'settings', text: 'Settings', icon: 'settings', onClick: () => this.props.openSettings() },
      { key: 'sign-out', text: 'Sign Out', icon: 'sign out', onClick: () => auth.logout() }
    ]

    return auth.isAuthenticated()
    ? <Dropdown onClose={this.closeBoards} trigger={trigger} options={options} pointing='left' icon={null} />
    : trigger
  }

  getShareViewIfAdmin = () => {
    const auth = this.props.auth
    if ((!auth.isAuthenticated() && this.props.currentBoard.id < 0) || this.props.currentBoard.userPermission === 3) {
      return (
        <a onClick={this.props.toggleShareModal} className='item'>
          <Icon name='share' />
          Share board
        </a>
      )
    }
  }

  getUsersViewIfAdmin = () => {
    if (this.props.currentBoard.userPermission === 3) {
      return (
        <a onClick={this.props.toggleUsersManagementModal} className='item'>
          <Icon name='users' />
          Users Management
        </a>
      )
    }
  }

  changeCurrentBoard = (props) => {
    const boardId = props[0]
    this.props.changeCurrentBoard(boardId)
  }

  openContextMenu = (event, boardId) => {
    event.preventDefault()
    const contextMenu = [{
      header: {icon: 'trash', text: 'Remove Board'},
      menuItems: [{
        icon: 'trash',
        text: 'Remove',
        onClick: () => {
          this.props.removeBoard(boardId)
          this.props.closeContextMenu()
        }}]
    }]

    this.props.openContextMenu(event.clientX, event.clientY, contextMenu)
  }

  render () {
    const { visible } = this.state

    return (
      <div className={styles.divsidebar}>
        <Sidebar.Pushable as={Segment} className={styles.sidebar}>
          <Sidebar as={Menu} animation='push' direction='left' width='thin' icon='labeled' visible={visible} vertical style={this.state.extraStyle} inverted className={styles.sidebarMenu}>
            {this.getAuthView()}
            {this.getShareViewIfAdmin()}
            {this.getUsersViewIfAdmin()}
            <Dropdown onClose={this.closeBoards} onClick={() => this.extendMenu(300)} item text='My Boards'>
              <Dropdown.Menu className={styles.myBoards} >
                <Dropdown.Header>Current Board</Dropdown.Header>
                <Dropdown.Item >{this.props.currentBoard.name}</Dropdown.Item>
                <Dropdown.Divider />
                <Dropdown.Header>Your Boards</Dropdown.Header>
                {this.props.userBoards
                  .filter(board => {
                    return board.userPermission === 3
                  }).map(board => {
                    return (
                      <Dropdown.Item onContextMenu={event => this.openContextMenu(event, board.id)} onClick={this.changeCurrentBoard.bind(this, [board.id])} key={board.id}>
                        {board.name}
                      </Dropdown.Item>
                    )
                  })
                }
                <Dropdown.Divider />
                <Dropdown.Header>Shared Boards</Dropdown.Header>
                {this.props.userBoards
                  .filter(board => {
                    return board.userPermission < 3
                  }).map(board => {
                    return <Dropdown.Item onContextMenu={event => this.openContextMenu(event, board.id)} onClick={this.changeCurrentBoard.bind(this, [board.id])} key={board.id}>{board.name}</Dropdown.Item>
                  })
{'fraction_non_alphanumeric': 0.14636642784032752, 'fraction_numerical': 0.004503582395087001, 'mean_word_length': 2.287685060565276, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 104, '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': '6438414', 'n_tokens_mistral': 2914, 'n_tokens_neox': 2817, 'n_words': 532}