<commit_before>import React from "react";
import PropTypes from "prop-types";
import { includes } from "lodash-es";
import { Row, Col } from "react-bootstrap";
import { ListGroupItem } from "../../../base";
import { getTaskDisplayName } from "../../../utils";
import TaskField from "./TaskField";

const getInitialState = () => ({
    exceedsError: false,
    zeroError: false
});

export default class Task extends React.Component {

    constructor (props) {
        super(props);
        this.state = getInitialState();
    }

    componentDidUpdate (prevProps, prevState) {
        const { proc, mem, inst } = prevProps;

        if (proc === this.props.proc && mem === this.props.mem && inst === this.props.inst) {
            if (prevState.exceedsError || prevState.zeroError) {
                this.handleClearError();
            }
        }
    }

    handleChangeLimit = (name, value) => {
        this.handleClearError();
        this.props.onChangeLimit(this.props.taskPrefix, name, value);
    };

    handleClearError = () => {
        this.setState(getInitialState());
    };

    handleInvalid = (e) => {
        const zeroError = e.target.value === "0";

        this.setState({
            exceedsError: !zeroError,
            zeroError
        });
    };

    render () {

        const {
            inst,
            mem,
            proc,
            taskPrefix,
            minProc,
            minMem,
            resourceProc,
            resourceMem,
            readOnlyFields
        } = this.props;

        const readOnly = includes(readOnlyFields, taskPrefix);

        let error;

        if (this.state.zeroError) {
            error = "Value cannot be 0";
        }

        if (this.state.exceedsError) {
            error = "Value cannot exceed system resource limits";
        }

        const errorComponent = (
            <div className={error ? "input-form-error" : "input-form-error-none"}>
                <span className="input-error-message">
                    {error || "None"}
                </span>
            </div>
        );

        return (
            <ListGroupItem allowFocus bsStyle={this.state.error ? "danger" : null}>
                <h5><strong>{getTaskDisplayName(taskPrefix)}</strong></h5>
                <Row>
                    <Col md={4}>
                        <TaskField
                            name="proc"
                            value={proc}
                            readOnly={readOnly}
                            onChange={this.handleChangeLimit}
                            clear={this.handleClearError}
                            lowerLimit={minProc}
                            upperLimit={resourceProc}
                            onInvalid={this.handleInvalid}
                        />
                    </Col>
                    <Col md={4}>
                        <TaskField
                            name="mem"
                            value={mem}
                            readOnly={readOnly}
                            onChange={this.handleChangeLimit}
                            clear={this.handleClearError}
                            lowerLimit={minMem}
                            upperLimit={resourceMem}
                            onInvalid={this.handleInvalid}<commit_msg>Update administration Task component error display<commit_after>import React from "react";
import PropTypes from "prop-types";
import { includes } from "lodash-es";
import { Row, Col } from "react-bootstrap";
import { ListGroupItem } from "../../../base";
import { getTaskDisplayName } from "../../../utils";
import TaskField from "./TaskField";

const getInitialState = () => ({
    exceedsError: false,
    zeroError: false
});

export default class Task extends React.Component {

    constructor (props) {
        super(props);
        this.state = getInitialState();
    }

    componentDidUpdate (prevProps, prevState) {
        const { proc, mem, inst } = prevProps;

        if (proc === this.props.proc && mem === this.props.mem && inst === this.props.inst) {
            if (prevState.exceedsError || prevState.zeroError) {
                this.handleClearError();
            }
        }
    }

    handleChangeLimit = (name, value) => {
        this.handleClearError();
        this.props.onChangeLimit(this.props.taskPrefix, name, value);
    };

    handleClearError = () => {
        this.setState(getInitialState());
    };

    handleInvalid = (e) => {
        const zeroError = e.target.value === "0";

        this.setState({
            exceedsError: !zeroError,
            zeroError
        });
    };

    render () {

        const {
            inst,
            mem,
            proc,
            taskPrefix,
            minProc,
            minMem,
            resourceProc,
            resourceMem,
            readOnlyFields
        } = this.props;

        const readOnly = includes(readOnlyFields, taskPrefix);

        let error;

        if (this.state.zeroError) {
            error = "Value cannot be 0";
        }

        if (this.state.exceedsError) {
            error = "Value cannot exceed system resource limits";
        }

        const errorComponent = (
            <div className={error ? "input-form-error" : "input-form-error-none"}>
                <span className="input-error-message">
                    {error || "None"}
                </span>
            </div>
        );

        return (
            <ListGroupItem allowFocus>
                <h5><strong>{getTaskDisplayName(taskPrefix)}</strong></h5>
                <Row>
                    <Col md={4}>
                        <TaskField
                            name="proc"
                            value={proc}
                            readOnly={readOnly}
                            onChange={this.handleChangeLimit}
                            clear={this.handleClearError}
                            lowerLimit={minProc}
                            upperLimit={resourceProc}
                            onInvalid={this.handleInvalid}
                        />
                    </Col>
                    <Col md={4}>
                        <TaskField
                            name="mem"
                            value={mem}
                            readOnly={readOnly}
                            onChange={this.handleChangeLimit}
                            clear={this.handleClearError}
                            lowerLimit={minMem}
                            upperLimit={resourceMem}
                            onInvalid={this.handleInvalid}
{'fraction_non_alphanumeric': 0.11122913505311077, 'fraction_numerical': 0.0018209408194233688, 'mean_word_length': 1.2893365751997221, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 39, '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': '3744279', 'n_tokens_mistral': 1632, 'n_tokens_neox': 1588, 'n_words': 327}