<commit_before>import PropTypes from "prop-types";
import React from "react";

import UniversePackage from "#SRC/js/structs/UniversePackage";

import Framework from "#PLUGINS/services/src/js/structs/Framework";
import { routerShape } from "react-router";
import FrameworkConfigurationReviewScreen from "#SRC/js/components/FrameworkConfigurationReviewScreen";
import Loader from "#SRC/js/components/Loader";
import CosmosPackagesStore from "#SRC/js/stores/CosmosPackagesStore";
import StringUtil from "#SRC/js/utils/StringUtil";
import { COSMOS_SERVICE_DESCRIBE_CHANGE } from "#SRC/js/constants/EventTypes";
import { getDefaultFormState } from "react-jsonschema-form/lib/utils";

const METHODS_TO_BIND = [
  "handleEditClick",
  "onCosmosPackagesStoreServiceDescriptionSuccess"
];

class FrameworkConfigurationContainer extends React.Component {
  constructor(props) {
    super(props);

    const { service } = this.props;

    this.state = {
      frameworkData: null,
      packageDetails: null
    };

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

    CosmosPackagesStore.fetchServiceDescription(service.getId());
  }

  componentDidMount() {
    CosmosPackagesStore.addChangeListener(
      COSMOS_SERVICE_DESCRIBE_CHANGE,
      this.onCosmosPackagesStoreServiceDescriptionSuccess
    );
  }

  componentWillUnmount() {
    CosmosPackagesStore.removeChangeListener(
      COSMOS_SERVICE_DESCRIBE_CHANGE,
      this.onCosmosPackagesStoreServiceDescriptionSuccess
    );
  }

  onCosmosPackagesStoreServiceDescriptionSuccess() {
    const fullPackage = CosmosPackagesStore.getServiceDetails();
    const packageDetails = new UniversePackage(fullPackage.package);

    const schema = packageDetails.getConfig();
    const frameworkData = getDefaultFormState(
      schema,
      fullPackage.resolvedOptions,
      schema.definitions
    );

    this.setState({ frameworkData, packageDetails });
  }

  handleEditClick() {
    const { router } = this.context;
    const { service } = this.props;

    router.push(
      `/services/detail/${encodeURIComponent(service.getId())}/edit/`
    );
  }

  render() {
    const { frameworkData, packageDetails } = this.state;

    if (!frameworkData) {
      return <Loader />;
    }

    const frameworkMeta =
      StringUtil.capitalize(packageDetails.getName()) +
      " " +
      packageDetails.getVersion();

    return (
      <FrameworkConfigurationReviewScreen
        frameworkData={frameworkData}
        onEditClick={this.handleEditClick}
        frameworkMeta={frameworkMeta}
      />
    );
  }
}

FrameworkConfigurationContainer.propTypes = {
  service: PropTypes.instanceOf(Framework).isRequired
};

FrameworkConfigurationContainer.contextTypes = {
  router: routerShape
};

module.exports = FrameworkConfigurationContainer;<commit_msg>chore(FrameworkConfigurationContainer): fix react warning<commit_after>import PropTypes from "prop-types";
import React from "react";

import UniversePackage from "#SRC/js/structs/UniversePackage";

import Framework from "#PLUGINS/services/src/js/structs/Framework";
import Application from "#PLUGINS/services/src/js/structs/Application";

import { routerShape } from "react-router";
import FrameworkConfigurationReviewScreen from "#SRC/js/components/FrameworkConfigurationReviewScreen";
import Loader from "#SRC/js/components/Loader";
import CosmosPackagesStore from "#SRC/js/stores/CosmosPackagesStore";
import StringUtil from "#SRC/js/utils/StringUtil";
import { COSMOS_SERVICE_DESCRIBE_CHANGE } from "#SRC/js/constants/EventTypes";
import { getDefaultFormState } from "react-jsonschema-form/lib/utils";

const METHODS_TO_BIND = [
  "handleEditClick",
  "onCosmosPackagesStoreServiceDescriptionSuccess"
];

class FrameworkConfigurationContainer extends React.Component {
  constructor(props) {
    super(props);

    const { service } = this.props;

    this.state = {
      frameworkData: null,
      packageDetails: null
    };

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

    CosmosPackagesStore.fetchServiceDescription(service.getId());
  }

  componentDidMount() {
    CosmosPackagesStore.addChangeListener(
      COSMOS_SERVICE_DESCRIBE_CHANGE,
      this.onCosmosPackagesStoreServiceDescriptionSuccess
    );
  }

  componentWillUnmount() {
    CosmosPackagesStore.removeChangeListener(
      COSMOS_SERVICE_DESCRIBE_CHANGE,
      this.onCosmosPackagesStoreServiceDescriptionSuccess
    );
  }

  onCosmosPackagesStoreServiceDescriptionSuccess() {
    const fullPackage = CosmosPackagesStore.getServiceDetails();
    const packageDetails = new UniversePackage(fullPackage.package);

    const schema = packageDetails.getConfig();
    const frameworkData = getDefaultFormState(
      schema,
      fullPackage.resolvedOptions,
      schema.definitions
    );

    this.setState({ frameworkData, packageDetails });
  }

  handleEditClick() {
    const { router } = this.context;
    const { service } = this.props;

    router.push(
      `/services/detail/${encodeURIComponent(service.getId())}/edit/`
    );
  }

  render() {
    const { frameworkData, packageDetails } = this.state;

    if (!frameworkData) {
      return <Loader />;
    }

    const frameworkMeta =
      StringUtil.capitalize(packageDetails.getName()) +
      " " +
      packageDetails.getVersion();

    return (
      <FrameworkConfigurationReviewScreen
        frameworkData={frameworkData}
        onEditClick={this.handleEditClick}
        frameworkMeta={frameworkMeta}
      />
    );
  }
}

FrameworkConfigurationContainer.propTypes = {
  service: PropTypes.oneOfType([
    PropTypes.instanceOf(Framework),
    PropTypes.instanceOf(Application)
  ]).isRequired
};

FrameworkConfigurationContainer.contextTypes = {
  router: routerShape
};

module.exports = FrameworkConfigurationContainer;
{'fraction_non_alphanumeric': 0.10236756940895929, 'fraction_numerical': 0.0, 'mean_word_length': 4.1827007943512795, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '6082681', 'n_tokens_mistral': 1678, 'n_tokens_neox': 1649, 'n_words': 267}