<commit_before>import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { addLogin, deleteLogin, updateLogin } from '../actions.js';

import Dialog from 'material-ui/lib/dialog';
import FlatButton from 'material-ui/lib/flat-button';

import FormsyText from 'formsy-material-ui/lib/FormsyText.js';

import { Form } from 'formsy-react';

class AccountEditDialog extends React.Component {
  static propTypes = {
    login: PropTypes.object.isRequired,
    addLogin: PropTypes.func.isRequired,
    updateLogin: PropTypes.func.isRequired,
    deleteLogin: PropTypes.func.isRequired,
    onDone: PropTypes.func
  };

  state = { canSubmit: false };

  enableButton = () => { this.setState({ canSubmit: true }); }
  disableButton = () => { this.setState({ canSubmit: false }); }

  submitForm = (model) => {
    if (this.props.login.guid) {
      this.props.updateLogin(this.props.login.guid, {
        username: model.username,
        accesskey: model.accesskey,
        server: model.server
      });
    } else {
      this.props.addLogin(model.username, model.accesskey, model.server);
    }
    this.refs.form.reset();
    if (this.props.onDone) { this.props.onDone(); }
  }

  onClickSubmit = () => { this.refs.form.submit(); }
  onClickDelete = () => {
    this.props.deleteLogin(this.props.login.guid);
    if (this.props.onDone) { this.props.onDone(); }
  }

  render () {
    const actions = [
      <FlatButton
        type='submit'
        primary
        disabled={!this.state.canSubmit}
        onClick={this.onClickSubmit}
        label='Save'
      />,
      <FlatButton
        secondary
        disabled={!this.props.login.guid}
        onClick={this.onClickDelete}
        label='Delete'
      />
    ];

    return (
      <Dialog
        title={this.props.login.guid ? 'Edit' : 'Add'}
        onRequestClose={this.props.onDone}
        actions={actions}
        autoScrollBodyContent
        open
      >
        <Form ref='form'
          onValid={this.enableButton}
          onInvalid={this.disableButton}
          onValidSubmit={this.submitForm}
          >
          <FormsyText
            name='username'
            required
            value={this.props.login.username}
            hintText='Sauce Labs Username'
            validations='isAlphanumeric,minLength:1,maxLength:1000'
          />
          <br />
          <FormsyText
            name='accesskey'
            type='password'
            value={this.props.login.accesskey}
            required
            hintText='Sauce Labs Access Key'
            validations='minLength:1,maxLength:1000'
          />
          <br/>
          <FormsyText
            name='server'<commit_msg>remove isalphanumeric requirement as it can also have dashes and other characters in username<commit_after>import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { addLogin, deleteLogin, updateLogin } from '../actions.js';

import Dialog from 'material-ui/lib/dialog';
import FlatButton from 'material-ui/lib/flat-button';

import FormsyText from 'formsy-material-ui/lib/FormsyText.js';

import { Form } from 'formsy-react';

class AccountEditDialog extends React.Component {
  static propTypes = {
    login: PropTypes.object.isRequired,
    addLogin: PropTypes.func.isRequired,
    updateLogin: PropTypes.func.isRequired,
    deleteLogin: PropTypes.func.isRequired,
    onDone: PropTypes.func
  };

  state = { canSubmit: false };

  enableButton = () => { this.setState({ canSubmit: true }); }
  disableButton = () => { this.setState({ canSubmit: false }); }

  submitForm = (model) => {
    if (this.props.login.guid) {
      this.props.updateLogin(this.props.login.guid, {
        username: model.username,
        accesskey: model.accesskey,
        server: model.server
      });
    } else {
      this.props.addLogin(model.username, model.accesskey, model.server);
    }
    this.refs.form.reset();
    if (this.props.onDone) { this.props.onDone(); }
  }

  onClickSubmit = () => { this.refs.form.submit(); }
  onClickDelete = () => {
    this.props.deleteLogin(this.props.login.guid);
    if (this.props.onDone) { this.props.onDone(); }
  }

  render () {
    const actions = [
      <FlatButton
        type='submit'
        primary
        disabled={!this.state.canSubmit}
        onClick={this.onClickSubmit}
        label='Save'
      />,
      <FlatButton
        secondary
        disabled={!this.props.login.guid}
        onClick={this.onClickDelete}
        label='Delete'
      />
    ];

    return (
      <Dialog
        title={this.props.login.guid ? 'Edit' : 'Add'}
        onRequestClose={this.props.onDone}
        actions={actions}
        autoScrollBodyContent
        open
      >
        <Form ref='form'
          onValid={this.enableButton}
          onInvalid={this.disableButton}
          onValidSubmit={this.submitForm}
          >
          <FormsyText
            name='username'
            required
            value={this.props.login.username}
            hintText='Sauce Labs Username'
            validations='minLength:1,maxLength:1000'
          />
          <br />
          <FormsyText
            name='accesskey'
            type='password'
            value={this.props.login.accesskey}
            required
            hintText='Sauce Labs Access Key'
            validations='minLength:1,maxLength:1000'
          />
          <br/>
          <FormsyText
            name='server'
{'fraction_non_alphanumeric': 0.1280388978930308, 'fraction_numerical': 0.003601656762110571, 'mean_word_length': 2.2747641509433962, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 29, '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': '7373346', 'n_tokens_mistral': 1641, 'n_tokens_neox': 1632, 'n_words': 288}