SubmissionStatus.js 4.3 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 { bool, shape } from 'prop-types';
  20. import I18n from 'i18n!gradebook';
  21. import Container from 'instructure-ui/lib/components/Container';
  22. import Pill from 'instructure-ui/lib/components/Pill';
  23. import Typography from 'instructure-ui/lib/components/Typography';
  24. import IconWarningLine from 'instructure-icons/lib/Line/IconWarningLine';
  25. function renderWarning (message) {
  26. return (
  27. <div style={{display: 'flex', alignItems: 'flex-start'}}>
  28. <Container as="span" padding="xx-small 0 0 0">
  29. <Typography color="error">
  30. <IconWarningLine title={message} />
  31. </Typography>
  32. </Container>
  33. <Container as="span" padding="0 0 0 x-small">
  34. <Typography size="small">
  35. {message}
  36. </Typography>
  37. </Container>
  38. </div>
  39. );
  40. }
  41. export default class SubmissionStatus extends React.Component {
  42. static defaultProps = {
  43. submission: {
  44. drop: false
  45. }
  46. };
  47. static propTypes = {
  48. assignment: shape({
  49. muted: bool.isRequired,
  50. published: bool.isRequired
  51. }).isRequired,
  52. isInClosedGradingPeriod: bool.isRequired,
  53. isInNoGradingPeriod: bool.isRequired,
  54. isInOtherGradingPeriod: bool.isRequired,
  55. submission: shape({
  56. drop: bool,
  57. excused: bool
  58. }).isRequired
  59. };
  60. getStatusPills () {
  61. const { assignment, submission } = this.props;
  62. const statusPillComponents = [];
  63. if (assignment.muted) {
  64. statusPillComponents.push(
  65. <Pill key="muted-assignment" variant="default" text={I18n.t('Muted')} margin="0 0 x-small" />
  66. );
  67. }
  68. if (!assignment.published) {
  69. statusPillComponents.push(
  70. <Pill key="unpublished-assignment" variant="danger" text={I18n.t('Unpublished')} margin="0 0 x-small" />
  71. );
  72. }
  73. if (submission.drop) {
  74. statusPillComponents.push(
  75. <Pill key="dropped-submission" variant="default" text={I18n.t('Dropped')} margin="0 0 x-small" />
  76. );
  77. }
  78. if (submission.excused) {
  79. statusPillComponents.push(
  80. <Pill key="excused-assignment" variant="default" text={I18n.t('Excused')} margin="0 0 x-small" />
  81. );
  82. }
  83. return statusPillComponents;
  84. }
  85. getStatusNotifications () {
  86. const statusNotificationComponents = [];
  87. const statusNotificationContainerStyle = {
  88. display: 'flex'
  89. };
  90. const gradingPeriodStatusMessage = this.gradingPeriodStatusMessage();
  91. if (gradingPeriodStatusMessage) {
  92. statusNotificationComponents.push(
  93. <div key="grading-period-status" style={statusNotificationContainerStyle}>
  94. {renderWarning(gradingPeriodStatusMessage)}
  95. </div>
  96. );
  97. }
  98. return statusNotificationComponents;
  99. }
  100. gradingPeriodStatusMessage () {
  101. const { isInOtherGradingPeriod, isInClosedGradingPeriod, isInNoGradingPeriod } = this.props;
  102. let message;
  103. if (isInOtherGradingPeriod) {
  104. message = I18n.t('This submission is in another grading period.');
  105. } else if (isInClosedGradingPeriod) {
  106. message = I18n.t('This submission is in a closed grading period.');
  107. } else if (isInNoGradingPeriod) {
  108. message = I18n.t('This submission is not in any grading period.');
  109. }
  110. return message;
  111. }
  112. render () {
  113. const statusPillComponents = this.getStatusPills();
  114. const statusNotificationComponents = this.getStatusNotifications();
  115. const statusContainerStyle = {
  116. display: 'flex',
  117. justifyContent: 'left'
  118. };
  119. return (
  120. <Container as="div" padding="0 0 small 0">
  121. <div key="status-icons" style={statusContainerStyle}>
  122. {statusPillComponents}
  123. </div>
  124. {statusNotificationComponents}
  125. </Container>
  126. );
  127. }
  128. };