<commit_before>// @flow
import React from 'react';
import { browserHistory } from 'react-router';
import { connect } from 'react-redux';

import { namespaceURL } from '../urls';
import { namespaceAdd } from '../actions';

const NewNamespace = ({ dispatch }) => {
  let input;
  return (
    <form onSubmit={e => {
      e.preventDefault();
      if (!input.value.trim()) {
        return;
      }
      dispatch(namespaceAdd(input.value));
      browserHistory.push(namespaceURL(input.value));
    }}>
      <div className="form-group">
        <label>Namespace Name</label>
        <input type="text" className="form-control" ref={node => input = node}/>
      </div>
      <button type="submit" className="btn btn-primary" >Create namespace</button>
    </form>
  );
};

const connected = connect()(NewNamespace);

export default connected;<commit_msg>cmd/elwinator: button to randomize namespace name<commit_after>// @flow
import React from 'react';
import { browserHistory } from 'react-router';
import { connect } from 'react-redux';

import { namespaceURL } from '../urls';
import { namespaceAdd } from '../actions';

const nameLength = 7;
const alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'

const randomName = (len: number): string => {
  let out = '';
  for (let i = 0; i < len; i++) {
    const randIndex = getRandomInt(0, alphabet.length)
    out += alphabet[randIndex];
  }
  return out;
}

function getRandomInt(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min)) + min;
}

const NewNamespace = ({ dispatch }) => {
  let input;
  return (
    <form onSubmit={e => {
      e.preventDefault();
      if (!input.value.trim()) {
        return;
      }
      dispatch(namespaceAdd(input.value));
      browserHistory.push(namespaceURL(input.value));
    }}>
      <div className="form-group">
        <label>Namespace Name</label>
        <input type="text" className="form-control" ref={node => input = node}/>
      </div>
      <button type="button" className="btn btn-primary" onClick={
        () => input.value = randomName(nameLength)
      }>Random Name</button><br />
      <button type="submit" className="btn btn-primary" >Create namespace</button>
    </form>
  );
};

const connected = connect()(NewNamespace);

export default connected;
{'fraction_non_alphanumeric': 0.15850021303792075, 'fraction_numerical': 0.005538985939497231, 'mean_word_length': 3.3643122676579926, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 32, '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': '1205230', 'n_tokens_mistral': 721, 'n_tokens_neox': 707, 'n_words': 173}