<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

const React = require('react')
const Immutable = require('immutable')
const ImmutableComponent = require('./immutableComponent')
const windowActions = require('../actions/windowActions')
const cx = require('../lib/classSet.js')
const KeyCodes = require('../constants/keyCodes')

class ContextMenuItem extends ImmutableComponent {
  componentDidMount () {
    window.addEventListener('keydown', this.onKeyDown.bind(this))
  }
  onKeyDown (e) {
    if (e.keyCode === KeyCodes.ESC || e.keyCode === KeyCodes.TAB) {
      windowActions.setContextMenuDetail()
    }
  }
  get submenu () {
    return this.props.contextMenuItem.get('submenu')
  }
  get hasSubmenu () {
    return this.submenu && this.submenu.size > 0
  }
  onClick (clickAction, shouldHide, e) {
    e.stopPropagation()
    if (clickAction) {
      if (shouldHide) {
        windowActions.setContextMenuDetail()<commit_msg>remove event listener on unmount and don't bind to avoid memory leak auditors: @bbondy<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

const React = require('react')
const Immutable = require('immutable')
const ImmutableComponent = require('./immutableComponent')
const windowActions = require('../actions/windowActions')
const cx = require('../lib/classSet.js')
const KeyCodes = require('../constants/keyCodes')

class ContextMenuItem extends ImmutableComponent {
  componentDidMount () {
    window.addEventListener('keydown', this.onKeyDown)
  }
  componentWillUnmount () {
    window.removeEventListener('keydown', this.onKeyDown)
  }
  onKeyDown (e) {
    if (e.keyCode === KeyCodes.ESC || e.keyCode === KeyCodes.TAB) {
      windowActions.setContextMenuDetail()
    }
  }
  get submenu () {
    return this.props.contextMenuItem.get('submenu')
  }
  get hasSubmenu () {
    return this.submenu && this.submenu.size > 0
  }
  onClick (clickAction, shouldHide, e) {
    e.stopPropagation()
    if (clickAction) {
      if (shouldHide) {
        windowActions.setContextMenuDetail()
{'fraction_non_alphanumeric': 0.1266949152542373, 'fraction_numerical': 0.00423728813559322, 'mean_word_length': 3.789046653144016, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4910910', 'n_tokens_mistral': 709, 'n_tokens_neox': 713, 'n_words': 191}