<commit_before>import React from 'react'

// Material UI imports
import TextField from 'material-ui/TextField';
import SelectField from 'material-ui/SelectField';
import MenuItem from 'material-ui/MenuItem';
import RaisedButton from 'material-ui/RaisedButton'
import ContentAdd from 'material-ui/svg-icons/content/add'

// Material UI Styles
const muiStyle = {
  floatingLabelStyle: {
    fontWeight: 'normal',
  },
  textFieldStyle: {
    margin: '0px 20px',
  },
  createButtonStyle:{
    margin: '80px 0px',
    minWidth: '116px',
  }
}

// Component Style
import style from './style'

import {createVehicle, getVehicleTypes, getVehicleGroups, getUnassignedAgents} from './actions'

export default class CreateVehicleForm extends React.Component {

  constructor(props) {
    super(props)
    this.state = {
      plateIdInput: "",
      vehicleTypeSelect: "",
      vehicleTypeList: [],
      vehicleGroupSelect: "",
      vehicleGroupList: [],
      agentListSelect: "",
      agentsList:[],
      inputError: ""
    }
  }

  componentWillMount() {
    this.updateVehicleTypes()
    this.updateVehicleGroups()
    this.updateAgentSelectList()
  }

  updateVehicleTypes(){
    getVehicleTypes((data) => {
      this.setState({
        vehicleTypeList: data,
      });
    }, (error) => {
      console.error(error);
    })
  }

  updateVehicleGroups(){
    getVehicleGroups((data) => {
      this.setState({
        vehicleGroupList: data,
      });
    }, (error) => {
      console.error(error);
    })
  }

  updateAgentSelectList(){
    getUnassignedAgents((data) => {
      this.setState({
        agentsList: data,
      });
    }, (error) => {
      console.error(error);
    })
  }

  // Handle Inputs
  handlePlateIdChange(event){
    this.setState({
      plateIdInput: event.target.value
    })
  }

  handleVehicleTypeChange(event, key, value){
    this.setState({
      vehicleTypeSelect: value
    })
  }

  handleVehicleGroupChange(event, key, value){
    this.setState({
      vehicleGroupSelect: value
    })
  }

  handleAgentListChange(event, key, value){
    this.setState({
      agentListSelect: value
    })
  }

  handleGroupChange(event){
    this.setState({
      groupInput: event.target.value
    })
  }

  handleCreateVehicle(event) {
    // Call preventDefault() on the event to prevent the browser's default
    // action of submitting the form.
    event.preventDefault();

    let plateId = this.state.plateIdInput
    let vehicleType = this.state.vehicleTypeSelect
    let agentUuid = this.state.agentListSelect
    let groupID = this.state.vehicleGroupSelect

    let validateForm = function(arr) {
      for (var i = 0; i < arr.length; i++) {
    		if (arr[i] == null || arr[i] == "") {
          return false
    		}
      }
      return true
    }

    let reqInputs = [plateId, vehicleType];

    if (validateForm(reqInputs)) {

      let formData = {
        plate_id: plateId,
        type: vehicleType,
        agent_uuid: agentUuid,
        // groups: groupID,
      }

      createVehicle(formData, (res) => {
        this.setState({
          plateIdInput: "",
          vehicleTypeSelect: "",
          vehicleGroupSelect: "",
          agentListSelect: "",
          inputError: ""<commit_msg>fix(CreateVehicleForm): fix bug on groups<commit_after>import React from 'react'

// Material UI imports
import TextField from 'material-ui/TextField';
import SelectField from 'material-ui/SelectField';
import MenuItem from 'material-ui/MenuItem';
import RaisedButton from 'material-ui/RaisedButton'
import ContentAdd from 'material-ui/svg-icons/content/add'

// Material UI Styles
const muiStyle = {
  floatingLabelStyle: {
    fontWeight: 'normal',
  },
  textFieldStyle: {
    margin: '0px 20px',
  },
  createButtonStyle:{
    margin: '80px 0px',
    minWidth: '116px',
  }
}

// Component Style
import style from './style'

import {createVehicle, getVehicleTypes, getVehicleGroups, getUnassignedAgents} from './actions'

export default class CreateVehicleForm extends React.Component {

  constructor(props) {
    super(props)
    this.state = {
      plateIdInput: "",
      vehicleTypeSelect: "",
      vehicleTypeList: [],
      vehicleGroupSelect: "",
      vehicleGroupList: [],
      agentListSelect: "",
      agentsList:[],
      inputError: ""
    }
  }

  componentWillMount() {
    this.updateVehicleTypes()
    this.updateVehicleGroups()
    this.updateAgentSelectList()
  }

  updateVehicleTypes(){
    getVehicleTypes((data) => {
      this.setState({
        vehicleTypeList: data,
      });
    }, (error) => {
      console.error(error);
    })
  }

  updateVehicleGroups(){
    getVehicleGroups((data) => {
      this.setState({
        vehicleGroupList: data,
      });
    }, (error) => {
      console.error(error);
    })
  }

  updateAgentSelectList(){
    getUnassignedAgents((data) => {
      this.setState({
        agentsList: data,
      });
    }, (error) => {
      console.error(error);
    })
  }

  // Handle Inputs
  handlePlateIdChange(event){
    this.setState({
      plateIdInput: event.target.value
    })
  }

  handleVehicleTypeChange(event, key, value){
    this.setState({
      vehicleTypeSelect: value
    })
  }

  handleVehicleGroupChange(event, key, value){
    this.setState({
      vehicleGroupSelect: value
    })
  }

  handleAgentListChange(event, key, value){
    this.setState({
      agentListSelect: value
    })
  }

  handleGroupChange(event){
    this.setState({
      groupInput: event.target.value
    })
  }

  handleCreateVehicle(event) {
    // Call preventDefault() on the event to prevent the browser's default
    // action of submitting the form.
    event.preventDefault();

    let plateId = this.state.plateIdInput
    let vehicleType = this.state.vehicleTypeSelect
    let agentUuid = this.state.agentListSelect
    let groupID = this.state.vehicleGroupSelect

    let validateForm = function(arr) {
      for (var i = 0; i < arr.length; i++) {
    		if (arr[i] == null || arr[i] == "") {
          return false
    		}
      }
      return true
    }

    let reqInputs = [plateId, vehicleType];

    if (validateForm(reqInputs)) {

      let formData = {
        plate_id: plateId,
        type: vehicleType,
        agent_uuid: agentUuid,
        groups: groupID,
      }

      createVehicle(formData, (res) => {
        this.setState({
          plateIdInput: "",
          vehicleTypeSelect: "",
          vehicleGroupSelect: [],
          agentListSelect: "",
          inputError: ""
{'fraction_non_alphanumeric': 0.12359895593428527, 'fraction_numerical': 0.0030707815138952864, 'mean_word_length': 2.6269487750556793, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '3017256', 'n_tokens_mistral': 2008, 'n_tokens_neox': 1998, 'n_words': 402}