<commit_before>import { Feature } from 'toolkit/extension/features/feature';
import { getEmberView } from 'toolkit/extension/utils/ember';
import { formatCurrency } from 'toolkit/extension/utils/currency';
import { isCurrentRouteBudgetPage } from 'toolkit/extension/utils/ynab';

export class DisplayTotalMonthlyGoals extends Feature {
  shouldInvoke() {
    return isCurrentRouteBudgetPage();
  }

  extractCategoryGoalInformation(element) {
    const emberId = element.id;
    const viewData = getEmberView(emberId).category;

    const goalType = viewData.get('subCategory.goalType');
    const monthlyFunding = viewData.get('subCategory.monthlyFunding');
    const targetBalanceDate = viewData.get('monthlySubCategoryBudgetCalculation.goalTarget');

    let monthlyGoalAmount = 0;

    switch (goalType) {
      case 'MF': {
        monthlyGoalAmount = monthlyFunding;
        break;
      }
      case 'TBD': {
        monthlyGoalAmount = targetBalanceDate;
        break;
      }
    }

    return {
      monthlyGoalAmount,
      isChecked: viewData.get('isChecked')
    };
  }

  calculateMonthlyGoals() {
    const categoryGoals = {
      total: 0,
      checkedTotal: 0,
      checkedCount: 0
    };

    $('.budget-table-row.is-sub-category').each((index, element) => {
      const categoryGoal = this.extractCategoryGoalInformation(element);

      categoryGoals.total += categoryGoal.monthlyGoalAmount;
      if (categoryGoal.isChecked) {
        categoryGoals.checkedTotal += categoryGoal.monthlyGoalAmount;
        categoryGoals.checkedCount++;<commit_msg>Call parseInt on goal amounts when calculation monthly goals total (#1447)<commit_after>import { Feature } from 'toolkit/extension/features/feature';
import { getEmberView } from 'toolkit/extension/utils/ember';
import { formatCurrency } from 'toolkit/extension/utils/currency';
import { isCurrentRouteBudgetPage } from 'toolkit/extension/utils/ynab';

export class DisplayTotalMonthlyGoals extends Feature {
  shouldInvoke() {
    return isCurrentRouteBudgetPage();
  }

  extractCategoryGoalInformation(element) {
    const emberId = element.id;
    const viewData = getEmberView(emberId).category;

    const goalType = viewData.get('subCategory.goalType');
    const monthlyFunding = viewData.get('subCategory.monthlyFunding');
    const targetBalanceDate = viewData.get('monthlySubCategoryBudgetCalculation.goalTarget');

    let monthlyGoalAmount = 0;

    switch (goalType) {
      case 'MF': {
        monthlyGoalAmount = monthlyFunding;
        break;
      }
      case 'TBD': {
        monthlyGoalAmount = targetBalanceDate;
        break;
      }
    }

    // if the user edits a goal amount, it's turned into a string on the `subCategory`
    // object. just convert everything into a number just in case.
    return {
      monthlyGoalAmount: parseInt(monthlyGoalAmount, 10),
      isChecked: viewData.get('isChecked')
    };
  }

  calculateMonthlyGoals() {
    const categoryGoals = {
      total: 0,
      checkedTotal: 0,
      checkedCount: 0
    };

    $('.budget-table-row.is-sub-category').each((index, element) => {
      const categoryGoal = this.extractCategoryGoalInformation(element);

      categoryGoals.total += categoryGoal.monthlyGoalAmount;
      if (categoryGoal.isChecked) {
        categoryGoals.checkedTotal += categoryGoal.monthlyGoalAmount;
        categoryGoals.checkedCount++;
{'fraction_non_alphanumeric': 0.10235988200589971, 'fraction_numerical': 0.004129793510324484, 'mean_word_length': 3.521333333333333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5831818', 'n_tokens_mistral': 1019, 'n_tokens_neox': 977, 'n_words': 196}