<commit_before>var React = require("react/addons");

var appValidator = require("../validators/appValidator");
var ContainerConstants = require("../constants/ContainerConstants");
var DuplicableRowControls = require("../components/DuplicableRowControls");
var FormGroupComponent = require("../components/FormGroupComponent");

var ContainerSettingsComponent = React.createClass({
  displayName: "ContainerSettingsComponent",

  propTypes: {
    errors: React.PropTypes.array,
    model: React.PropTypes.object.isRequired
  },

  getInitialState: function () {
    var container = this.props.model.container;

    var portMappingsCount = 1;
    var parametersCount = 1;
    var volumesCount = 1;

    if (container != null) {
      if (container.docker != null && container.docker.portMappings != null) {
        portMappingsCount = container.docker.portMappings.length || 1;
      }
      if (container.parameters != null) {
        parametersCount = container.parameters.length || 1;
      }
      if (container.volumes != null) {
        volumesCount = container.volumes.length || 1;
      }
    }

    return {
      rows: {
        portMappings:
          Array(portMappingsCount).fill(true),
        parameters: Array(parametersCount).fill(true),
        volumes: Array(volumesCount).fill(true)
      }
    };
  },

  handleAddRow: function (rowKey, position, event) {
    event.target.blur();
    event.preventDefault();
    var rows = React.addons.update(
      this.state.rows, {[rowKey]: {$push: [true]}}
    );
    this.setState({rows: rows});
  },

  handleRemoveRow: function (rowKey, position, event) {
    /* Each array represents a list of duplicable rows, in order to keep track
     * of which rows have been deleted by the user. A value of false signifies
     * a deleted row.
     * The form submits values infered directly from the DOM.
     */
    event.target.blur();
    event.preventDefault();
    var rows = React.addons.update(
      this.state.rows, {[rowKey]: {[position]: {$set: false}}}
    );
    if (rows[rowKey].filter((exists) => exists).length === 0) {
      rows[rowKey].push(true);
    }
    this.setState({rows: rows});
  },

  getPortMappingRow: function (i = 0) {
    var props = this.props;
    var model = props.model;
    var errors = props.errors;

    return (
      <div key={`pm-${i}`} className="row duplicable-row">
        <div className="col-sm-3">
          <FormGroupComponent
            attribute={`container.docker.portMappings[${i}].containerPort`}
            label="Container port"
            model={model}
            errors={errors}
            validator={appValidator}>
            <input type="number" step="1" min="0" max="65535"/>
          </FormGroupComponent>
        </div>
        <div className="col-sm-3">
          <FormGroupComponent
            attribute={`container.docker.portMappings[${i}].hostPort`}
            label="Host port"
            model={model}
            errors={errors}
            validator={appValidator}>
            <input type="number" step="1" min="0" max="65535"/>
          </FormGroupComponent>
        </div>
        <div className="col-sm-2">
          <FormGroupComponent
            attribute={`container.docker.portMappings[${i}].servicePort`}
            label="Service port"
            model={model}
            errors={errors}
            validator={appValidator}>
            <input type="number" step="1" min="0" max="65535"/>
          </FormGroupComponent>
        </div><commit_msg>Revert "uncapitalise port in app modal"<commit_after>var React = require("react/addons");

var appValidator = require("../validators/appValidator");
var ContainerConstants = require("../constants/ContainerConstants");
var DuplicableRowControls = require("../components/DuplicableRowControls");
var FormGroupComponent = require("../components/FormGroupComponent");

var ContainerSettingsComponent = React.createClass({
  displayName: "ContainerSettingsComponent",

  propTypes: {
    errors: React.PropTypes.array,
    model: React.PropTypes.object.isRequired
  },

  getInitialState: function () {
    var container = this.props.model.container;

    var portMappingsCount = 1;
    var parametersCount = 1;
    var volumesCount = 1;

    if (container != null) {
      if (container.docker != null && container.docker.portMappings != null) {
        portMappingsCount = container.docker.portMappings.length || 1;
      }
      if (container.parameters != null) {
        parametersCount = container.parameters.length || 1;
      }
      if (container.volumes != null) {
        volumesCount = container.volumes.length || 1;
      }
    }

    return {
      rows: {
        portMappings:
          Array(portMappingsCount).fill(true),
        parameters: Array(parametersCount).fill(true),
        volumes: Array(volumesCount).fill(true)
      }
    };
  },

  handleAddRow: function (rowKey, position, event) {
    event.target.blur();
    event.preventDefault();
    var rows = React.addons.update(
      this.state.rows, {[rowKey]: {$push: [true]}}
    );
    this.setState({rows: rows});
  },

  handleRemoveRow: function (rowKey, position, event) {
    /* Each array represents a list of duplicable rows, in order to keep track
     * of which rows have been deleted by the user. A value of false signifies
     * a deleted row.
     * The form submits values infered directly from the DOM.
     */
    event.target.blur();
    event.preventDefault();
    var rows = React.addons.update(
      this.state.rows, {[rowKey]: {[position]: {$set: false}}}
    );
    if (rows[rowKey].filter((exists) => exists).length === 0) {
      rows[rowKey].push(true);
    }
    this.setState({rows: rows});
  },

  getPortMappingRow: function (i = 0) {
    var props = this.props;
    var model = props.model;
    var errors = props.errors;

    return (
      <div key={`pm-${i}`} className="row duplicable-row">
        <div className="col-sm-3">
          <FormGroupComponent
            attribute={`container.docker.portMappings[${i}].containerPort`}
            label="Container Port"
            model={model}
            errors={errors}
            validator={appValidator}>
            <input type="number" step="1" min="0" max="65535"/>
          </FormGroupComponent>
        </div>
        <div className="col-sm-3">
          <FormGroupComponent
            attribute={`container.docker.portMappings[${i}].hostPort`}
            label="Host Port"
            model={model}
            errors={errors}
            validator={appValidator}>
            <input type="number" step="1" min="0" max="65535"/>
          </FormGroupComponent>
        </div>
        <div className="col-sm-2">
          <FormGroupComponent
            attribute={`container.docker.portMappings[${i}].servicePort`}
            label="Service Port"
            model={model}
            errors={errors}
            validator={appValidator}>
            <input type="number" step="1" min="0" max="65535"/>
          </FormGroupComponent>
        </div>
{'fraction_non_alphanumeric': 0.13834329632792486, 'fraction_numerical': 0.009109023626530032, 'mean_word_length': 2.570630081300813, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 37, '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': '3742045', 'n_tokens_mistral': 2036, 'n_tokens_neox': 1978, 'n_words': 430}