GradebookMenu.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Copyright (C) 2017 - 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 IconMiniArrowDownSolid from 'instructure-icons/lib/Solid/IconMiniArrowDownSolid'
  21. import Button from 'instructure-ui/lib/components/Button'
  22. import { MenuItem, MenuItemSeparator } from 'instructure-ui/lib/components/Menu'
  23. import PopoverMenu from 'instructure-ui/lib/components/PopoverMenu'
  24. import Typography from 'instructure-ui/lib/components/Typography'
  25. import I18n from 'i18n!gradebook'
  26. const { oneOf, bool, string, func } = PropTypes;
  27. class GradebookMenu extends React.Component {
  28. static propTypes = {
  29. courseUrl: string.isRequired,
  30. learningMasteryEnabled: bool.isRequired,
  31. navigate: func.isRequired,
  32. variant: oneOf(['DefaultGradebook', 'DefaultGradebookLearningMastery']).isRequired
  33. };
  34. static menuItemsForGradebook = {
  35. DefaultGradebook: ['LearningMastery', 'IndividualGradebook', 'Separator', 'GradebookHistory'],
  36. DefaultGradebookLearningMastery: ['DefaultGradebook', 'IndividualGradebook', 'Separator', 'GradebookHistory'],
  37. };
  38. constructor (props) {
  39. super(props);
  40. this.handleDefaultGradebookSelect = this.handleDefaultGradebookSelect.bind(this);
  41. this.handleIndividualGradebookSelect = this.handleIndividualGradebookSelect.bind(this);
  42. this.handleGradebookHistorySelect = this.handleGradebookHistorySelect.bind(this);
  43. this.handleLearningMasterySelect = this.handleLearningMasterySelect.bind(this);
  44. }
  45. setLocation (url) {
  46. window.location = url;
  47. }
  48. handleDefaultGradebookSelect () {
  49. this.props.navigate('tab-assignment', { trigger: true });
  50. }
  51. handleLearningMasterySelect () {
  52. this.props.navigate('tab-outcome', { trigger: true });
  53. }
  54. handleIndividualGradebookSelect () {
  55. this.setLocation(`${this.props.courseUrl}/gradebook/change_gradebook_version?version=individual`);
  56. }
  57. handleGradebookHistorySelect () {
  58. this.setLocation(`${this.props.courseUrl}/gradebook/history`);
  59. }
  60. renderDefaultGradebookMenuItem () {
  61. const key = 'default-gradebook';
  62. return (
  63. <MenuItem onSelect={this.handleDefaultGradebookSelect} key={key}>
  64. <span data-menu-item-id={key}>
  65. {I18n.t('Gradebook…')}
  66. </span>
  67. </MenuItem>
  68. );
  69. }
  70. renderIndividualGradebookMenuItem () {
  71. const key = 'individual-gradebook';
  72. return (
  73. <MenuItem onSelect={this.handleIndividualGradebookSelect} key={key}>
  74. <span data-menu-item-id={key}>
  75. {I18n.t('Individual View…')}
  76. </span>
  77. </MenuItem>
  78. );
  79. }
  80. renderGradebookHistoryMenuItem () {
  81. const key = 'gradebook-history';
  82. return (
  83. <MenuItem onSelect={this.handleGradebookHistorySelect} key={key}>
  84. <span data-menu-item-id={key}>
  85. {I18n.t('Gradebook History…')}
  86. </span>
  87. </MenuItem>
  88. );
  89. }
  90. renderLearningMasteryMenuItem () {
  91. if (!this.props.learningMasteryEnabled) return null;
  92. const key = 'learning-mastery';
  93. return (
  94. <MenuItem onSelect={this.handleLearningMasterySelect} key={key}>
  95. <span data-menu-item-id={key}>
  96. {I18n.t('Learning Mastery…')}
  97. </span>
  98. </MenuItem>
  99. );
  100. }
  101. renderSeparatorMenuItem () {
  102. return <MenuItemSeparator key="separator" />;
  103. }
  104. renderMenuItems () {
  105. const menuItems = GradebookMenu.menuItemsForGradebook[this.props.variant];
  106. return menuItems.map(menuItem => this[`render${menuItem}MenuItem`]());
  107. }
  108. renderButton () {
  109. let label = I18n.t('Gradebook');
  110. if (this.props.variant === 'DefaultGradebookLearningMastery') label = I18n.t('Learning Mastery');
  111. return (
  112. <Button variant="link">
  113. <Typography color="primary">
  114. {label} <IconMiniArrowDownSolid />
  115. </Typography>
  116. </Button>
  117. );
  118. }
  119. render () {
  120. return (
  121. <PopoverMenu trigger={this.renderButton()}>
  122. {this.renderMenuItems()}
  123. </PopoverMenu>
  124. );
  125. }
  126. }
  127. export default GradebookMenu;