<commit_before>import React, {Component} from 'react'
import PropTypes from 'prop-types'
import Input from '../../common/forms/Input'
import DropDown from '../../common/forms/DropDown'
import './tray-settings.scss'

class TraySettings extends Component {
  constructor(props) {
    super(props)
    this.state = {newName: props.name, newUsername: props.username, newPassword: '', updatingPassword: false, credentialsChanged: false}
  }

  componentWillUnmount() {
    if (this.state.credentialsChanged) {
      this.props.refreshTray(this.props, this.props.pendingRequest)
    }
  }

  componentDidUpdate(prevProps, prevState) {
    if (!prevState.updatingPassword && this.state.updatingPassword) {
      this.passwordInput.focus()
    }
  }

  render() {
    const nameChanged = (evt) => this.setState({newName: evt.target.value})
    const setName = () => this.props.setTrayName(this.props.trayId, this.state.newName)
    const generateRandomName = () => this.setState({newName: generateRandomName()}, () => setName())
    const serverTypeChange = (evt) => this.props.setServerType(this.props.trayId, evt.target.value)
    const usernameChanged = (evt) => this.setState({newUsername: evt.target.value})
    const setUsername = () => {
      this.setState({credentialsChanged: this.props.username !== this.state.newUsername})
      this.props.setTrayUsername(this.props.trayId, this.state.newUsername)
    }
    const passwordChanged = (evt) => this.setState({newPassword: evt.target.value})
    const existingPassword = this.props.password ? '*******' : ''
    const password = this.state.updatingPassword ? this.state.newPassword : existingPassword
    const deleteTray = () => this.props.removeTray(this.props.trayId, this.props.pendingRequest)
    const cancel = () => this.setState({updatingPassword: false})
    const changePassword = () => this.setState({updatingPassword: true})
    const setPassword = () => {
      this.props.encryptPassword(this.props.trayId, this.state.newPassword, this.props.pendingRequest)
      this.setState({updatingPassword: false, newPassword: '', credentialsChanged: true})
    }

    return (
      <section className='tray-settings' data-locator='tray-settings'>
        <Input className='tray-settings-name' value={this.state.newName} onChange={nameChanged} onBlur={setName} onEnter={setName}
               placeholder='e.g. project or team name' data-locator='tray-name' autoFocus>
          <span>name</span>
        </Input>
        <button className='random' onClick={generateRandomName} data-locator='generate-random'>randomise</button>
        <DropDown className='server-type' title='server type' value={this.props.serverType} onChange={serverTypeChange}>
          <option value=''>Auto detect</option>
          <option value='circle'>CircleCI</option>
          <option value='cruise-control'>CruiseControl</option>
          <option value='cruise-control-net'>CruiseControl.net</option>
          <option value='cruise-control-rb'>CruiseControl.rb</option>
          <option value='go'>GoCD</option><commit_msg>fixes random name button<commit_after>import React, {Component} from 'react'
import PropTypes from 'prop-types'
import Input from '../../common/forms/Input'
import DropDown from '../../common/forms/DropDown'
import {generateRandomName} from '../../common/project/Name'
import './tray-settings.scss'

class TraySettings extends Component {
  constructor(props) {
    super(props)
    this.state = {newName: props.name, newUsername: props.username, newPassword: '', updatingPassword: false, credentialsChanged: false}
  }

  componentWillUnmount() {
    if (this.state.credentialsChanged) {
      this.props.refreshTray(this.props, this.props.pendingRequest)
    }
  }

  componentDidUpdate(prevProps, prevState) {
    if (!prevState.updatingPassword && this.state.updatingPassword) {
      this.passwordInput.focus()
    }
  }

  render() {
    const nameChanged = (evt) => this.setState({newName: evt.target.value})
    const setName = () => this.props.setTrayName(this.props.trayId, this.state.newName)
    const generateNewName = () => this.setState({newName: generateRandomName()}, () => setName())
    const serverTypeChange = (evt) => this.props.setServerType(this.props.trayId, evt.target.value)
    const usernameChanged = (evt) => this.setState({newUsername: evt.target.value})
    const setUsername = () => {
      this.setState({credentialsChanged: this.props.username !== this.state.newUsername})
      this.props.setTrayUsername(this.props.trayId, this.state.newUsername)
    }
    const passwordChanged = (evt) => this.setState({newPassword: evt.target.value})
    const existingPassword = this.props.password ? '*******' : ''
    const password = this.state.updatingPassword ? <PASSWORD> : existingPassword
    const deleteTray = () => this.props.removeTray(this.props.trayId, this.props.pendingRequest)
    const cancel = () => this.setState({updatingPassword: false})
    const changePassword = () => this.setState({updatingPassword: true})
    const setPassword = () => {
      this.props.encryptPassword(this.props.trayId, this.state.newPassword, this.props.pendingRequest)
      this.setState({updatingPassword: false, newPassword: '', credentialsChanged: true})
    }

    return (
      <section className='tray-settings' data-locator='tray-settings'>
        <Input className='tray-settings-name' value={this.state.newName} onChange={nameChanged} onBlur={setName} onEnter={setName}
               placeholder='e.g. project or team name' data-locator='tray-name' autoFocus>
          <span>name</span>
        </Input>
        <button className='random' onClick={generateNewName} data-locator='generate-random'>randomise</button>
        <DropDown className='server-type' title='server type' value={this.props.serverType} onChange={serverTypeChange}>
          <option value=''>Auto detect</option>
          <option value='circle'>CircleCI</option>
          <option value='cruise-control'>CruiseControl</option>
          <option value='cruise-control-net'>CruiseControl.net</option>
          <option value='cruise-control-rb'>CruiseControl.rb</option>
          <option value='go'>GoCD</option>
{'fraction_non_alphanumeric': 0.1461836998706339, 'fraction_numerical': 0.0, 'mean_word_length': 4.053104575163399, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 68, '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': '3510971', 'n_tokens_mistral': 1793, 'n_tokens_neox': 1821, 'n_words': 316}