<commit_before>define(
  [
    'react',
    'components/mixins/BootstrapModalMixin.react',
    'stores'
  ],
  function (React, BootstrapModalMixin, stores) {

    return React.createClass({

      getInitialState: function () {
        return {
          identity: this.props.identity,
          selectedCPU: null
        };
      },

      componentDidMount: function () {
        /* Calculate AU calculator options list one time as soon as the component initially renders
        to avoid having to constantly calculate the same list every time a render occurs. */

        // Get instances user has and add create option elements for each of them.
        var instanceOptions = stores.InstanceStore.getAll().map(function(instance){
          return (
            <option key={instance.id} value={instance.get('size').cpu}>{instance.get('name')}({instance.get('size').cpu} CPU)</option>
          );
        });

        // An array of CPU sizes to map to option values in the list
        var sizes = [1, 2, 4, 8, 16];

        // Actually map the CPU values to options
        var defaultOptions = sizes.map(function(size){
          return (
            <option key={size} value={size}>a {size} CPU instance</option>
          );
        });

        // Combine the instance size list and defualt size list into one to display
        var options = instanceOptions.concat(defaultOptions),
            // It's possible that the user has no instances when using this calculator, so default to the 1 CPU option
            cpuToSet = instanceOptions ? stores.InstanceStore.getAll().models[0].get('size').cpu : 1;

        this.setState({options: options, selectedCPU: cpuToSet});
      },

      handleCPUChange: function(e){
        this.setState({selectedCPU: Number(e.target.value)});
      },

      render: function(){
        var instances = stores.InstanceStore.getAll();

        if (!instances) return <div className="loading"/>;

        var remainingAU = stores.IdentityStore.get(this.props.identity).get('usage').remaining;

        var options = this.state.options;

        if(!this.state.options){
          return <div className="loading" />
        }
        var selectedCPU = this.state.selectedCPU ? this.state.selectedCPU: options[0];
<commit_msg>fix bug when user has no instances<commit_after>define(
  [
    'react',
    'components/mixins/BootstrapModalMixin.react',
    'stores'
  ],
  function (React, BootstrapModalMixin, stores) {

    return React.createClass({

      getInitialState: function () {
        return {
          identity: this.props.identity,
          selectedCPU: null
        };
      },

      componentDidMount: function () {
        /* Calculate AU calculator options list one time as soon as the component initially renders
        to avoid having to constantly calculate the same list every time a render occurs. */

        // Get instances user has and add create option elements for each of them.
        var instanceOptions = stores.InstanceStore.getAll().map(function(instance){
          return (
            <option key={instance.id} value={instance.get('size').cpu}>{instance.get('name')}({instance.get('size').cpu} CPU)</option>
          );
        });

        // An array of CPU sizes to map to option values in the list
        var sizes = [1, 2, 4, 8, 16];

        // Actually map the CPU values to options
        var defaultOptions = sizes.map(function(size){
          return (
            <option key={size} value={size}>a {size} CPU instance</option>
          );
        });

        // Combine the instance size list and defualt size list into one to display
        var options = instanceOptions.concat(defaultOptions),
            // It's possible that the user has no instances when using this calculator, so default to the 1 CPU option
            cpuToSet = instanceOptions.length > 0 ? stores.InstanceStore.getAll().models[0].get('size').cpu : 1;

        this.setState({options: options, selectedCPU: cpuToSet});
      },

      handleCPUChange: function(e){
        this.setState({selectedCPU: Number(e.target.value)});
      },

      render: function(){
        var instances = stores.InstanceStore.getAll();

        if (!instances) return <div className="loading"/>;

        var remainingAU = stores.IdentityStore.get(this.props.identity).get('usage').remaining;

        var options = this.state.options;

        if(!this.state.options){
          return <div className="loading" />
        }
        var selectedCPU = this.state.selectedCPU ? this.state.selectedCPU: options[0];

{'fraction_non_alphanumeric': 0.11286089238845144, 'fraction_numerical': 0.004593175853018373, 'mean_word_length': 2.4591527987897126, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, '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': '1371136', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1160, 'n_words': 361}