UNPKG

@instructure/quiz-grading

Version:

The Quiz React SDK by Instructure Inc.

393 lines (392 loc) • 16.3 kB
/** @jsx jsx */ function _assert_this_initialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _call_super(_this, derived, args) { derived = _get_prototype_of(derived); return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args)); } function _class_call_check(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for(var i = 0; i < props.length; i++){ var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _create_class(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _define_property(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _get_prototype_of(o) { _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _get_prototype_of(o); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _set_prototype_of(subClass, superClass); } function _object_spread(target) { for(var i = 1; i < arguments.length; i++){ var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === "function") { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function(key) { _define_property(target, key, source[key]); }); } return target; } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function(sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } function _object_spread_props(target, source) { source = source != null ? source : {}; if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function(key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } function _possible_constructor_return(self, call) { if (call && (_type_of(call) === "object" || typeof call === "function")) { return call; } return _assert_this_initialized(self); } function _set_prototype_of(o, p) { _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _set_prototype_of(o, p); } function _type_of(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; } function _is_native_reflect_construct() { try { var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {})); } catch (_) {} return (_is_native_reflect_construct = function() { return !!result; })(); } import { Component } from 'react'; import PropTypes from 'prop-types'; import { Alert } from '@instructure/ui-alerts'; import { Button, CloseButton } from '@instructure/ui-buttons'; import { Text } from '@instructure/ui-text'; import { Heading } from '@instructure/ui-heading'; import { RadioInput, RadioInputGroup } from '@instructure/ui-radio-input'; import { jsx, InstUISettingsProvider } from '@instructure/emotion'; import { Modal, ModalHeader, ModalBody, ModalFooter } from '@instructure/quiz-common/components/Modal/index'; import { XSMALL_SIDE_MARGIN } from '@instructure/quiz-common/constants'; import { withStyleOverrides } from '@instructure/quiz-common/util/withStyleOverrides'; import generateStyle from './styles'; import generateComponentTheme from './theme'; import t from '@instructure/quiz-i18n/format-message'; var BaseRegradingModal = /*#__PURE__*/ function(Component) { "use strict"; _inherits(BaseRegradingModal, Component); function BaseRegradingModal() { _class_call_check(this, BaseRegradingModal); var _this; _this = _call_super(this, BaseRegradingModal, arguments), _define_property(_this, "state", { hasGenericErrorFromApi: false }), // Handlers _define_property(_this, "clearGenericErrorFromApi", function() { _this.setState({ hasGenericErrorFromApi: false }); }), _define_property(_this, "cancelAction", function() { _this.clearGenericErrorFromApi(); _this.props.closeModal(); }), _define_property(_this, "onSpeedgraderOptionChange", function(event, newValue) { _this.props.setScoreReconciliation(newValue); }), _define_property(_this, "onSubmit", function() { var _this_props = _this.props, createQuizEntryRegrade = _this_props.createQuizEntryRegrade, quizId = _this_props.quizId, regradingPayload = _this_props.regradingPayload, scoreReconciliation = _this_props.scoreReconciliation; _this.clearGenericErrorFromApi(); createQuizEntryRegrade(quizId, _object_spread_props(_object_spread({}, regradingPayload), { scoreReconciliation: scoreReconciliation })).then(function() { _this.props.toggleRegradingEditMode(''); _this.props.addSuccess(t('Regrade scheduled successfully; check back later to see it applied.')); }).catch(function(e) { if (e.validationErrorsFromApi) { // Close the modal so the user can view the input validation errors and correct them _this.cancelAction(); _this.props.handleValidationErrorsFromApi(e.validationErrorsFromApi); } else { // Some other type of error occurred _this.setState({ hasGenericErrorFromApi: true }); } throw e; }); }); return _this; } _create_class(BaseRegradingModal, [ { key: "optionInputs", get: // Getters function get() { return { new_score: { hint: t('some scores may be reduced, some may be raised'), text: t('award points for correct answer only') }, old_score: { hint: t('no scores will be reduced'), text: t('award points for both current and previous answers') }, any_response: { hint: t('everyone who answers gets full credit'), text: t('award points for any submitted answer') }, thrown_out: { hint: t('full credit awarded to all who have submitted the quiz'), text: t('give everyone full credit') } }; } }, { key: "scoreReconciliation", get: function get() { return this.props.scoreReconciliation; } }, { key: "selectHint", get: function get() { var hint = this.optionInputs[this.scoreReconciliation].hint; return [ { text: t('Result: {hint}', { hint: hint }), type: 'hint' } ]; } }, { // Rendering key: "cancelButton", value: function cancelButton() { return /*#__PURE__*/ jsx(Button, { margin: XSMALL_SIDE_MARGIN, onClick: this.cancelAction, ref: this.setRef('cancelImportButton') }, t('Cancel')); } }, { key: "regradeButton", value: function regradeButton() { return /*#__PURE__*/ jsx(Button, { margin: XSMALL_SIDE_MARGIN, onClick: this.onSubmit, ref: this.setRef('confirmButton'), color: "primary", "data-automation": "sdk-regrade-button" }, t('Regrade')); } }, { key: "setRef", value: function setRef(refName) { var _this = this; return function(node) { _this[refName] = node; }; } }, { key: "renderOptionInputs", value: function renderOptionInputs() { return Object.entries(this.optionInputs).map(function(optionInput) { return /*#__PURE__*/ jsx("option", { key: optionInput[0], value: optionInput[0] }, optionInput[1].text); }); } }, { key: "renderRadioInputs", value: function renderRadioInputs() { return Object.entries(this.optionInputs).map(function(optionInput) { return /*#__PURE__*/ jsx(RadioInput, { label: optionInput[1].text, value: optionInput[0], key: optionInput[0], "data-automation": "sdk-regrade-option-".concat(optionInput[0]) }); }); } }, { key: "renderModalBody", value: function renderModalBody() { return /*#__PURE__*/ jsx("div", null, /*#__PURE__*/ jsx(Alert, { margin: "small 0", transition: "none", variant: "info" }, /*#__PURE__*/ jsx("div", { css: this.props.styles.alert }, /*#__PURE__*/ jsx("span", null, t.rich("\n <0>Regrading only applies to completed submissions.</0>\n <1>If all students are affected please wait for all submissions before Regrading.</1>\n ", [ function(param) { var children = param.children; return /*#__PURE__*/ jsx(Text, { as: "div", weight: "bold", key: "0" }, children); }, function(param) { var children = param.children; return /*#__PURE__*/ jsx(Text, { as: "span", key: "1" }, children); } ])))), /*#__PURE__*/ jsx("div", { css: this.props.styles.radioInputGroup, role: "form" }, /*#__PURE__*/ jsx(RadioInputGroup, { description: t('Select how you would like to apply this regrade.'), name: "scoring_reconciliation", onChange: this.onSpeedgraderOptionChange, messages: this.selectHint, value: this.scoreReconciliation }, this.renderRadioInputs()))); } }, { key: "renderErrorFromApi", value: function renderErrorFromApi() { if (this.state.hasGenericErrorFromApi) { return /*#__PURE__*/ jsx("div", { css: this.props.styles.errorAlert }, /*#__PURE__*/ jsx(InstUISettingsProvider, { theme: { componentOverrides: { Alert: { contentPadding: '0.4rem 1.5rem' } } } }, /*#__PURE__*/ jsx(Alert, { margin: "0 0", transition: "fade", variant: "error" }, /*#__PURE__*/ jsx(Text, { size: "small" }, t('Regrade did not run due to server error. Please try again later!'))))); } } }, { key: "render", value: function render() { return /*#__PURE__*/ jsx(Modal, { open: this.props.modalOpen, size: "medium", onDismiss: this.cancelAction, label: t('Question Regrade Options'), ref: this.setRef('modal'), "data-automation": "sdk-regrade-modal", shouldCloseOnDocumentClick: false }, /*#__PURE__*/ jsx(ModalHeader, null, /*#__PURE__*/ jsx(Heading, { level: "reset", as: "h2" }, t('Question Regrade Options')), /*#__PURE__*/ jsx(CloseButton, { onClick: this.cancelAction, placement: "end", offset: "medium", screenReaderLabel: t('Close') })), /*#__PURE__*/ jsx(ModalBody, null, this.renderModalBody()), /*#__PURE__*/ jsx(ModalFooter, null, this.renderErrorFromApi(), this.cancelButton(), this.regradeButton())); } } ]); return BaseRegradingModal; }(Component); _define_property(BaseRegradingModal, "displayName", 'RegradingModal'); _define_property(BaseRegradingModal, "componentId", "Quizzes".concat(BaseRegradingModal.displayName)); _define_property(BaseRegradingModal, "propTypes", { addSuccess: PropTypes.func.isRequired, closeModal: PropTypes.func.isRequired, createQuizEntryRegrade: PropTypes.func.isRequired, modalOpen: PropTypes.bool.isRequired, quizId: PropTypes.string.isRequired, regradingPayload: PropTypes.shape({ quizEntryId: PropTypes.string.isRequired, scoringAlgorithm: PropTypes.string, scoringData: PropTypes.object }).isRequired, scoreReconciliation: PropTypes.string.isRequired, setScoreReconciliation: PropTypes.func.isRequired, toggleRegradingEditMode: PropTypes.func.isRequired, handleValidationErrorsFromApi: PropTypes.func, styles: PropTypes.object }); _define_property(BaseRegradingModal, "defaultProps", { handleValidationErrorsFromApi: Function.prototype }); export var RegradingModal = withStyleOverrides(generateStyle, generateComponentTheme)(BaseRegradingModal); export default RegradingModal;