<commit_before>import classNames from "classnames";
import { Modal } from "reactjs-components";
import mixin from "reactjs-mixin";
import React from "react";
import { StoreMixin } from "mesosphere-shared-reactjs";

import BetaOptInUtil from "../../utils/BetaOptInUtil";
import CosmosErrorHeader from "../CosmosErrorHeader";
import CosmosErrorMessage from "../CosmosErrorMessage";
import CosmosPackagesStore from "../../stores/CosmosPackagesStore";
import defaultServiceImage
  from "../../../../plugins/services/src/img/icon-service-default-large@2x.png";
import Icon from "../Icon";
import Image from "../Image";
import InternalStorageMixin from "../../mixins/InternalStorageMixin";
import Loader from "../Loader";
import ReviewConfig from "../ReviewConfig";
import SchemaForm from "../SchemaForm";
import SchemaUtil from "../../utils/SchemaUtil";
import StringUtil from "../../utils/StringUtil";
import TabsMixin from "../../mixins/TabsMixin";
import UniversePackage from "../../structs/UniversePackage";

const PREINSTALL_NOTES_CHAR_LIMIT = 140;

const METHODS_TO_BIND = [
  "getAdvancedSubmit",
  "handleAcceptBetaTerms",
  "handleChangeTab",
  "handleInstallPackage",
  "handleAdvancedFormChange",
  "handleModalClose",
  "handlePreinstallNotesToggle"
];

class InstallPackageModal
  extends mixin(InternalStorageMixin, TabsMixin, StoreMixin) {
  constructor() {
    super(...arguments);

    this.tabs_tabs = {
      betaTerms: "BetaTerms",
      defaultInstall: "DefaultInstall",
      advancedInstall: "AdvancedInstall",
      reviewAdvancedConfig: "ReviewAdvancedConfig",
      packageInstalled: "PackageInstalled"
    };

    this.internalStorage_set({
      descriptionError: null,
      hasFormErrors: false,
      installError: null,
      pendingRequest: false
    });

    this.state = {
      currentTab: "defaultInstall",
      schemaIncorrect: false,
      truncatedPreInstallNotes: true
    };

    this.store_listeners = [
      {
        name: "cosmosPackages",
        events: [
          "descriptionError",
          "descriptionSuccess",
          "installError",
          "installSuccess"
        ]
      }
    ];

    METHODS_TO_BIND.forEach(method => {
      this[method] = this[method].bind(this);
    });
  }

  componentWillReceiveProps(nextProps) {
    super.componentWillReceiveProps(...arguments);
    const { props } = this;
    // If closing
    if (props.open && !nextProps.open) {
      this.internalStorage_set({
        descriptionError: null,
        installError: null,
        pendingRequest: false
      });
      // Reset our trigger submit for advanced install
      this.triggerAdvancedSubmit = undefined;
      this.setState({
        currentTab: "defaultInstall",
        truncatedPreInstallNotes: true
      });

      return;
    }

    if (nextProps.isBetaPackage) {
      this.setState({
        betaTermsAccepted: false,
        betaOptInProperties: BetaOptInUtil.getProperty(<commit_msg>fix(InstallPackageModal): add tighter constraints for auto-install<commit_after>import classNames from "classnames";
import { Modal } from "reactjs-components";
import mixin from "reactjs-mixin";
import React from "react";
import { StoreMixin } from "mesosphere-shared-reactjs";

import BetaOptInUtil from "../../utils/BetaOptInUtil";
import CosmosErrorHeader from "../CosmosErrorHeader";
import CosmosErrorMessage from "../CosmosErrorMessage";
import CosmosPackagesStore from "../../stores/CosmosPackagesStore";
import defaultServiceImage
  from "../../../../plugins/services/src/img/icon-service-default-large@2x.png";
import Icon from "../Icon";
import Image from "../Image";
import InternalStorageMixin from "../../mixins/InternalStorageMixin";
import Loader from "../Loader";
import ReviewConfig from "../ReviewConfig";
import SchemaForm from "../SchemaForm";
import SchemaUtil from "../../utils/SchemaUtil";
import StringUtil from "../../utils/StringUtil";
import TabsMixin from "../../mixins/TabsMixin";
import UniversePackage from "../../structs/UniversePackage";

const PREINSTALL_NOTES_CHAR_LIMIT = 140;

const METHODS_TO_BIND = [
  "getAdvancedSubmit",
  "handleAcceptBetaTerms",
  "handleChangeTab",
  "handleInstallPackage",
  "handleAdvancedFormChange",
  "handleModalClose",
  "handlePreinstallNotesToggle"
];

class InstallPackageModal
  extends mixin(InternalStorageMixin, TabsMixin, StoreMixin) {
  constructor() {
    super(...arguments);

    this.tabs_tabs = {
      betaTerms: "BetaTerms",
      defaultInstall: "DefaultInstall",
      advancedInstall: "AdvancedInstall",
      reviewAdvancedConfig: "ReviewAdvancedConfig",
      packageInstalled: "PackageInstalled"
    };

    this.internalStorage_set({
      descriptionError: null,
      hasFormErrors: false,
      installError: null,
      pendingRequest: false
    });

    this.state = {
      currentTab: "defaultInstall",
      schemaIncorrect: false,
      truncatedPreInstallNotes: true
    };

    this.store_listeners = [
      {
        name: "cosmosPackages",
        events: [
          "descriptionError",
          "descriptionSuccess",
          "installError",
          "installSuccess"
        ]
      }
    ];

    METHODS_TO_BIND.forEach(method => {
      this[method] = this[method].bind(this);
    });
  }

  componentWillReceiveProps(nextProps) {
    super.componentWillReceiveProps(...arguments);
    const { props } = this;

    // Return early if open prop did not change
    if (props.open === nextProps.open) {
      return;
    }

    // If closing
    if (props.open && !nextProps.open) {
      this.internalStorage_set({
        descriptionError: null,
        installError: null,
        pendingRequest: false
      });
      // Reset our trigger submit for advanced install
      this.triggerAdvancedSubmit = undefined;
      this.setState({
        currentTab: "defaultInstall",
        truncatedPreInstallNotes: true
      });

      return;
    }

    // If opening

    if (nextProps.isBetaPackage) {
      this.setState({
        betaTermsAccepted: false,
        betaOptInProperties: BetaOptInUtil.getProperty(
{'fraction_non_alphanumeric': 0.12127203822705553, 'fraction_numerical': 0.0013181743285549513, 'mean_word_length': 3.1718213058419242, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1208371', 'n_tokens_mistral': 1732, 'n_tokens_neox': 1680, 'n_words': 372}