UNPKG

@instructure/quiz-grading

Version:

The Quiz React SDK by Instructure Inc.

279 lines • 11.2 kB
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; import _createClass from "@babel/runtime/helpers/esm/createClass"; import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf"; import _inherits from "@babel/runtime/helpers/esm/inherits"; import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; var _dec, _class, _RegradingModal; 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 _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else 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 _callSuper(_this, derived, args) { function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { return !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (e) { return false; } } derived = _getPrototypeOf(derived); return _possibleConstructorReturn(_this, isNativeReflectConstruct() ? Reflect.construct(derived, args || [], _getPrototypeOf(_this).constructor) : derived.apply(_this, args)); } /** @jsx jsx */ 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, XSMALL_SIDE_MARGIN, withStyleOverrides } from '@instructure/quiz-common'; import generateStyle from './styles'; import generateComponentTheme from './theme'; import t from '@instructure/quiz-i18n/es/format-message'; export var RegradingModal = (_dec = withStyleOverrides(generateStyle, generateComponentTheme), _dec(_class = (_RegradingModal = /*#__PURE__*/function (_Component) { function RegradingModal() { var _this2; _classCallCheck(this, RegradingModal); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this2 = _callSuper(this, RegradingModal, [].concat(args)); _defineProperty(_this2, "state", { hasGenericErrorFromApi: false }); // Handlers _defineProperty(_this2, "clearGenericErrorFromApi", function () { _this2.setState({ hasGenericErrorFromApi: false }); }); _defineProperty(_this2, "cancelAction", function () { _this2.clearGenericErrorFromApi(); _this2.props.closeModal(); }); _defineProperty(_this2, "onSpeedgraderOptionChange", function (event, newValue) { _this2.props.setScoreReconciliation(newValue); }); _defineProperty(_this2, "onSubmit", function () { var _this2$props = _this2.props, createQuizEntryRegrade = _this2$props.createQuizEntryRegrade, quizId = _this2$props.quizId, regradingPayload = _this2$props.regradingPayload, scoreReconciliation = _this2$props.scoreReconciliation; _this2.clearGenericErrorFromApi(); createQuizEntryRegrade(quizId, _objectSpread(_objectSpread({}, regradingPayload), {}, { scoreReconciliation: scoreReconciliation })).then(function () { _this2.props.toggleRegradingEditMode(''); _this2.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 _this2.cancelAction(); _this2.props.handleValidationErrorsFromApi(e.validationErrorsFromApi); } else { // Some other type of error occurred _this2.setState({ hasGenericErrorFromApi: true }); } throw e; }); }); return _this2; } _inherits(RegradingModal, _Component); return _createClass(RegradingModal, [{ 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' }]; } }, { key: "cancelButton", value: // Rendering function cancelButton() { return jsx(Button, { margin: XSMALL_SIDE_MARGIN, onClick: this.cancelAction, ref: this.setRef('cancelImportButton') }, t('Cancel')); } }, { key: "regradeButton", value: function regradeButton() { return 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 _this3 = this; return function (node) { _this3[refName] = node; }; } }, { key: "renderOptionInputs", value: function renderOptionInputs() { return Object.entries(this.optionInputs).map(function (optionInput) { return 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 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 jsx("div", null, jsx(Alert, { margin: "small 0", transition: "none", variant: "info" }, jsx("div", { css: this.props.styles.alert }, 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 (_ref) { var children = _ref.children; return jsx(Text, { as: "div", weight: "bold", key: "0" }, children); }, function (_ref2) { var children = _ref2.children; return jsx(Text, { as: "span", key: "1" }, children); }])))), jsx("div", { css: this.props.styles.radioInputGroup, role: "form" }, 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 jsx("div", { css: this.props.styles.errorAlert }, jsx(InstUISettingsProvider, { theme: { componentOverrides: { Alert: { contentPadding: '0.4rem 1.5rem' } } } }, jsx(Alert, { margin: "0 0", transition: "fade", variant: "error" }, jsx(Text, { size: "small" }, t('Regrade did not run due to server error. Please try again later!'))))); } } }, { key: "render", value: function render() { return 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 }, jsx(ModalHeader, null, jsx(Heading, { level: "reset", as: "h2" }, t('Question Regrade Options')), jsx(CloseButton, { onClick: this.cancelAction, placement: "end", offset: "medium", screenReaderLabel: t('Close') })), jsx(ModalBody, null, this.renderModalBody()), jsx(ModalFooter, null, this.renderErrorFromApi(), this.cancelButton(), this.regradeButton())); } }]); }(Component), _defineProperty(_RegradingModal, "displayName", 'RegradingModal'), _defineProperty(_RegradingModal, "componentId", "Quizzes".concat(_RegradingModal.displayName)), _defineProperty(_RegradingModal, "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 }), _defineProperty(_RegradingModal, "defaultProps", { handleValidationErrorsFromApi: Function.prototype }), _RegradingModal)) || _class); export default RegradingModal;