<commit_before>import React from 'react';
import { t } from 'i18next';
import _ from 'lodash';
import { Loadout } from './loadout.service';
import { router } from '../../router';

export default function LoadoutDrawerOptions(
  this: void,
  {
    loadout,
    showClass,
    isNew,
    classTypeOptions,
    updateLoadout,
    saveLoadout,
    saveAsNew
  }: {
    loadout?: Loadout;
    showClass: boolean;
    isNew: boolean;
    clashingLoadout?: Loadout;
    classTypeOptions: {
      label: string;
      value: number;
    }[];
    updateLoadout(loadout: Loadout);
    saveLoadout(e);
    saveAsNew(e);
  }
) {
  if (!loadout) {
    return null;
  }

  const setName = (e: React.ChangeEvent<HTMLInputElement>) => {
    updateLoadout({
      ...loadout,
      name: e.target.value
    });
  };

  const setClassType = (e: React.ChangeEvent<HTMLSelectElement>) => {
    updateLoadout({
      ...loadout,
      classType: parseInt(e.target.value, 10)
    });
  };

  const setClearSpace = (e: React.ChangeEvent<HTMLInputElement>) => {
    updateLoadout({
      ...loadout,
      clearSpace: e.target.checked
    });
  };

  return (
    <div className="loadout-options">
      <form onSubmit={saveLoadout}>
        <div className="input-group loadout-name">
          <input
            className="dim-input"
            name="name"
            onChange={setName}
            minLength={1}
            maxLength={50}
            required={true}
            type="text"
            value={loadout.name}
            placeholder={t('Loadouts.LoadoutName')}
          />
          {showClass && (
            <select
              className="dim-select"
              name="classType"
              onChange={setClassType}
              value={loadout.classType}
            >
              {classTypeOptions.map((option) => (
                <option key={option.value} value={option.value}>
                  {option.label}
                </option>
              ))}
            </select>
          )}
        </div>
        <div className="input-group">
          <button
            className="dim-button"
            disabled={!loadout.name.length || _.isEmpty(loadout.items)}
          >
            {t('Loadouts.Save')}
          </button>
          {!isNew && (
            <button className="dim-button" onClick={saveAsNew}>
              {t('Loadouts.SaveAsNew')}
            </button>
          )}
        </div>
        {$featureFlags.d2LoadoutBuilder && (
          <div className="input-group">
            <button className="dim-button" onClick={(e) => goToLoadoutBuilder(e, loadout)}>
              {t('LB.LB')}
            </button>
          </div>
        )}
        <div className="input-group">
          <label>
            <input type="checkbox" checked={Boolean(loadout.clearSpace)} onChange={setClearSpace} />{' '}
            {t('Loadouts.ClearSpace')}
          </label>
        </div>
      </form>
    </div>
  );
}

function goToLoadoutBuilder(e, loadout?: Loadout) {
  e.preventDefault();

  if (_.size(loadout!.items) === 0 || confirm(t('Loadouts.Abandon'))) {
    router.stateService.go(
      this.props.account.destinyVersion === 2
        ? 'destiny2.loadoutbuilder'
        : 'destiny1.loadout-builder'
    );
  }
}
<commit_msg>fixed this undefined issue in goToLoadoutBuilder<commit_after>import React from 'react';
import { t } from 'i18next';
import _ from 'lodash';
import { Loadout } from './loadout.service';
import { router } from '../../router';

export default function LoadoutDrawerOptions(
  this: void,
  {
    loadout,
    showClass,
    isNew,
    classTypeOptions,
    updateLoadout,
    saveLoadout,
    saveAsNew
  }: {
    loadout?: Loadout;
    showClass: boolean;
    isNew: boolean;
    clashingLoadout?: Loadout;
    classTypeOptions: {
      label: string;
      value: number;
    }[];
    updateLoadout(loadout: Loadout);
    saveLoadout(e);
    saveAsNew(e);
  }
) {
  if (!loadout) {
    return null;
  }

  const setName = (e: React.ChangeEvent<HTMLInputElement>) => {
    updateLoadout({
      ...loadout,
      name: e.target.value
    });
  };

  const setClassType = (e: React.ChangeEvent<HTMLSelectElement>) => {
    updateLoadout({
      ...loadout,
      classType: parseInt(e.target.value, 10)
    });
  };

  const setClearSpace = (e: React.ChangeEvent<HTMLInputElement>) => {
    updateLoadout({
      ...loadout,
      clearSpace: e.target.checked
    });
  };

  return (
    <div className="loadout-options">
      <form onSubmit={saveLoadout}>
        <div className="input-group loadout-name">
          <input
            className="dim-input"
            name="name"
            onChange={setName}
            minLength={1}
            maxLength={50}
            required={true}
            type="text"
            value={loadout.name}
            placeholder={t('Loadouts.LoadoutName')}
          />
          {showClass && (
            <select
              className="dim-select"
              name="classType"
              onChange={setClassType}
              value={loadout.classType}
            >
              {classTypeOptions.map((option) => (
                <option key={option.value} value={option.value}>
                  {option.label}
                </option>
              ))}
            </select>
          )}
        </div>
        <div className="input-group">
          <button
            className="dim-button"
            disabled={!loadout.name.length || _.isEmpty(loadout.items)}
          >
            {t('Loadouts.Save')}
          </button>
          {!isNew && (
            <button className="dim-button" onClick={saveAsNew}>
              {t('Loadouts.SaveAsNew')}
            </button>
          )}
        </div>
        {$featureFlags.d2LoadoutBuilder && (
          <div className="input-group">
            <button className="dim-button" onClick={(e) => goToLoadoutBuilder(e, loadout)}>
              {t('LB.LB')}
            </button>
          </div>
        )}
        <div className="input-group">
          <label>
            <input type="checkbox" checked={Boolean(loadout.clearSpace)} onChange={setClearSpace} />{' '}
            {t('Loadouts.ClearSpace')}
          </label>
        </div>
      </form>
    </div>
  );
}

function goToLoadoutBuilder(e, loadout?: Loadout) {
  e.preventDefault();
  if (!loadout) {
    return;
  }

  if (_.size(loadout.items) === 0 || confirm(t('Loadouts.Abandon'))) {
    router.stateService.go(
      loadout.destinyVersion === 2 ? 'destiny2.loadoutbuilder' : 'destiny1.loadout-builder'
    );
  }
}

{'fraction_non_alphanumeric': 0.14594430071526404, 'fraction_numerical': 0.003652412113833511, 'mean_word_length': 1.86611426079372, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 71, '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': '6875307', 'n_tokens_mistral': 1995, 'n_tokens_neox': 1963, 'n_words': 332}