<commit_before>import React from 'react';
import "babel-polyfill";
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import * as actionCreators from '../../actions/transactions';
import AddTransaction from '../Modals/AddTransaction.js'
import EditTransaction from '../Modals/EditTransaction.js'
import TextField from 'material-ui/TextField';
import Toggle from 'material-ui/Toggle';

import {
  Table,
  TableBody,
  TableFooter,
  TableHeader,
  TableHeaderColumn,
  TableRow,
  TableRowColumn,
} from 'material-ui/Table';

import styles from './styles.scss';


function mapStateToProps(state) {
  return {
    data: state.transactions.data,
    token: state.auth.token,
    loaded: state.transactions.loaded,
    isFetching: state.transactions.isFetching,
    selectedAccount: state.accounts.selectedAccount,
  };
}

function mapDispatchToProps(dispatch) {
  return bindActionCreators(actionCreators, dispatch);
}


@connect(mapStateToProps, mapDispatchToProps)
export default class TransactionsList extends React.Component {
  state = {
    fixedHeader: true,
    fixedFooter: true,
    stripedRows: true,
    showRowHover: false,
    selectable: false,
    multiSelectable: false,
    enableSelectAll: false,
    deselectOnClickaway: false,
    showCheckboxes: false,
    height: '400px',
  };

  fetchData(account_id=null) {
    if (account_id === null) {
      account_id = this.props.selectedAccount
    }
    if (account_id !== null)
    {
      const token = this.props.token
      this.props.fetchTransactionsData(token, account_id)
    }
  }

  componentWillReceiveProps(nextProps) {
    if (nextProps.selectedAccount !== this.props.selectedAccount) {
      this.fetchData(nextProps.selectedAccount)
    }
  }

  componentDidUpdate(prevProps, prevState) {
    this.scrollToBottom()
  }

  handleToggle = (event, toggled) => {
    this.setState({
      [event.target.name]: toggled,
    });
  };

  handleChange = (event) => {
    this.setState({height: event.target.value});
  };

  scrollToBottom() {
    if (this.refs.table !== undefined) {
      this.refs.table.refs.tableDiv.scrollTop = this.refs.table.refs.tableDiv.scrollHeight
    }
  }

  createTransaction( transaction ) {
    const token = this.props.token;
    let call = async () =>
      await (await this.props.createTransaction(token, transaction));
    call()
      .then(() => {
        this.fetchData();
        this.props.updateBalance();
      })
  }

  editTransaction( transaction ) {
    const token = this.props.token;
    let call = async () =>
      await (await this.props.editTransaction(token, transaction));
    call()
      .then(() => {
        this.fetchData();
        this.props.updateBalance();
      })
  }

  deleteTransaction( id ) {
    const token = this.props.token;
    let call = async () =>
      await (await this.props.deleteTransaction(token, id));
    call()
      .then(() => {
        this.fetchData();
        this.props.updateBalance();
      })
  }

  renderTransactionsList( transactions ) {
    transactions.sort((a,b) => {
      return new Date(a.date) - new Date(b.date);
    });
    const rows = transactions.map((row, index) => {
      let credit = parseFloat(row.amount) < 0 ? '' : Number(row.amount).toFixed(2)
      let debit = parseFloat(row.amount) < 0 ? Number(row.amount).toFixed(2) : ''
      return (
        <TableRow key={index}>
          <TableHeaderColumn className={styles.smallColumn}>{row.date.toString()}</TableHeaderColumn>
          <TableHeaderColumn>{row.label}</TableHeaderColumn>
          <TableHeaderColumn className={styles.smallColumn}>{debit}</TableHeaderColumn>
          <TableHeaderColumn className={styles.smallColumn}>{credit}</TableHeaderColumn>
          <TableHeaderColumn className={styles.smallColumn}>
            <EditTransaction
              fields={row}
              editTransaction={this.editTransaction.bind(this)}
              deleteTransaction={this.deleteTransaction.bind(this)}
            />
          </TableHeaderColumn>
        </TableRow>
      )
    })
    return rows
  }

  render() {
    if (this.props.selectedAccount === undefined || this.props.selectedAccount === null) {
      return (
        <div className={styles.mainContainer}><commit_msg>Filter future recurring transactions<commit_after>import React from 'react';
import "babel-polyfill";
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import * as actionCreators from '../../actions/transactions';
import AddTransaction from '../Modals/AddTransaction.js'
import EditTransaction from '../Modals/EditTransaction.js'
import TextField from 'material-ui/TextField';
import Toggle from 'material-ui/Toggle';

import {
  Table,
  TableBody,
  TableFooter,
  TableHeader,
  TableHeaderColumn,
  TableRow,
  TableRowColumn,
} from 'material-ui/Table';

import styles from './styles.scss';


function mapStateToProps(state) {
  return {
    data: state.transactions.data,
    token: state.auth.token,
    loaded: state.transactions.loaded,
    isFetching: state.transactions.isFetching,
    selectedAccount: state.accounts.selectedAccount,
  };
}

function mapDispatchToProps(dispatch) {
  return bindActionCreators(actionCreators, dispatch);
}


@connect(mapStateToProps, mapDispatchToProps)
export default class TransactionsList extends React.Component {
  state = {
    fixedHeader: true,
    fixedFooter: true,
    stripedRows: true,
    showRowHover: false,
    selectable: false,
    multiSelectable: false,
    enableSelectAll: false,
    deselectOnClickaway: false,
    showCheckboxes: false,
    height: '400px',
  };

  fetchData(account_id=null) {
    if (account_id === null) {
      account_id = this.props.selectedAccount
    }
    if (account_id !== null)
    {
      const token = this.props.token
      this.props.fetchTransactionsData(token, account_id)
    }
  }

  componentWillReceiveProps(nextProps) {
    if (nextProps.selectedAccount !== this.props.selectedAccount) {
      this.fetchData(nextProps.selectedAccount)
    }
  }

  componentDidUpdate(prevProps, prevState) {
    this.scrollToBottom()
  }

  handleToggle = (event, toggled) => {
    this.setState({
      [event.target.name]: toggled,
    });
  };

  handleChange = (event) => {
    this.setState({height: event.target.value});
  };

  scrollToBottom() {
    if (this.refs.table !== undefined) {
      this.refs.table.refs.tableDiv.scrollTop = this.refs.table.refs.tableDiv.scrollHeight
    }
  }

  createTransaction( transaction ) {
    const token = this.props.token;
    let call = async () =>
      await (await this.props.createTransaction(token, transaction));
    call()
      .then(() => {
        this.fetchData();
        this.props.updateBalance();
      })
  }

  editTransaction( transaction ) {
    const token = this.props.token;
    let call = async () =>
      await (await this.props.editTransaction(token, transaction));
    call()
      .then(() => {
        this.fetchData();
        this.props.updateBalance();
      })
  }

  deleteTransaction( id ) {
    const token = this.props.token;
    let call = async () =>
      await (await this.props.deleteTransaction(token, id));
    call()
      .then(() => {
        this.fetchData();
        this.props.updateBalance();
      })
  }

  renderTransactionsList( transactions ) {
    transactions.sort((a,b) => {
      return new Date(a.date) - new Date(b.date);
    });
    // filter future recurring transactions
    transactions = transactions.filter((element) => {
      return element.recurring_group_id === null
      || (element.recurring_group_id !== null && new Date(element.date) <= new Date)
    })
    const rows = transactions.map((row, index) => {
      let credit = parseFloat(row.amount) < 0 ? '' : Number(row.amount).toFixed(2)
      let debit = parseFloat(row.amount) < 0 ? Number(row.amount).toFixed(2) : ''
      return (
        <TableRow key={index}>
          <TableHeaderColumn className={styles.smallColumn}>{row.date.toString()}</TableHeaderColumn>
          <TableHeaderColumn>{row.label}</TableHeaderColumn>
          <TableHeaderColumn className={styles.smallColumn}>{debit}</TableHeaderColumn>
          <TableHeaderColumn className={styles.smallColumn}>{credit}</TableHeaderColumn>
          <TableHeaderColumn className={styles.smallColumn}>
            <EditTransaction
              fields={row}
              editTransaction={this.editTransaction.bind(this)}
              deleteTransaction={this.deleteTransaction.bind(this)}
            />
          </TableHeaderColumn>
        </TableRow>
      )
    })
    return rows
  }

  render() {
    if (this.props.selectedAccount === undefined || this.props.selectedAccount === null) {
      return (
        <div className={styles.mainContainer}>
{'fraction_non_alphanumeric': 0.1302913063268093, 'fraction_numerical': 0.0015930814747382794, 'mean_word_length': 3.0784222737819027, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 52, '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': '246657', 'n_tokens_mistral': 2587, 'n_tokens_neox': 2571, 'n_words': 483}