<commit_before>// @flow //
import * as React from 'react'
import { connect } from 'react-redux'
import { getConfig, addManualIp } from '../../../config'
import { startDiscovery } from '../../../discovery'

import { Formik, Form, Field } from 'formik'
import IpField from './IpField'

import type { State, Dispatch } from '../../../types'
import type { DiscoveryCandidates } from '../../../config'

type OP = {||}

type SP = {| candidates: DiscoveryCandidates |}

type DP = {| addManualIp: (ip: string) => mixed |}

type Props = { ...SP, ...DP }

class IpForm extends React.Component<Props> {
  inputRef: { current: null | HTMLInputElement }

  constructor(props: Props) {
    super(props)
    this.inputRef = React.createRef()
  }

  render() {
    return (
      <Formik
        initialValues={{ ip: '' }}
        onSubmit={(values, actions) => {
          this.props.addManualIp(values.ip)

          const $input = this.inputRef.current
          if ($input) $input.blur()

          actions.resetForm()<commit_msg>fix(app): Disable manual ip double submit on enter keypress (#3376)<commit_after>// @flow //
import * as React from 'react'
import { connect } from 'react-redux'
import { getConfig, addManualIp } from '../../../config'
import { startDiscovery } from '../../../discovery'

import { Formik, Form, Field } from 'formik'
import IpField from './IpField'

import type { State, Dispatch } from '../../../types'
import type { DiscoveryCandidates } from '../../../config'

type OP = {||}

type SP = {| candidates: DiscoveryCandidates |}

type DP = {| addManualIp: (ip: string) => mixed |}

type Props = { ...SP, ...DP }

class IpForm extends React.Component<Props> {
  inputRef: { current: null | HTMLInputElement }

  constructor(props: Props) {
    super(props)
    this.inputRef = React.createRef()
  }

  render() {
    return (
      <Formik
        initialValues={{ ip: '' }}
        onSubmit={(values, actions) => {
          // trim whitespace and carriage returns
          const ip = values.ip.trim()
          // guard against double submit on enter keypress
          if (!ip) return

          this.props.addManualIp(ip)

          const $input = this.inputRef.current
          if ($input) $input.blur()

          actions.resetForm()
{'fraction_non_alphanumeric': 0.16083296411165263, 'fraction_numerical': 0.0017722640673460345, 'mean_word_length': 2.5898251192368837, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '6099759', 'n_tokens_mistral': 700, 'n_tokens_neox': 682, 'n_words': 196}