<commit_before>import React from 'react'
import gql from 'graphql-tag'
import { withApollo } from 'react-apollo'
import { Form, Grid, Select } from 'semantic-ui-react'
import RolesQuery from 'components/queries/RolesQuery'
import PlayerSelector from './PlayerSelector'
import GraphQLErrorMessage from 'components/GraphQLErrorMessage'

class AssignPlayersRoleForm extends React.Component {
  state = { loading: false, error: null }

  handlePlayerChange = (value) => {
    this.setState({ players: value })
  }

  handleChange = (e, { name, value }) => this.setState({ [name]: value })

  onSubmit = async () => {
    const { players, role } = this.state

    this.setState({ loading: true })

    try {
      await this.props.client.mutate({ mutation, variables: { players, role: parseInt(role, 10) } })
    } catch (error) {
      this.setState({ error })
    }

    this.setState({ loading: false })
  }

  render() {
    const { error, loading } = this.state

    return (
      <Grid>
        <Grid.Row columns={3}>
          <Grid.Column width={10}>
            <GraphQLErrorMessage error={error} />
            <PlayerSelector handleChange={this.handlePlayerChange} />
          </Grid.Column>
          <Grid.Column width={4}>
            <RolesQuery>
              {({ roles }) => {
                const data = roles.map(role => ({ key: role.id, text: role.name, value: role.id } ))

                return (
                  <Form.Field
                    required
                    name='role'
                    control={Select}
                    options={data}
                    placeholder='Role'
                    onChange={this.handleChange}
                  /><commit_msg>Handle assign players role errors correctly<commit_after>import React from 'react'
import gql from 'graphql-tag'
import { withApollo } from 'react-apollo'
import { Form, Grid, Select } from 'semantic-ui-react'
import RolesQuery from 'components/queries/RolesQuery'
import PlayerSelector from './PlayerSelector'
import GraphQLErrorMessage from 'components/GraphQLErrorMessage'

class AssignPlayersRoleForm extends React.Component {
  state = { loading: false, error: null }

  handlePlayerChange = (value) => {
    this.setState({ players: value })
  }

  handleChange = (e, { name, value }) => this.setState({ [name]: value })

  onSubmit = async () => {
    const { players, role } = this.state

    this.setState({ loading: true, error: null })

    try {
      await this.props.client.mutate({ mutation, variables: { players, role: parseInt(role, 10) } })
    } catch (error) {
      this.setState({ error })
    }

    this.setState({ loading: false, players: [] })
  }

  render() {
    const { error, loading } = this.state

    return (
      <Grid>
        <Grid.Row columns={3}>
          <Grid.Column width={10}>
            <GraphQLErrorMessage error={error} />
            <PlayerSelector handleChange={this.handlePlayerChange} />
          </Grid.Column>
          <Grid.Column width={4}>
            <RolesQuery>
              {({ roles }) => {
                const data = roles.map(role => ({ key: role.id, text: role.name, value: role.id } ))

                return (
                  <Form.Field
                    required
                    name='role'
                    control={Select}
                    options={data}
                    placeholder='Role'
                    onChange={this.handleChange}
                  />
{'fraction_non_alphanumeric': 0.1266628108733372, 'fraction_numerical': 0.003470213996529786, 'mean_word_length': 2.088392857142857, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 31, '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': '5551317', 'n_tokens_mistral': 978, 'n_tokens_neox': 937, 'n_words': 234}