<commit_before>import React, { Component } from 'react'
import pureRender from 'pure-render-decorator'
import Answer from './answer'
import { CompareAnswerCheckboxContainer } from '../containers/compare-answer'
import ShowCompareContainer from '../containers/show-compare'
import { connect } from 'react-redux'

import '../../css/answers-table.less'

@pureRender
class AnswersTable extends Component {

  getLatestFeedback(answer) {
    const feedbackKey = answer.get('feedbacks').last()
    return this.props.feedbacks.get(feedbackKey)
  }

  render() {
    const {question, answers, hidden} = this.props
    const getLatestFeedback = this.getLatestFeedback.bind(this)

    const scoreEnabled = question.get("scoreEnabled")
    const feedbackEnabled = question.get("feedbackEnabled")

    const feedbackTH = feedbackEnabled ?  <th>Feedback</th> : ""
    const scoreTH = scoreEnabled ?  <th>Score</th> : ""
    return (
      <table className={`answers-table ${hidden ? 'hidden' : ''}`}>
        <tbody>
          <tr>
            <th className='student-header'>Student</th>
            <th>Response</th>
            {feedbackTH}
            {scoreTH}
            <th className='select-header'>Select</th>
          </tr>
          {answers.map(function(answer) {
              const feedback = getLatestFeedback(answer)
              return (<AnswerRow
                key={answer.get('studentId')}
                answer={answer}
                feedback={feedback}
                showFeedback={feedbackEnabled}
                showScore={scoreEnabled}
              />)
            }
          )}
        </tbody>
      </table>
    )
  }
}

function AnswerRow ({answer, feedback, showScore, showFeedback}) {
  const hasAnswer =  answer.get("type") !== "NoAnswer"
  const score = feedback && feedback.get("score")
  const textFeedback = feedback && feedback.get("feedback")
  const scoreTD = showScore ? <td className="score">{score}</td> : ""
  const feedbackTD = showFeedback ? <td className="feedback">{textFeedback}</td> : ""
  const compareDIV =  hasAnswer ?
    <div>
      <CompareAnswerCheckboxContainer answer={answer}/>
      <ShowCompareContainer answer={answer}/>
    </div>
    : ""

   return (
      <tr>
        <td>{answer.getIn(["student", "name"])}</td>
        <td> <Answer answer={answer}/> </td>
        {feedbackTD}
        {scoreTD}
        <td className="select-answer-column">
          {compareDIV}
        </td>
      </tr>
    )
}


function mapStateToProps(state) {
  return { feedbacks: state.getIn(["report","feedbacks"]) }
}

const mapDispatchToProps = (dispatch, ownProps) => {
  return {}
}

export default connect(mapStateToProps, mapDispatchToProps)(AnswersTable)<commit_msg>In teacher report: If "Hide Names" is selected don't show feedback.<commit_after>import React, { Component } from 'react'
import pureRender from 'pure-render-decorator'
import Answer from './answer'
import { CompareAnswerCheckboxContainer } from '../containers/compare-answer'
import ShowCompareContainer from '../containers/show-compare'
import { connect } from 'react-redux'

import '../../css/answers-table.less'

@pureRender
class AnswersTable extends Component {

  getLatestFeedback(answer) {
    const feedbackKey = answer.get('feedbacks').last()
    return this.props.feedbacks.get(feedbackKey)
  }

  render() {
    const {question, answers, hidden} = this.props
    const getLatestFeedback = this.getLatestFeedback.bind(this)
    const anonymous = this.props.anonymous
    const scoreEnabled = (!anonymous) && question.get("scoreEnabled")
    const feedbackEnabled = (!anonymous) && question.get("feedbackEnabled")

    const feedbackTH = feedbackEnabled ?  <th>Feedback</th> : null
    const scoreTH = scoreEnabled ?  <th>Score</th> : null
    return (
      <table className={`answers-table ${hidden ? 'hidden' : ''}`}>
        <tbody>
          <tr>
            <th className='student-header'>Student</th>
            <th>Response</th>
            {feedbackTH}
            {scoreTH}
            <th className='select-header'>Select</th>
          </tr>
          {answers.map(function(answer) {
              const feedback = getLatestFeedback(answer)
              return (<AnswerRow
                key={answer.get('studentId')}
                answer={answer}
                feedback={feedback}
                showFeedback={feedbackEnabled}
                showScore={scoreEnabled}
              />)
            }
          )}
        </tbody>
      </table>
    )
  }
}

function AnswerRow ({answer, feedback, showScore, showFeedback}) {
  const hasAnswer =  answer.get("type") !== "NoAnswer"
  const score = feedback && feedback.get("score")
  const textFeedback = feedback && feedback.get("feedback")
  const scoreTD = showScore ? <td className="score">{score}</td> : null
  const feedbackTD = showFeedback ? <td className="feedback">{textFeedback}</td> : null
  const compareDIV =  hasAnswer ?
    <div>
      <CompareAnswerCheckboxContainer answer={answer}/>
      <ShowCompareContainer answer={answer}/>
    </div>
    : ""

   return (
      <tr>
        <td>{answer.getIn(["student", "name"])}</td>
        <td> <Answer answer={answer}/> </td>
        {feedbackTD}
        {scoreTD}
        <td className="select-answer-column">
          {compareDIV}
        </td>
      </tr>
    )
}


function mapStateToProps(state) {
  return {
    feedbacks: state.getIn(["report","feedbacks"]),
    anonymous: state.getIn(["report","anonymous"])
  }
}

const mapDispatchToProps = (dispatch, ownProps) => {
  return {}
}

export default connect(mapStateToProps, mapDispatchToProps)(AnswersTable)
{'fraction_non_alphanumeric': 0.14006398862424457, 'fraction_numerical': 0.0, 'mean_word_length': 2.7663989290495317, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 73, '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': '4913910', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1597, 'n_words': 330}