<commit_before>import React, {Component} from 'react'
import PropTypes from 'prop-types'
import {connect} from 'react-redux'
import {bindActionCreators} from 'redux'

import classnames from 'classnames'

import MenuTooltipButton from 'src/shared/components/MenuTooltipButton'
import CustomTimeIndicator from 'src/shared/components/CustomTimeIndicator'

import {EDITING} from 'src/shared/annotations/helpers'
import {cellSupportsAnnotations} from 'src/shared/constants/index'

import {
  addingAnnotation,
  editingAnnotation,
  dismissEditingAnnotation,
} from 'src/shared/actions/annotations'

class LayoutCellMenu extends Component {
  state = {
    subMenuIsOpen: false,
  }

  handleToggleSubMenu = () => {
    this.setState({subMenuIsOpen: !this.state.subMenuIsOpen})
  }

  render() {
    const {subMenuIsOpen} = this.state
    const {
      mode,
      cell,
      onEdit,
      onClone,
      queries,
      onDelete,
      isEditable,
      dataExists,
      onCSVDownload,
      onStartAddingAnnotation,
      onStartEditingAnnotation,
      onDismissEditingAnnotation,
    } = this.props

    const menuOptions = [
      {
        text: 'Configure',
        action: onEdit(cell),
      },
      {
        text: 'Add Annotation',
        action: onStartAddingAnnotation,
        disabled: !cellSupportsAnnotations(cell.type),
      },
      {
        text: 'Edit Annotations',
        action: onStartEditingAnnotation,
        disabled: !cellSupportsAnnotations(cell.type),
      },
    ]

    if (dataExists) {
      menuOptions.push({text: 'Download CSV', action: onCSVDownload(cell)})
    }

    return (
      <div
        className={classnames('dash-graph-context', {
          'dash-graph-context__open': subMenuIsOpen,
        })}
      >
        <div
          className={`${
            isEditable
              ? 'dash-graph--custom-indicators dash-graph--draggable'
              : 'dash-graph--custom-indicators'
          }`}
        >
          {queries && <CustomTimeIndicator queries={queries} />}
        </div>
        {isEditable &&
          mode !== EDITING && (
            <div className="dash-graph-context--buttons">
              {queries.length ? (
                <MenuTooltipButton
                  icon="pencil"
                  menuOptions={menuOptions}
                  informParent={this.handleToggleSubMenu}
                />
              ) : null}

              <MenuTooltipButton
                icon="duplicate"
                menuOptions={[{text: 'Clone Cell', action: onClone(cell)}]}
                informParent={this.handleToggleSubMenu}
              />

              <MenuTooltipButton
                icon="trash"
                theme="danger"
                menuOptions={[{text: 'Confirm', action: onDelete(cell)}]}
                informParent={this.handleToggleSubMenu}
              />
            </div>
          )}
        {mode === 'editing' &&
          cellSupportsAnnotations(cell.type) && (
            <div className="dash-graph-context--buttons">
              <div
                className="btn btn-xs btn-success"
                onClick={onDismissEditingAnnotation}
              >
                Done Editing<commit_msg>Always show download option but disable if no data<commit_after>import React, {Component} from 'react'
import PropTypes from 'prop-types'
import {connect} from 'react-redux'
import {bindActionCreators} from 'redux'

import classnames from 'classnames'

import MenuTooltipButton from 'src/shared/components/MenuTooltipButton'
import CustomTimeIndicator from 'src/shared/components/CustomTimeIndicator'

import {EDITING} from 'src/shared/annotations/helpers'
import {cellSupportsAnnotations} from 'src/shared/constants/index'

import {
  addingAnnotation,
  editingAnnotation,
  dismissEditingAnnotation,
} from 'src/shared/actions/annotations'

class LayoutCellMenu extends Component {
  state = {
    subMenuIsOpen: false,
  }

  handleToggleSubMenu = () => {
    this.setState({subMenuIsOpen: !this.state.subMenuIsOpen})
  }

  render() {
    const {subMenuIsOpen} = this.state
    const {
      mode,
      cell,
      onEdit,
      onClone,
      queries,
      onDelete,
      isEditable,
      dataExists,
      onCSVDownload,
      onStartAddingAnnotation,
      onStartEditingAnnotation,
      onDismissEditingAnnotation,
    } = this.props

    const menuOptions = [
      {
        text: 'Configure',
        action: onEdit(cell),
      },
      {
        text: 'Add Annotation',
        action: onStartAddingAnnotation,
        disabled: !cellSupportsAnnotations(cell.type),
      },
      {
        text: 'Edit Annotations',
        action: onStartEditingAnnotation,
        disabled: !cellSupportsAnnotations(cell.type),
      },
      {
        text: 'Download CSV',
        action: onCSVDownload(cell),
        disabled: !dataExists,
      },
    ]

    return (
      <div
        className={classnames('dash-graph-context', {
          'dash-graph-context__open': subMenuIsOpen,
        })}
      >
        <div
          className={`${
            isEditable
              ? 'dash-graph--custom-indicators dash-graph--draggable'
              : 'dash-graph--custom-indicators'
          }`}
        >
          {queries && <CustomTimeIndicator queries={queries} />}
        </div>
        {isEditable &&
          mode !== EDITING && (
            <div className="dash-graph-context--buttons">
              {queries.length ? (
                <MenuTooltipButton
                  icon="pencil"
                  menuOptions={menuOptions}
                  informParent={this.handleToggleSubMenu}
                />
              ) : null}
              <MenuTooltipButton
                icon="duplicate"
                menuOptions={[{text: 'Clone Cell', action: onClone(cell)}]}
                informParent={this.handleToggleSubMenu}
              />
              <MenuTooltipButton
                icon="trash"
                theme="danger"
                menuOptions={[{text: 'Confirm', action: onDelete(cell)}]}
                informParent={this.handleToggleSubMenu}
              />
            </div>
          )}
        {mode === 'editing' &&
          cellSupportsAnnotations(cell.type) && (
            <div className="dash-graph-context--buttons">
              <div
                className="btn btn-xs btn-success"
                onClick={onDismissEditingAnnotation}
              >
                Done Editing
{'fraction_non_alphanumeric': 0.10782339271882262, 'fraction_numerical': 0.0, 'mean_word_length': 1.9385525716886665, 'pattern_counts': {'":': 0, '<': 25, '<?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': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5314223', 'n_tokens_mistral': 1780, 'n_tokens_neox': 1758, 'n_words': 313}