<commit_before>React = require 'react'
BS = require 'react-bootstrap'

{PinnedHeaderFooterCard} = require 'openstax-react-components'
{ExerciseStore} = require '../../flux/exercise'
Icon = require '../icon'
QuestionsControls = require './questions-controls'
SectionQuestions = require './section-questions'

QuestionsList = React.createClass

  propTypes:
    courseId: React.PropTypes.string.isRequired
    helpTooltip: React.PropTypes.string.isRequired
    sectionIds: React.PropTypes.array

  componentWillMount:   -> ExerciseStore.on('change',  @update)
  componentWillUnmount: -> ExerciseStore.off('change', @update)
  update: -> @forceUpdate()

  renderEmpty: ->
    <div className="no-exercises">
      <h3>No exercises were found for the given sections.</h3>
      <p className="lead">Please select addtional sections and retry</p>
    </div>

  onFilterChange: (filter) ->
    @setState({filter})

  renderQuestionControls: (exercises) ->
    <QuestionsControls
      filter={@state.filter}
      courseId={@props.courseId}
      onFilterChange={@onFilterChange}
      onSectionSelect={@scrollToSection}
      exercises={exercises}
    />

  renderQuestions: (exercises) ->
    chapter_sections = _.keys(exercises.grouped).sort()
    for cs in chapter_sections
      <SectionQuestions key={cs} {...@props}
        chapter_section={cs} exercises={exercises.grouped[cs]} />

  render: ->
    return null if ExerciseStore.isLoading() or _.isEmpty(@props.sectionIds)

    exercises = ExerciseStore.groupBySectionsAndTypes(@props.sectionIds)
    selectedExercises = if @state.filter then exercises[@state.filter] else exercises.all
    questions = if selectedExercises.count
      @renderQuestions(selectedExercises)
    else
      @renderEmpty()

    <div className="questions-list">
      <div className="instructions">
        <div className="wrapper">
          Click each question that you would like to exclude from
          all aspects of your students’ Tutor experience.
          <Icon type='question-circle' tooltip={@props.helpTooltip} />
        </div>
      </div>

      <PinnedHeaderFooterCard
        containerBuffer={50}
        header={@renderQuestionControls(exercises)}
        cardType='sections-questions'
      >

      {questions}

      </PinnedHeaderFooterCard>
    </div>


module.exports = QuestionsList<commit_msg>Default filter to reading<commit_after>React = require 'react'
BS = require 'react-bootstrap'

{PinnedHeaderFooterCard} = require 'openstax-react-components'
{ExerciseStore} = require '../../flux/exercise'
Icon = require '../icon'
QuestionsControls = require './questions-controls'
SectionQuestions = require './section-questions'

QuestionsList = React.createClass

  propTypes:
    courseId: React.PropTypes.string.isRequired
    helpTooltip: React.PropTypes.string.isRequired
    sectionIds: React.PropTypes.array
  getInitialState: -> {
    filter: 'reading'
  }
  componentWillMount:   -> ExerciseStore.on('change',  @update)
  componentWillUnmount: -> ExerciseStore.off('change', @update)
  update: -> @forceUpdate()

  renderEmpty: ->
    <div className="no-exercises">
      <h3>No exercises were found for the given sections.</h3>
      <p className="lead">Please select addtional sections and retry</p>
    </div>

  onFilterChange: (filter) ->
    @setState({filter})

  renderQuestionControls: (exercises) ->
    <QuestionsControls
      filter={@state.filter}
      courseId={@props.courseId}
      onFilterChange={@onFilterChange}
      onSectionSelect={@scrollToSection}
      exercises={exercises}
    />

  renderQuestions: (exercises) ->
    chapter_sections = _.keys(exercises.grouped).sort()
    for cs in chapter_sections
      <SectionQuestions key={cs} {...@props}
        chapter_section={cs} exercises={exercises.grouped[cs]} />

  render: ->
    return null if ExerciseStore.isLoading() or _.isEmpty(@props.sectionIds)

    exercises = ExerciseStore.groupBySectionsAndTypes(@props.sectionIds)
    selectedExercises = if @state.filter then exercises[@state.filter] else exercises.all
    questions = if selectedExercises.count
      @renderQuestions(selectedExercises)
    else
      @renderEmpty()

    <div className="questions-list">
      <div className="instructions">
        <div className="wrapper">
          Click each question that you would like to exclude from
          all aspects of your students’ Tutor experience.
          <Icon type='info-circle' tooltip={@props.helpTooltip} />
        </div>
      </div>

      <PinnedHeaderFooterCard
        containerBuffer={50}
        header={@renderQuestionControls(exercises)}
        cardType='sections-questions'
      >

      {questions}

      </PinnedHeaderFooterCard>
    </div>


module.exports = QuestionsList
{'fraction_non_alphanumeric': 0.11950347149168945, 'fraction_numerical': 0.001683147485798443, 'mean_word_length': 3.5190114068441063, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 54, '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': '5207318', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1337, 'n_words': 285}