<commit_before>import React from "react";
import {TextAreaFormGroup, TextFormGroup} from "bootstrap-react-components";
import AbilityList from "../Ability/List";

export default class RaceEditor extends React.Component {

	cancel() {

	}

	componentWillMount() {
		this.propsToState(this.props);

	}

	componentWillReceiveProps(nextProps) {
		this.propsToState(nextProps);
	}

	constructor(props) {
		super(props);
	}

	descriptionChange(e) {
		this.setState({
			description: e.target.value
		});
	}

	nameChange(e) {
		this.setState({
			name: e.target.value
		});
	}

	onAbilityListChange(list) {
		this.setState({
			abilities: list
		});
	}

	propsToState(props) {
		let {_id, name, description, abilities = [], descriptionError, abilityError, nameError} = props;
		this.setState({
			_id, name, description, abilities, descriptionError, abilityError, nameError
		});
	}

	render() {
		const {name, description, abilities, descriptionError, nameError} = this.state;

		return (
				<div id="raceForm">
					<TextFormGroup
							error={nameError}
							label="Race"
							id="raceFormName"
							onChange={this.nameChange.bind(this)}
							value={name}
					/>
					<TextAreaFormGroup
							error={descriptionError}
							label="Description"
							id="raceFormDescription"
							onChange={this.descriptionChange.bind(this)}
							value={description}
					/>
					<AbilityList list={abilities} onListChange={this.onAbilityListChange.bind(this)} allowEditing={true}/>
					<button type="button" class="btn btn-default"
					        onClick={this.save.bind(this)}>Save
					</button>
					<button type="button" class="btn btn-default" onClick={this.cancel.bind(this)}>Cancel</button>
				</div>
		)
	}

	save(event) {
		event.preventDefault();
		let {_id, name, description, abilities} = this.state;
		this.props.save({
			_id, name, description, abilities
		})
	}
}<commit_msg>Race editor refactored.<commit_after>import React from "react";
import {TextAreaFormGroup, TextFormGroup} from "bootstrap-react-components";
import AbilityList from "../Ability/List";
import {ItemEditor} from "../Item";

export default class RaceEditor extends ItemEditor {


	descriptionChange(e) {
		this.setState({
			description: e.target.value
		});
	}

	nameChange(e) {
		this.setState({
			name: e.target.value
		});
	}

	onAbilityListChange(list) {
		this.setState({
			abilities: list
		});
	}

	propsToState(props) {
		let {_id, name, description, abilities = [], descriptionError, abilityError, nameError} = props;
		this.setState({
			_id, name, description, abilities, descriptionError, abilityError, nameError
		});
	}

	render() {
		const {name, description, abilities, descriptionError, nameError} = this.state;

		return (
				<div id="raceForm">
					<TextFormGroup
							error={nameError}
							label="Race"
							id="raceFormName"
							onChange={this.nameChange.bind(this)}
							value={name}
					/>
					<TextAreaFormGroup
							error={descriptionError}
							label="Description"
							id="raceFormDescription"
							onChange={this.descriptionChange.bind(this)}
							value={description}
					/>
					<AbilityList list={abilities} onListChange={this.onAbilityListChange.bind(this)} allowEditing={true}/>
					<button type="button" class="btn btn-default"
					        onClick={this.save.bind(this)}>Save
					</button>
					<button type="button" class="btn btn-default" onClick={this.cancel.bind(this)}>Cancel</button>
				</div>
		)
	}

	stateToItem() {
		let {_id, name, description, abilities} = this.state;
		return {_id, name, description, abilities};
	}
}
{'fraction_non_alphanumeric': 0.13982696064750208, 'fraction_numerical': 0.0, 'mean_word_length': 3.6849673202614377, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '809897', 'n_tokens_mistral': 1389, 'n_tokens_neox': 1113, 'n_words': 214}