<commit_before>import React, {Component} from 'react';

import CollapsibleContainer from '../../../../../../src/js/components/CollapsibleContainer';
import FieldError from '../../../../../../src/js/components/form/FieldError';
import FieldHelp from '../../../../../../src/js/components/form/FieldHelp';
import FieldInput from '../../../../../../src/js/components/form/FieldInput';
import FieldTextarea from '../../../../../../src/js/components/form/FieldTextarea';
import FieldLabel from '../../../../../../src/js/components/form/FieldLabel';
import FieldSelect from '../../../../../../src/js/components/form/FieldSelect';
import FormGroup from '../../../../../../src/js/components/form/FormGroup';
import Icon from '../../../../../../src/js/components/Icon';
import {FormReducer as healthChecks} from '../../reducers/serviceForm/HealthChecks';

class HealthChecksFormSection extends Component {
  getAdvancedSettings(healthCheck, key) {
    const {errors} = this.props;
    if (healthCheck.protocol !== 'COMMAND' && healthCheck.protocol !== 'HTTP' &&
      healthCheck.protocol !== 'HTTPS') {
      return null;
    }

    return (
      <CollapsibleContainer label="Advanced Settings">
        <div className="flex row">
          <FormGroup
            className="column-3"
            required={false}
            showError={Boolean(errors.healthChecks[key])}>
            <FieldLabel>Grace Period (s)</FieldLabel>
            <FieldInput
              name={`healthChecks.${key}.gracePeriodSeconds`}
              type="number"
              min="0"
              value={healthCheck.gracePeriodSeconds}/>
            <FieldError>{errors.healthChecks[key]}</FieldError>
          </FormGroup>
          <FormGroup
            className="column-3"
            required={false}
            showError={Boolean(errors.healthChecks[key])}>
            <FieldLabel>Interval (s)</FieldLabel>
            <FieldInput
              name={`healthChecks.${key}.intervalSeconds`}
              type="number"
              min="0"
              value={healthCheck.intervalSeconds}/>
            <FieldError>{errors.healthChecks[key]}</FieldError>
          </FormGroup>
          <FormGroup
            className="column-3"
            required={false}
            showError={Boolean(errors.healthChecks[key])}>
            <FieldLabel>Timeout (s)</FieldLabel>
            <FieldInput
              name={`healthChecks.${key}.timeoutSeconds`}
              type="number"
              min="0"
              value={healthCheck.timeoutSeconds}/>
            <FieldError>{errors.healthChecks[key]}</FieldError>
          </FormGroup>
          <FormGroup
            className="column-3"
            required={false}
            showError={Boolean(errors.healthChecks[key])}>
            <FieldLabel>Max Failures</FieldLabel>
            <FieldInput
              name={`healthChecks.${key}.maxConsecutiveFailures`}
              type="number"
              min="0"
              value={healthCheck.maxConsecutiveFailures}/>
            <FieldError>{errors.healthChecks[key]}</FieldError>
          </FormGroup>
        </div>
      </CollapsibleContainer>);
  }

  getCommandFields(healthCheck, key) {
    const {errors} = this.props;

    if (healthCheck.protocol !== 'COMMAND') {
      return null;
    }

    return (
      <div className="flex row">
        <FormGroup
          className="column-12"
          required={false}
          showError={Boolean(errors.healthChecks[key])}>
          <FieldLabel>Command</FieldLabel>
          <FieldTextarea
            name={`healthChecks.${key}.command`}
            type="text"
            value={healthCheck.command}/>
          <FieldError>{errors.healthChecks[key]}</FieldError>
        </FormGroup>
      </div>
    );
  }

  getHTTPFields(healthCheck, key) {
    const {errors} = this.props;

    if (healthCheck.protocol !== 'HTTP' && healthCheck.protocol !== 'HTTPS') {
      return null;
    }

    return [
      (<div className="flex row" key="path">
        <FormGroup
          className="column-6"
          required={false}
          showError={false}>
          <FieldLabel>Service Endpoint</FieldLabel>
          <FieldSelect name={`healthChecks.${key}.portIndex`}>
            <option value="">Select Endpoint</option>
          </FieldSelect>
        </FormGroup>
        <FormGroup
          className="column-6"
          required={false}
          showError={Boolean(errors.healthChecks[key])}>
          <FieldLabel>Path</FieldLabel>
          <FieldInput
            name={`healthChecks.${key}.path`}
            type="text"
            value={healthCheck.path}/>
          <FieldError>{errors.healthChecks[key]}</FieldError>
        </FormGroup>
      </div>),
      (<div className="row flex" key="HTTPS">
        <FormGroup showError={false} className="column-12">
          <FieldLabel>
            <FieldInput
              checked={healthCheck.protocol === 'HTTPS'}
              name={`healthChecks.${key}.https`}
              type="checkbox"
              value="HTTPS"/>
            Make HTTPS
            <FieldHelp>Morbi leo risus</FieldHelp>
          </FieldLabel>
          <FieldError>{errors.healthChecks[key]}</FieldError>
        </FormGroup>
      </div>)
    ];
  }

  getHealthChecksLines(data) {
    const {errors} = this.props;

    return data.map((healthCheck, key) => {
      return (
        <div key={key} className="panel pod-short">
          <div className="pod-narrow pod-short">
            <div className="flex row">
              <FormGroup
                className="column-6"
                required={false}
                showError={Boolean(errors.healthChecks[key])}>
                <FieldLabel>Protocol</FieldLabel>
                <FieldSelect name={`healthChecks.${key}.protocol`}
                  value={healthCheck.protocol &&
                  healthCheck.protocol.replace('HTTPS', 'HTTP')}>
                  <option value="">Select Protocol</option>
                  <option value="COMMAND">Command</option>
                  <option value="HTTP">HTTP</option>
                </FieldSelect>
                <FieldError>{errors.healthChecks[key]}</FieldError>
              </FormGroup>
              <div className="form-remove">
                <a className="button button-link"
                  onClick={this.props.onRemoveItem.bind(this, {value: key, path: 'healthChecks'})}>
                  <Icon id="close" color="grey" size="tiny"/>
                </a>
              </div>
            </div>
            {this.getCommandFields(healthCheck, key)}
            {this.getHTTPFields(healthCheck, key)}
            {this.getAdvancedSettings(healthCheck, key)}
          </div>
        </div>
      );
    });
  }

  render() {
    let {data} = this.props;<commit_msg>Use healthChecks directly from the errors object<commit_after>import React, {Component} from 'react';

import CollapsibleContainer from '../../../../../../src/js/components/CollapsibleContainer';
import FieldError from '../../../../../../src/js/components/form/FieldError';
import FieldHelp from '../../../../../../src/js/components/form/FieldHelp';
import FieldInput from '../../../../../../src/js/components/form/FieldInput';
import FieldTextarea from '../../../../../../src/js/components/form/FieldTextarea';
import FieldLabel from '../../../../../../src/js/components/form/FieldLabel';
import FieldSelect from '../../../../../../src/js/components/form/FieldSelect';
import FormGroup from '../../../../../../src/js/components/form/FormGroup';
import Icon from '../../../../../../src/js/components/Icon';
import {FormReducer as healthChecks} from '../../reducers/serviceForm/HealthChecks';

class HealthChecksFormSection extends Component {
  getAdvancedSettings(healthCheck, key) {
    const {healthChecks} = this.props.errors;
    if (healthCheck.protocol !== 'COMMAND' && healthCheck.protocol !== 'HTTP' &&
      healthCheck.protocol !== 'HTTPS') {
      return null;
    }

    return (
      <CollapsibleContainer label="Advanced Settings">
        <div className="flex row">
          <FormGroup
            className="column-3"
            required={false}
            showError={Boolean(healthChecks[key])}>
            <FieldLabel>Grace Period (s)</FieldLabel>
            <FieldInput
              name={`healthChecks.${key}.gracePeriodSeconds`}
              type="number"
              min="0"
              value={healthCheck.gracePeriodSeconds}/>
            <FieldError>{healthChecks[key]}</FieldError>
          </FormGroup>
          <FormGroup
            className="column-3"
            required={false}
            showError={Boolean(healthChecks[key])}>
            <FieldLabel>Interval (s)</FieldLabel>
            <FieldInput
              name={`healthChecks.${key}.intervalSeconds`}
              type="number"
              min="0"
              value={healthCheck.intervalSeconds}/>
            <FieldError>{healthChecks[key]}</FieldError>
          </FormGroup>
          <FormGroup
            className="column-3"
            required={false}
            showError={Boolean(healthChecks[key])}>
            <FieldLabel>Timeout (s)</FieldLabel>
            <FieldInput
              name={`healthChecks.${key}.timeoutSeconds`}
              type="number"
              min="0"
              value={healthCheck.timeoutSeconds}/>
            <FieldError>{healthChecks[key]}</FieldError>
          </FormGroup>
          <FormGroup
            className="column-3"
            required={false}
            showError={Boolean(healthChecks[key])}>
            <FieldLabel>Max Failures</FieldLabel>
            <FieldInput
              name={`healthChecks.${key}.maxConsecutiveFailures`}
              type="number"
              min="0"
              value={healthCheck.maxConsecutiveFailures}/>
            <FieldError>{healthChecks[key]}</FieldError>
          </FormGroup>
        </div>
      </CollapsibleContainer>);
  }

  getCommandFields(healthCheck, key) {
    const {healthChecks} = this.props.errors;

    if (healthCheck.protocol !== 'COMMAND') {
      return null;
    }

    return (
      <div className="flex row">
        <FormGroup
          className="column-12"
          required={false}
          showError={Boolean(healthChecks[key])}>
          <FieldLabel>Command</FieldLabel>
          <FieldTextarea
            name={`healthChecks.${key}.command`}
            type="text"
            value={healthCheck.command}/>
          <FieldError>{healthChecks[key]}</FieldError>
        </FormGroup>
      </div>
    );
  }

  getHTTPFields(healthCheck, key) {
    const {healthChecks} = this.props.errors;

    if (healthCheck.protocol !== 'HTTP' && healthCheck.protocol !== 'HTTPS') {
      return null;
    }

    return [
      (<div className="flex row" key="path">
        <FormGroup
          className="column-6"
          required={false}
          showError={false}>
          <FieldLabel>Service Endpoint</FieldLabel>
          <FieldSelect name={`healthChecks.${key}.portIndex`}>
            <option value="">Select Endpoint</option>
          </FieldSelect>
        </FormGroup>
        <FormGroup
          className="column-6"
          required={false}
          showError={Boolean(healthChecks[key])}>
          <FieldLabel>Path</FieldLabel>
          <FieldInput
            name={`healthChecks.${key}.path`}
            type="text"
            value={healthCheck.path}/>
          <FieldError>{healthChecks[key]}</FieldError>
        </FormGroup>
      </div>),
      (<div className="row flex" key="HTTPS">
        <FormGroup showError={false} className="column-12">
          <FieldLabel>
            <FieldInput
              checked={healthCheck.protocol === 'HTTPS'}
              name={`healthChecks.${key}.https`}
              type="checkbox"
              value="HTTPS"/>
            Make HTTPS
            <FieldHelp>Morbi leo risus</FieldHelp>
          </FieldLabel>
          <FieldError>{healthChecks[key]}</FieldError>
        </FormGroup>
      </div>)
    ];
  }

  getHealthChecksLines(data) {
    const {healthChecks} = this.props.errors;

    return data.map((healthCheck, key) => {
      return (
        <div key={key} className="panel pod-short">
          <div className="pod-narrow pod-short">
            <div className="flex row">
              <FormGroup
                className="column-6"
                required={false}
                showError={Boolean(healthChecks[key])}>
                <FieldLabel>Protocol</FieldLabel>
                <FieldSelect name={`healthChecks.${key}.protocol`}
                  value={healthCheck.protocol &&
                  healthCheck.protocol.replace('HTTPS', 'HTTP')}>
                  <option value="">Select Protocol</option>
                  <option value="COMMAND">Command</option>
                  <option value="HTTP">HTTP</option>
                </FieldSelect>
                <FieldError>{healthChecks[key]}</FieldError>
              </FormGroup>
              <div className="form-remove">
                <a className="button button-link"
                  onClick={this.props.onRemoveItem.bind(this, {value: key, path: 'healthChecks'})}>
                  <Icon id="close" color="grey" size="tiny"/>
                </a>
              </div>
            </div>
            {this.getCommandFields(healthCheck, key)}
            {this.getHTTPFields(healthCheck, key)}
            {this.getAdvancedSettings(healthCheck, key)}
          </div>
        </div>
      );
    });
  }

  render() {
    let {data} = this.props;
{'fraction_non_alphanumeric': 0.1552130954136558, 'fraction_numerical': 0.0022120631175342868, 'mean_word_length': 1.9230603448275863, 'pattern_counts': {'":': 0, '<': 191, '<?xml version=': 0, '>': 193, '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': '829434', 'n_tokens_mistral': 3641, 'n_tokens_neox': 3607, 'n_words': 575}