<commit_before>/**
Copyright (c) 2017 <NAME>

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
**/
import React from "react";
import {connect} from "react-redux";
import {
	removeExpressionUI,
	updateExpressionUI
} from "../UIActions";
import {globExpressionToRegExp} from "../../services/libs";

const styles = {
	actionButton: {
		margin: "0 5px"
	}
};

const ActionButtonColumn = ({
	editId, onRemoveExpression, onUpdateExpression, editMode, setEdit, expressionObject, expressionInput, storeId
}) => (
	<td style={{
		width: "60px"
	}}>
		<i onClick={() => onRemoveExpression({
			id: expressionObject.id, storeId
		})} style={styles.actionButton} className="fa fa-times fa-2x cursorPoint" aria-hidden="true"></i>
		{
			editMode && expressionObject.id === editId ? <i onClick={() => setEdit({
				editMode: false, id: expressionObject.id, expressionInput: expressionObject.expression
			})} style={styles.actionButton} className="fa fa-eraser fa-2x  cursorPoint" aria-hidden="true"></i> :
				<i onClick={() => setEdit({
					editMode: true, id: expressionObject.id, expressionInput: expressionObject.expression
				})} style={styles.actionButton} className="fa fa-pencil-square-o fa-2x  cursorPoint" aria-hidden="true"></i>

		}
		{
			editMode && expressionObject.id === editId ?
				<i
					onClick={() => {
						setEdit({
							editMode: false
						});
						onUpdateExpression({
							...expressionObject, expression: expressionInput, storeId
						});
					}}
					style={styles.actionButton}
					className="fa fa-floppy-o fa-2x cursorPoint"
					aria-hidden="true"
				>
				</i> : ""
		}

	</td>
);

class ExpressionTableBody extends React.Component {
	constructor(props) {
		super(props);
		this.state = {
			expressionInput: "",
			editMode: false,
			id: ""
		};
	}

	// Toggle edit for a particular row
	setEdit(editModeObject) {
		this.setState(editModeObject);
	}

	render() {
		const {
			onRemoveExpression, onUpdateExpression, storeId
		} = this.props;
		const {
			editMode, id, expressionInput
		} = this.state;
		const expressions = this.props.expressions === undefined ? [] : this.props.expressions;
		return (
			<tbody>
				{
					expressions.map((expression) => (
						<tr key={expression.id}>
							<ActionButtonColumn
								editMode={this.state.editMode}
								expressionObject={expression}
								expressionInput={expressionInput}
								editId={id}
								storeId={storeId}
								onRemoveExpression={(payload) => onRemoveExpression(payload)}
								onUpdateExpression={(payload) => onUpdateExpression(payload)}
								setEdit={(editModeObject) => this.setEdit(editModeObject)}
							/>
							{
								editMode & id === expression.id ?
									<div className="md-form">
										<input id="form1" className="form-control" value={expressionInput} onChange={(e) => this.setState({
											expressionInput: e.target.value
										})} type="text" />
									</div> :
									<td>{`${expression.expression}`}</td>
							}
							<td>{`${globExpressionToRegExp(expression.expression)}`}</td>
							<td>
								{
									editMode & id === expression.id ?
										<button onClick={() => onUpdateExpression({
											id, storeId, listType: expression.listType === "GREY" ? "WHITE" : "GREY"
										})} className="btn btn-primary">
											{`${expression.listType === "WHITE" ? browser.i18n.getMessage("whiteListWordText") : browser.i18n.getMessage("greyListWordText")}`}
										</button> :
										`${expression.listType === "WHITE" ? browser.i18n.getMessage("whiteListWordText") : browser.i18n.getMessage("greyListWordText")}`
								}
							</td>
						</tr>
					))
				}
			</tbody>
		);
	}
}

const mapDispatchToProps = (dispatch) => ({
	onRemoveExpression(payload) {
		dispatch(
			removeExpressionUI(payload)
		);
	},
	onUpdateExpression(payload) {
		dispatch(
			updateExpressionUI(payload)
		);
	}
});
export default connect(null, mapDispatchToProps)(ExpressionTableBody);<commit_msg>Inline button for toggling white/gray lists.<commit_after>/**
Copyright (c) 2017 <NAME>

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
**/
import React from "react";
import {connect} from "react-redux";
import {
	removeExpressionUI,
	updateExpressionUI
} from "../UIActions";
import {globExpressionToRegExp} from "../../services/libs";

const styles = {
	actionButton: {
		margin: "0 5px"
	}
};

const ActionButtonColumn = ({
	editId, onRemoveExpression, onUpdateExpression, editMode, setEdit, expressionObject, expressionInput, storeId
}) => (
	<td style={{
		width: "60px"
	}}>
		<i onClick={() => onRemoveExpression({
			id: expressionObject.id, storeId
		})} style={styles.actionButton} className="fa fa-times fa-2x cursorPoint" aria-hidden="true"></i>
		{
			editMode && expressionObject.id === editId ? <i onClick={() => setEdit({
				editMode: false, id: expressionObject.id, expressionInput: expressionObject.expression
			})} style={styles.actionButton} className="fa fa-eraser fa-2x  cursorPoint" aria-hidden="true"></i> :
				<i onClick={() => setEdit({
					editMode: true, id: expressionObject.id, expressionInput: expressionObject.expression
				})} style={styles.actionButton} className="fa fa-pencil-square-o fa-2x  cursorPoint" aria-hidden="true"></i>

		}
		{
			editMode && expressionObject.id === editId ?
				<i
					onClick={() => {
						setEdit({
							editMode: false
						});
						onUpdateExpression({
							...expressionObject, expression: expressionInput, storeId
						});
					}}
					style={styles.actionButton}
					className="fa fa-floppy-o fa-2x cursorPoint"
					aria-hidden="true"
				>
				</i> : ""
		}

	</td>
);

class ExpressionTableBody extends React.Component {
	constructor(props) {
		super(props);
		this.state = {
			expressionInput: "",
			editMode: false,
			id: ""
		};
	}

	// Toggle edit for a particular row
	setEdit(editModeObject) {
		this.setState(editModeObject);
	}

	render() {
		const {
			onRemoveExpression, onUpdateExpression, storeId
		} = this.props;
		const {
			editMode, id, expressionInput
		} = this.state;
		const expressions = this.props.expressions === undefined ? [] : this.props.expressions;
		return (
			<tbody>
				{
					expressions.map((expression) => (
						<tr key={expression.id}>
							<ActionButtonColumn
								editMode={this.state.editMode}
								expressionObject={expression}
								expressionInput={expressionInput}
								editId={id}
								storeId={storeId}
								onRemoveExpression={(payload) => onRemoveExpression(payload)}
								onUpdateExpression={(payload) => onUpdateExpression(payload)}
								setEdit={(editModeObject) => this.setEdit(editModeObject)}
							/>
							{
								editMode & id === expression.id ?
									<div className="md-form">
										<input id="form1" className="form-control" value={expressionInput} onChange={(e) => this.setState({
											expressionInput: e.target.value
										})} type="text" />
									</div> :
									<td>{`${expression.expression}`}</td>
							}
							<td>{`${globExpressionToRegExp(expression.expression)}`}</td>
							<td>
								{`${expression.listType === "WHITE" ? browser.i18n.getMessage("whiteListWordText") : browser.i18n.getMessage("greyListWordText")}`}
								<button onClick={() => onUpdateExpression({
									id: expression.id,
									storeId,
									listType: expression.listType === "GREY" ? "WHITE" : "GREY"
								})} className="btn btn-light" style={{ marginLeft: "5px", padding: "4px 7px" }}>
									<i className="fa fa-refresh" aria-hidden="true"/>
								</button>
							</td>
						</tr>
					))
				}
			</tbody>
		);
	}
}

const mapDispatchToProps = (dispatch) => ({
	onRemoveExpression(payload) {
		dispatch(
			removeExpressionUI(payload)
		);
	},
	onUpdateExpression(payload) {
		dispatch(
			updateExpressionUI(payload)
		);
	}
});
export default connect(null, mapDispatchToProps)(ExpressionTableBody);
{'fraction_non_alphanumeric': 0.1422339570657789, 'fraction_numerical': 0.004706692687406727, 'mean_word_length': 3.3800904977375565, 'pattern_counts': {'":': 0, '<': 58, '<?xml version=': 0, '>': 82, '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': '2133264', 'n_tokens_mistral': 3361, 'n_tokens_neox': 2596, 'n_words': 596}