<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')

// Components
const ImmutableComponent = require('../immutableComponent')
const Dialog = require('../common/dialog')
const BrowserButton = require('../common/browserButton')

// Actions
const appActions = require('../../../../js/actions/appActions')
const windowActions = require('../../../../js/actions/windowActions')

// Constants
const KeyCodes = require('../../../common/constants/keyCodes')
const siteTags = require('../../../../js/constants/siteTags')
const settings = require('../../../../js/constants/settings')

// Utils
const cx = require('../../../../js/lib/classSet')
const siteUtil = require('../../../../js/state/siteUtil')
const UrlUtil = require('../../../../js/lib/urlutil')
const getSetting = require('../../../../js/settings').getSetting

const {StyleSheet, css} = require('aphrodite/no-important')
const globalStyles = require('../styles/global')
const commonStyles = require('../styles/commonStyles')

const {
  CommonFormBookmarkHanger,
  CommonFormSection,
  CommonFormDropdown,
  CommonFormTextbox,
  CommonFormButtonWrapper,
  CommonFormBottomWrapper,
  commonFormStyles
} = require('../common/commonForm')

class AddEditBookmarkHanger extends ImmutableComponent {
  constructor () {
    super()
    this.onNameChange = this.onNameChange.bind(this)
    this.onLocationChange = this.onLocationChange.bind(this)
    this.onParentFolderChange = this.onParentFolderChange.bind(this)
    this.onKeyDown = this.onKeyDown.bind(this)
    this.onClose = this.onClose.bind(this)
    this.onClick = this.onClick.bind(this)
    this.onSave = this.onSave.bind(this)
    this.onViewBookmarks = this.onViewBookmarks.bind(this)
    this.onRemoveBookmark = this.onRemoveBookmark.bind(this)
  }
  get bookmarkNameValid () {
    const title = this.props.currentDetail.get('title') || this.props.currentDetail.get('customTitle')
    const location = this.props.currentDetail.get('location')
    return this.isFolder
      ? (typeof title === 'string' && title.trim().length > 0)
      : (typeof location === 'string' && location.trim().length > 0)
  }
  get displayBookmarkName () {
    const customTitle = this.props.currentDetail.get('customTitle')
    if (customTitle !== undefined && customTitle !== '') {
      return customTitle || ''
    }
    return this.props.currentDetail.get('title') || ''
  }
  get heading () {
    if (this.isFolder) {
      return this.props.shouldShowLocation
        ? 'bookmarkFolderEditing'
        : 'bookmarkFolderAdding'
    }
    return this.props.shouldShowLocation
      ? (!this.props.originalDetail || !this.props.originalDetail.has('location'))
        ? 'bookmarkCreateNew'
        : 'bookmarkEdit'
      : 'bookmarkAdded'
  }
  get isFolder () {
    // Fake a folderId property so that the bookmark is considered a bookmark folder.
    // This is ImmutableJS so it doesn't actually set a value, it just returns a new one.
    return siteUtil.isFolder(this.props.currentDetail.set('folderId', 0))
  }
  setDefaultFocus () {
    this.bookmarkName.select()
    this.bookmarkName.focus()
  }
  updateFolders (props) {
    this.folders = siteUtil.getFolders(this.props.sites, props.currentDetail.get('folderId'))
  }
  componentWillMount () {
    this.updateFolders(this.props)
  }
  componentWillUpdate (nextProps) {
    if (this.props.sites !== nextProps.sites) {
      this.updateFolders(nextProps)
    }
  }
  componentDidUpdate () {
  }
  componentDidMount () {
    // Automatically save if this is triggered by the url star
    if (!this.props.isModal && !this.props.shouldShowLocation) {
      this.onSave(false)
    }
    this.setDefaultFocus()
    this.bookmarkName.value = this.displayBookmarkName
  }
  onKeyDown (e) {
    switch (e.keyCode) {
      case KeyCodes.ENTER:
        this.onSave()
        break
      case KeyCodes.ESC:
        this.onClose()
        break
    }
  }
  onClose () {
    windowActions.setBookmarkDetail()
  }
  onClick (e) {
    e.stopPropagation()
  }
  onNameChange (e) {
    let currentDetail = this.props.currentDetail
    let name = e.target.value
    if (typeof name === 'string' && UrlUtil.isURL(name)) {
      const punycodeUrl = UrlUtil.getPunycodeUrl(name)<commit_msg>Remove debug info for https://github.com/brave/browser-laptop/pull/9031#discussion_r118426769<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')

// Components
const ImmutableComponent = require('../immutableComponent')
const Dialog = require('../common/dialog')
const BrowserButton = require('../common/browserButton')

// Actions
const appActions = require('../../../../js/actions/appActions')
const windowActions = require('../../../../js/actions/windowActions')

// Constants
const KeyCodes = require('../../../common/constants/keyCodes')
const siteTags = require('../../../../js/constants/siteTags')
const settings = require('../../../../js/constants/settings')

// Utils
const cx = require('../../../../js/lib/classSet')
const siteUtil = require('../../../../js/state/siteUtil')
const UrlUtil = require('../../../../js/lib/urlutil')
const getSetting = require('../../../../js/settings').getSetting

const {StyleSheet, css} = require('aphrodite/no-important')
const globalStyles = require('../styles/global')
const commonStyles = require('../styles/commonStyles')

const {
  CommonFormBookmarkHanger,
  CommonFormSection,
  CommonFormDropdown,
  CommonFormTextbox,
  CommonFormButtonWrapper,
  CommonFormBottomWrapper,
  commonFormStyles
} = require('../common/commonForm')

class AddEditBookmarkHanger extends ImmutableComponent {
  constructor () {
    super()
    this.onNameChange = this.onNameChange.bind(this)
    this.onLocationChange = this.onLocationChange.bind(this)
    this.onParentFolderChange = this.onParentFolderChange.bind(this)
    this.onKeyDown = this.onKeyDown.bind(this)
    this.onClose = this.onClose.bind(this)
    this.onClick = this.onClick.bind(this)
    this.onSave = this.onSave.bind(this)
    this.onViewBookmarks = this.onViewBookmarks.bind(this)
    this.onRemoveBookmark = this.onRemoveBookmark.bind(this)
  }
  get bookmarkNameValid () {
    const title = this.props.currentDetail.get('title') || this.props.currentDetail.get('customTitle')
    const location = this.props.currentDetail.get('location')
    return this.isFolder
      ? (typeof title === 'string' && title.trim().length > 0)
      : (typeof location === 'string' && location.trim().length > 0)
  }
  get displayBookmarkName () {
    const customTitle = this.props.currentDetail.get('customTitle')
    if (customTitle !== undefined && customTitle !== '') {
      return customTitle || ''
    }
    return this.props.currentDetail.get('title') || ''
  }
  get heading () {
    if (this.isFolder) {
      return this.props.shouldShowLocation
        ? 'bookmarkFolderEditing'
        : 'bookmarkFolderAdding'
    }
    return this.props.shouldShowLocation
      ? (!this.props.originalDetail || !this.props.originalDetail.has('location'))
        ? 'bookmarkCreateNew'
        : 'bookmarkEdit'
      : 'bookmarkAdded'
  }
  get isFolder () {
    // Fake a folderId property so that the bookmark is considered a bookmark folder.
    // This is ImmutableJS so it doesn't actually set a value, it just returns a new one.
    return siteUtil.isFolder(this.props.currentDetail.set('folderId', 0))
  }
  setDefaultFocus () {
    this.bookmarkName.select()
    this.bookmarkName.focus()
  }
  updateFolders (props) {
    this.folders = siteUtil.getFolders(this.props.sites, props.currentDetail.get('folderId'))
  }
  componentWillMount () {
    this.updateFolders(this.props)
  }
  componentWillUpdate (nextProps) {
    if (this.props.sites !== nextProps.sites) {
      this.updateFolders(nextProps)
    }
  }
  componentDidMount () {
    // Automatically save if this is triggered by the url star
    if (!this.props.isModal && !this.props.shouldShowLocation) {
      this.onSave(false)
    }
    this.setDefaultFocus()
    this.bookmarkName.value = this.displayBookmarkName
  }
  onKeyDown (e) {
    switch (e.keyCode) {
      case KeyCodes.ENTER:
        this.onSave()
        break
      case KeyCodes.ESC:
        this.onClose()
        break
    }
  }
  onClose () {
    windowActions.setBookmarkDetail()
  }
  onClick (e) {
    e.stopPropagation()
  }
  onNameChange (e) {
    let currentDetail = this.props.currentDetail
    let name = e.target.value
    if (typeof name === 'string' && UrlUtil.isURL(name)) {
      const punycodeUrl = UrlUtil.getPunycodeUrl(name)
{'fraction_non_alphanumeric': 0.1470058532192706, 'fraction_numerical': 0.003039171544349392, 'mean_word_length': 3.2289386006663494, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 1, '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': '1789088', 'n_tokens_mistral': 2719, 'n_tokens_neox': 2708, 'n_words': 546}