content: import React from 'react'
  import { connect } from 'react-redux'
  import _ from 'lodash'
  
  import Instance from './Instance'
  
  export default connect(mapStateToProps)(({
    adjudicatorTestScores,
    adjudicators,
    institutionsById
  }) => {
    let sortedAdjudicators = _.cloneDeep(adjudicators)
  
    sortedAdjudicators.sort((a, b) => {
      if (institutionsById[a.institution] && institutionsById[b.institution]) {
        if (institutionsById[a.institution].name < institutionsById[b.institution].name) return -1
        if (institutionsById[a.institution].name > institutionsById[b.institution].name) return 1
      }
  
      if (a.firstName < b.firstName) return -1
      if (a.firstName > b.firstName) return 1
      return 0
    })
  
    return (
      <div>
        {sortedAdjudicators.map(adjudicator =>
          <Instance
            key={adjudicator._id}
            adjudicator={adjudicator}
          />
        )}
      </div>
    )
  })
  
  function mapStateToProps (state, ownProps) {
    return {
      adjudicators: Object.values(state.adjudicators.data),
      adjudicatorTestScores: Object.values(state.adjudicatorTestScores.data),
      institutionsById: state.institutions.data
    }
  }
  