EnrollmentTermsDropdown.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (C) 2016 - present Instructure, Inc.
  3. *
  4. * This file is part of Canvas.
  5. *
  6. * Canvas is free software: you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero General Public License as published by the Free
  8. * Software Foundation, version 3 of the License.
  9. *
  10. * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
  11. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. * details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. import React from 'react'
  19. import PropTypes from 'prop-types'
  20. import _ from 'underscore'
  21. import I18n from 'i18n!grading_periods'
  22. let EnrollmentTermsDropdown = React.createClass({
  23. propTypes: {
  24. terms: PropTypes.array.isRequired,
  25. changeSelectedEnrollmentTerm: PropTypes.func.isRequired
  26. },
  27. sortedTerms(terms) {
  28. const dated = _.select(terms, term => term.startAt);
  29. const datedTermsSortedByStart = _.sortBy(dated, term => term.startAt).reverse();
  30. const undated = _.select(terms, term => !term.startAt);
  31. const undatedTermsSortedByCreate = _.sortBy(undated, term => term.createdAt).reverse();
  32. return datedTermsSortedByStart.concat(undatedTermsSortedByCreate);
  33. },
  34. termOptions(terms) {
  35. const allTermsOption = (<option key={0} value={0}>{I18n.t("All Terms")}</option>);
  36. let options = _.map(this.sortedTerms(terms), function(term) {
  37. return (<option key={term.id} value={term.id}>{term.displayName}</option>);
  38. });
  39. options.unshift(allTermsOption);
  40. return options;
  41. },
  42. render() {
  43. return (
  44. <select
  45. className="EnrollmentTerms__dropdown ic-Input"
  46. name="enrollment_term"
  47. data-view="termSelect"
  48. aria-label="Enrollment Term"
  49. ref="termsDropdown"
  50. onChange={this.props.changeSelectedEnrollmentTerm} >
  51. {this.termOptions(this.props.terms)}
  52. </select>
  53. );
  54. }
  55. });
  56. export default EnrollmentTermsDropdown