<commit_before>'use strict';

import React, {Component} from 'react';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import PropTypes from 'prop-types';
import SwitcherStyle from './switcher-style';
import SwitcherRetry from './switcher-retry';
import ControlButton from '../controls/button';
import State from '../state';
import * as actions from '../../modules/actions';
import {isSuccessStatus, isFailStatus, isErroredStatus} from '../../../common-utils';
import {isAcceptable} from '../../modules/utils';

class SectionBrowserBody extends Component {
    static propTypes = {
        result: PropTypes.object.isRequired,
        retries: PropTypes.array
    }

    static defaultProps = {
        retries: []
    }

    constructor(props) {
        super(props);

        this.state = {
            color: 1,
            retry: this.props.retries.length
        };
    }

    onSwitcherStyleChange = (index) => {
        this.setState({color: index});
    }

    onSwitcherRetryChange = (index) => {
        this.setState({retry: index});
    }

    onTestAccept = () => {
        const {result, suite} = this.props;

        this.props.actions.acceptTest(suite, result.name, this.state.retry);
    }

    onTestRetry = () => {
        const {result, suite} = this.props;

        this.props.actions.retryTest(suite, result.name);
    }

    _addExtraButtons(activeResult) {
        const {gui, running} = this.props;
        const {status} = activeResult;
        const acceptDisabled = !isAcceptable(activeResult);
        const retryDisabled = running || isSuccessStatus(status) || (!isFailStatus(status) && !isErroredStatus(status));

        return gui
            ? (
                <div className="controls__item">
                    <ControlButton
                        label="✔ Accept"
                        isSuiteControl={true}
                        isDisabled={acceptDisabled}
                        handler={this.onTestAccept}
                    />
                    <ControlButton
                        label="↻ Retry"
                        isSuiteControl={true}
                        isDisabled={retryDisabled}
                        handler={this.onTestRetry}
                    />
                </div>
            )
            : null;
    }

    _getActiveResult = () => {
        const {result, retries} = this.props;

        return retries.concat(result)[this.state.retry];
    }

    render() {
        const {retries} = this.props;
        const activeResult = this._getActiveResult();

        return (
            <div className="section__body">
                <div className={`image-box cswitcher_color_${this.state.color}`}>
                    <div className="controls">
                        <div className="controls__item">
                            <SwitcherStyle onChange={this.onSwitcherStyleChange}/><commit_msg>feat: enable retry button for passed tests (#115)<commit_after>'use strict';

import React, {Component} from 'react';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import PropTypes from 'prop-types';
import SwitcherStyle from './switcher-style';
import SwitcherRetry from './switcher-retry';
import ControlButton from '../controls/button';
import State from '../state';
import * as actions from '../../modules/actions';
import {isAcceptable} from '../../modules/utils';

class SectionBrowserBody extends Component {
    static propTypes = {
        result: PropTypes.object.isRequired,
        retries: PropTypes.array
    }

    static defaultProps = {
        retries: []
    }

    constructor(props) {
        super(props);

        this.state = {
            color: 1,
            retry: this.props.retries.length
        };
    }

    onSwitcherStyleChange = (index) => {
        this.setState({color: index});
    }

    onSwitcherRetryChange = (index) => {
        this.setState({retry: index});
    }

    onTestAccept = () => {
        const {result, suite} = this.props;

        this.props.actions.acceptTest(suite, result.name, this.state.retry);
    }

    onTestRetry = () => {
        const {result, suite} = this.props;

        this.props.actions.retryTest(suite, result.name);
    }

    _addExtraButtons(activeResult) {
        const {gui, running} = this.props;
        const acceptDisabled = !isAcceptable(activeResult);

        return gui
            ? (
                <div className="controls__item">
                    <ControlButton
                        label="✔ Accept"
                        isSuiteControl={true}
                        isDisabled={acceptDisabled}
                        handler={this.onTestAccept}
                    />
                    <ControlButton
                        label="↻ Retry"
                        isSuiteControl={true}
                        isDisabled={running}
                        handler={this.onTestRetry}
                    />
                </div>
            )
            : null;
    }

    _getActiveResult = () => {
        const {result, retries} = this.props;

        return retries.concat(result)[this.state.retry];
    }

    render() {
        const {retries} = this.props;
        const activeResult = this._getActiveResult();

        return (
            <div className="section__body">
                <div className={`image-box cswitcher_color_${this.state.color}`}>
                    <div className="controls">
                        <div className="controls__item">
                            <SwitcherStyle onChange={this.onSwitcherStyleChange}/>
{'fraction_non_alphanumeric': 0.11977865048197073, 'fraction_numerical': 0.0008925383791503035, 'mean_word_length': 1.7931206380857427, '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': '2632942', 'n_tokens_mistral': 1477, 'n_tokens_neox': 1465, 'n_words': 299}