SearchResultsRow.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 { bool, shape, string } from 'prop-types';
  20. import $ from 'jquery';
  21. import 'jquery.instructure_date_and_time'
  22. import environment from 'jsx/gradebook-history/environment';
  23. import GradeFormatHelper from 'jsx/gradebook/shared/helpers/GradeFormatHelper';
  24. import NumberHelper from 'jsx/shared/helpers/numberHelper';
  25. import I18n from 'i18n!gradebook_history';
  26. import IconOffLine from 'instructure-icons/lib/Line/IconOffLine';
  27. import ScreenReaderContent from 'instructure-ui/lib/components/ScreenReaderContent';
  28. import Tooltip from 'instructure-ui/lib/components/Tooltip';
  29. function anonymouslyGraded (anonymous) {
  30. return anonymous ? (
  31. <div>
  32. <Tooltip tip={I18n.t('Anonymously graded')} on={['focus', 'hover']}>
  33. <span role="presentation" tabIndex="0">
  34. <IconOffLine />
  35. <ScreenReaderContent>{I18n.t('Anonymously graded')}</ScreenReaderContent>
  36. </span>
  37. </Tooltip>
  38. </div>
  39. ) : (
  40. <ScreenReaderContent>{I18n.t('Not anonymously graded')}</ScreenReaderContent>
  41. );
  42. }
  43. function displayGrade (grade, possible, displayAsPoints) {
  44. // show the points possible if the assignment is set to display grades as
  45. // "points" and the grade can be parsed as a number
  46. if (displayAsPoints && NumberHelper.validate(grade)) {
  47. return `${GradeFormatHelper.formatGrade(grade, { defaultValue: '–' })}/${GradeFormatHelper.formatGrade(possible)}`;
  48. }
  49. return GradeFormatHelper.formatGrade(grade, { defaultValue: '–' });
  50. }
  51. function SearchResultsRow (props) {
  52. const item = props.item;
  53. return (
  54. <tr>
  55. <td>{$.datetimeString(new Date(item.date), { format: 'medium', timezone: environment.timezone() })}</td>
  56. <td>{anonymouslyGraded(item.anonymous)}</td>
  57. <td>{item.student || I18n.t('Not available')}</td>
  58. <td>{item.grader || I18n.t('Not available')}</td>
  59. <td>{item.assignment || I18n.t('Not available')}</td>
  60. <td>{displayGrade(item.gradeBefore, item.pointsPossibleBefore, item.displayAsPoints)}</td>
  61. <td>{displayGrade(item.gradeAfter, item.pointsPossibleAfter, item.displayAsPoints)}</td>
  62. <td>{displayGrade(item.gradeCurrent, item.pointsPossibleCurrent, item.displayAsPoints)}</td>
  63. </tr>
  64. );
  65. }
  66. SearchResultsRow.propTypes = {
  67. item: shape({
  68. anonymous: bool.isRequired,
  69. assignment: string.isRequired,
  70. date: string.isRequired,
  71. displayAsPoints: bool.isRequired,
  72. grader: string.isRequired,
  73. gradeAfter: string.isRequired,
  74. gradeBefore: string.isRequired,
  75. gradeCurrent: string.isRequired,
  76. pointsPossibleAfter: string.isRequired,
  77. pointsPossibleBefore: string.isRequired,
  78. pointsPossibleCurrent: string.isRequired,
  79. student: string.isRequired
  80. }).isRequired
  81. };
  82. export default SearchResultsRow;