<commit_before>import React, { PropTypes } from "react";
import ReactDOM from "react-dom";
import { Modal, Button } from "react-bootstrap";

import DataModel from "../../DataModel";
import mapDefault from "./mapDefault";


export default class FormModal extends DataModel {
	static displayName = "FormModal";
	static dataModelType = "DataModel";

	static propTypes = {
		children: PropTypes.node,
		bsSize: PropTypes.string,
		dialogClassName: PropTypes.string,
		show: PropTypes.bool.isRequired,
		title: PropTypes.string,

		onCancel: PropTypes.func.isRequired,
		cancelText: PropTypes.string,
		onSave: PropTypes.func.isRequired,
		saveText: PropTypes.string,
		data: PropTypes.object,
		mapFunc: PropTypes.func,
		style: React.PropTypes.object,
		focusFirstInput: PropTypes.bool,
	};

	static defaultProps = {
		title: null,
		bsSize: null,
		dialogClassName: "",
		cancelText: "Cancel",
		saveText: "Save",
		data: {},
		mapFunc: mapDefault,
		style: {},
		focusFirstInput: true,
	};

	inputRefs = [];

	componentDidMount() {
		if (this.props.show) {
			this.onShow();
		}
	}

	componentWillUpdate(nextProps) {
		if (nextProps.show !== this.props.show) {
			this.inputRefs = [];
		}
	}

	componentDidUpdate(prevProps) {
		if (!prevProps.show && this.props.show) {
			this.onShow();
		}
	}

	focusRefInput(ref) {
		if (ref.refs.input) {
			const input = ReactDOM.findDOMNode(ref.refs.input);
			input.focus();
			input.scrollIntoView();
		}
	}

	onShow() {
		if (this.inputRefs.length > 0 && this.props.focusFirstInput) {
			this.focusRefInput(this.inputRefs[0]);
		}
	}

	onRef(ref) {
		if (ref) {
			this.inputRefs.push(ref);

			const next = this.inputRefs.length;
			ref.onKeyUp = event => {
				if (event.keyCode === 13 && next < this.inputRefs.length) {
					this.focusRefInput(this.inputRefs[next]);
				}
			};
		}
	}

	render() {
		const { bsSize, dialogClassName, show} = this.props;
		const { title, cancelText, saveText } = this.props;
		const { onCancel, onSave } = this.props;
		const mappedChildren = super.render();
		const validationError = this.validate();
		return (
			<Modal bsSize={bsSize} dialogClassName={dialogClassName} show={show} onHide={() => undefined}><commit_msg>onSave at FormModal when pressing enter in last input<commit_after>import React, { PropTypes } from "react";
import ReactDOM from "react-dom";
import { Modal, Button } from "react-bootstrap";

import DataModel from "../../DataModel";
import mapDefault from "./mapDefault";


export default class FormModal extends DataModel {
	static displayName = "FormModal";
	static dataModelType = "DataModel";

	static propTypes = {
		children: PropTypes.node,
		bsSize: PropTypes.string,
		dialogClassName: PropTypes.string,
		show: PropTypes.bool.isRequired,
		title: PropTypes.string,

		onCancel: PropTypes.func.isRequired,
		cancelText: PropTypes.string,
		onSave: PropTypes.func.isRequired,
		saveText: PropTypes.string,
		data: PropTypes.object,
		mapFunc: PropTypes.func,
		style: React.PropTypes.object,
		focusFirstInput: PropTypes.bool,
	};

	static defaultProps = {
		title: null,
		bsSize: null,
		dialogClassName: "",
		cancelText: "Cancel",
		saveText: "Save",
		data: {},
		mapFunc: mapDefault,
		style: {},
		focusFirstInput: true,
	};

	inputRefs = [];

	componentDidMount() {
		if (this.props.show) {
			this.onShow();
		}
	}

	componentWillUpdate(nextProps) {
		if (nextProps.show !== this.props.show) {
			this.inputRefs = [];
		}
	}

	componentDidUpdate(prevProps) {
		if (!prevProps.show && this.props.show) {
			this.onShow();
		}
	}

	focusRefInput(ref) {
		if (ref.refs.input) {
			const input = ReactDOM.findDOMNode(ref.refs.input);
			input.focus();
			input.scrollIntoView();
		}
	}

	onShow() {
		if (this.inputRefs.length > 0 && this.props.focusFirstInput) {
			this.focusRefInput(this.inputRefs[0]);
		}
	}

	onRef(ref) {
		if (!ref) {
			return;
		}
		this.inputRefs.push(ref);

		const nextInputIndex = this.inputRefs.length;
		ref.onKeyUp = event => {
			if (event.keyCode === 13) {
				this.onEnterReleased(nextInputIndex);
			}
		};
	}

	onEnterReleased(nextInputIndex) {
		if (nextInputIndex < this.inputRefs.length) {
			this.focusRefInput(this.inputRefs[nextInputIndex]);
		} else if (nextInputIndex === this.inputRefs.length) {
			if (this.validate() === null) {
				this.props.onSave(this.state);
			}
		}
	}

	render() {
		const { bsSize, dialogClassName, show} = this.props;
		const { title, cancelText, saveText } = this.props;
		const { onCancel, onSave } = this.props;
		const mappedChildren = super.render();
		const validationError = this.validate();
		return (
			<Modal bsSize={bsSize} dialogClassName={dialogClassName} show={show} onHide={() => undefined}>
{'fraction_non_alphanumeric': 0.14419595314164005, 'fraction_numerical': 0.0017039403620873268, 'mean_word_length': 3.8967674661105316, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '4487661', 'n_tokens_mistral': 1762, 'n_tokens_neox': 1595, 'n_words': 321}