<commit_before>import React, { Component } from 'react'
import { Modal, Button, Radio, FormControl, Alert } from 'react-bootstrap'
import Select from 'react-select'
import _ from 'lodash'

const style = require('./style.scss')

export default class ConditionModalForm extends Component {
  state = {
    typeOfTransition: 'end',
    flowToSubflow: null,
    flowToNode: null,
    transitionError: null,
    conditionError: null
  }

  componentWillReceiveProps(nextProps) {
    const { item } = nextProps

    if (this.props.show || !nextProps.show) {
      return
    }

    if (item && item.node) {
      let typeOfTransition = item.node.indexOf('.') !== -1 ? 'subflow' : 'node'
      typeOfTransition = item.node === 'END' ? 'end' : typeOfTransition
      typeOfTransition = /^#/.test(item.node) ? 'return' : typeOfTransition

      this.setState({
        typeOfTransition,
        condition: item.condition,
        flowToSubflow: typeOfTransition === 'subflow' ? item.node : null,
        flowToNode: typeOfTransition === 'node' ? item.node : null,
        returnToNode: typeOfTransition === 'return' ? item.node.substr(1) : ''
      })
    } else {
      this.resetForm({ condition: (item && item.condition) || '' })
    }

    this.setState({ isEdit: Boolean(item) })
  }

  changeTransitionType(type) {
    const subflowOptions = this.getSubflowOptions()
    const nodeOptions = this.getNodeOptions()
    this.setState({
      typeOfTransition: type,
      flowToSubflow: this.state.flowToSubflow || _.get(subflowOptions, '[0].value'),
      flowToNode: this.state.flowToNode || _.get(nodeOptions, '[0].value')
    })
  }

  validation() {
    if (this.state.typeOfTransition === 'subflow' && !this.state.flowToSubflow) {
      this.setState({
        transitionError: 'You must select a subflow to transition to'
      })

      return false
    }

    if (this.state.typeOfTransition === 'node' && !this.state.flowToNode && this.getNodeOptions().length > 0) {
      this.setState({
        transitionError: 'You must select a subflow to transition to'
      })

      return false
    }

    if (_.isEmpty(this.state.condition)) {
      this.setState({
        conditionError: 'Specify a condition'
      })

      return false
    }

    this.setState({
      conditionError: null,
      transitionError: null<commit_msg>fix(flow): allow empty transition to node and clear error<commit_after>import React, { Component } from 'react'
import { Modal, Button, Radio, FormControl, Alert } from 'react-bootstrap'
import Select from 'react-select'
import _ from 'lodash'

const style = require('./style.scss')

export default class ConditionModalForm extends Component {
  state = {
    typeOfTransition: 'end',
    flowToSubflow: null,
    flowToNode: null,
    transitionError: null,
    conditionError: null
  }

  componentWillReceiveProps(nextProps) {
    const { item } = nextProps

    if (this.props.show || !nextProps.show) {
      return
    }

    if (item && item.node) {
      let typeOfTransition = item.node.indexOf('.') !== -1 ? 'subflow' : 'node'
      typeOfTransition = item.node === 'END' ? 'end' : typeOfTransition
      typeOfTransition = /^#/.test(item.node) ? 'return' : typeOfTransition

      this.setState({
        typeOfTransition,
        condition: item.condition,
        flowToSubflow: typeOfTransition === 'subflow' ? item.node : null,
        flowToNode: typeOfTransition === 'node' ? item.node : null,
        returnToNode: typeOfTransition === 'return' ? item.node.substr(1) : ''
      })
    } else {
      this.resetForm({ condition: (item && item.condition) || '' })
    }

    this.setState({ isEdit: Boolean(item) })
  }

  changeTransitionType(type) {
    const subflowOptions = this.getSubflowOptions()
    const nodeOptions = this.getNodeOptions()
    this.setState({
      typeOfTransition: type,
      flowToSubflow: this.state.flowToSubflow || _.get(subflowOptions, '[0].value'),
      flowToNode: this.state.flowToNode || _.get(nodeOptions, '[0].value'),
      transitionError: null
    })
  }

  validation() {
    if (this.state.typeOfTransition === 'subflow' && !this.state.flowToSubflow) {
      this.setState({
        transitionError: 'You must select a subflow to transition to'
      })

      return false
    }

    if (_.isEmpty(this.state.condition)) {
      this.setState({
        conditionError: 'Specify a condition'
      })

      return false
    }

    this.setState({
      conditionError: null,
      transitionError: null
{'fraction_non_alphanumeric': 0.13114025338964214, 'fraction_numerical': 0.0020004445432318294, 'mean_word_length': 2.937007874015748, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '19273', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1334, 'n_words': 309}