<commit_before>import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { fetch_credits } from './../actions/creditsActions'
import { useTranslation } from 'react-i18next';

import Table from '@material-ui/core/Table'
import TableBody from '@material-ui/core/TableBody'
import TableCell from '@material-ui/core/TableCell'
import TableHead from '@material-ui/core/TableHead'
import TableRow from '@material-ui/core/TableRow'
import { withStyles } from '@material-ui/core/styles'

const styles = theme => ({
  tableHeader: {
    color: 'rgba(0, 0, 0, 1)',
    fontWeight: 600,
    fontSize: 14
  },
  cell: {
    color: 'rgba(0, 0, 0, 0.87)',
    fontWeight: 'bolder'
  }
})

class AdvisingGrades extends React.Component {
  state = {
    creditsObj: null
  }

  componentDidMount() {
    // eslint-disable-next-line
    this.props.fetch_credits
  }

  getRows = creditsObj => {
    let rows = []
    let i = 0
    for (let cr of creditsObj) {
      rows.push(
        <TableRow key={i}>
          <TableCell>{cr.level}</TableCell>
          <TableCell>{cr.credits}</TableCell>
          <TableCell>{cr.gpa}</TableCell>
        </TableRow>
      )
      i++
    }
    return rows
  }

  render() {
    //const { creditsObj } = this.state
    const { t } = useTranslation();
    const { classes, credits, credits_fetched } = this.props
    if (credits_fetched === true) {
      return (
        <Table>
          <TableHead>
            <TableRow className={classes.tableHeader}>
              <TableCell classes={{ head: classes.cell }} scope="col">
                {t('level')}
              </TableCell>
              <TableCell classes={{ head: classes.cell }} scope="col">
                {t('credits')}
              </TableCell>
              <TableCell classes={{ head: classes.cell }} scope="col">
                GPA
              </TableCell>
            </TableRow>
          </TableHead>
          <TableBody>{this.getRows(credits)}</TableBody>
        </Table>
      )
    } else {
      return <div />
    }
  }
}

AdvisingGrades.propTypes = {
  classes: PropTypes.object.isRequired
}

const mapStateToProps = state => ({
  credits: state.credits.credits,
  credits_fetched: state.credits.fetched
})

const mapDispatchToProps = dispatch => {
  return {
    fetch_credits: dispatch(fetch_credits())
  }
}

export default withStyles(styles, { name: 'AdvisingGrades' })(
  connect(mapStateToProps, mapDispatchToProps)(AdvisingGrades)
)<commit_msg>Migrate AdvisingGrades to function and redux hooks<commit_after>import React, { useState, useEffect } from 'react'
import PropTypes from 'prop-types'
import { useDispatch, useSelector } from 'react-redux'
import { fetch_credits } from './../actions/creditsActions'
import { useTranslation } from 'react-i18next';

import Table from '@material-ui/core/Table'
import TableBody from '@material-ui/core/TableBody'
import TableCell from '@material-ui/core/TableCell'
import TableHead from '@material-ui/core/TableHead'
import TableRow from '@material-ui/core/TableRow'
import { makeStyles } from '@material-ui/styles'

const useStyles = makeStyles(theme => ({
  tableHeader: {
    color: 'rgba(0, 0, 0, 1)',
    fontWeight: 600,
    fontSize: 14
  },
  cell: {
    color: 'rgba(0, 0, 0, 0.87)',
    fontWeight: 'bolder'
  }
}))

export default function AdvisingGrades() {
  const classes = useStyles()
  const { t } = useTranslation()
  const credits = useSelector(state => state.credits.credits)
  const credits_fetched = useSelector(state => state.credits.credits_fetched)
  const dispatch = useDispatch()

  useEffect(() => {
    dispatch(fetch_credits())
  }, [dispatch])

  function getRows() {
    if (credits !== null) {
      let rows = []
      let i = 0
      console.log(credits)
      for (let cr of credits) {
        rows.push(
          <TableRow key={i}>
            <TableCell>{cr.level}</TableCell>
            <TableCell>{cr.credits}</TableCell>
            <TableCell>{cr.gpa}</TableCell>
          </TableRow>
        )
        i++
      }
      return rows
    }
  }

  return (
    <Table>
      <TableHead>
        <TableRow className={classes.tableHeader}>
          <TableCell classes={{ head: classes.cell }} scope="col">
            {t('level')}
          </TableCell>
          <TableCell classes={{ head: classes.cell }} scope="col">
            {t('credits')}
          </TableCell>
          <TableCell classes={{ head: classes.cell }} scope="col">
            GPA
            </TableCell>
        </TableRow>
      </TableHead>
      <TableBody>{getRows()}</TableBody>
    </Table>
  )
}
{'fraction_non_alphanumeric': 0.13982683982683983, 'fraction_numerical': 0.007792207792207792, 'mean_word_length': 2.571097372488408, 'pattern_counts': {'":': 0, '<': 48, '<?xml version=': 0, '>': 56, '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': '3496325', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1440, 'n_words': 322}