@instructure/quiz-grading
Version:
The Quiz React SDK by Instructure Inc.
244 lines • 10.7 kB
JavaScript
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, _SessionItemResultWrapper;
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 ImmutablePropTypes from 'react-immutable-proptypes';
import { Map } from 'immutable';
import { jsx } from '@instructure/emotion';
import { featureOn, CustomPropTypes, SessionItemResultView as SessionItemResult } from '@instructure/quiz-core';
import GradingBar from '../GradingBar';
import RegradeOverride from '../../quizEntry/RegradeOverride';
import { CLEAR_ALL_INPUT_VALIDATION_ERRORS, withStyleOverrides } from '@instructure/quiz-common';
import generateStyle from './styles';
import generateComponentTheme from './theme';
export var SessionItemResultWrapper = (_dec = withStyleOverrides(generateStyle, generateComponentTheme), _dec(_class = (_SessionItemResultWrapper = /*#__PURE__*/function (_Component) {
function SessionItemResultWrapper() {
var _this2;
_classCallCheck(this, SessionItemResultWrapper);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this2 = _callSuper(this, SessionItemResultWrapper, [].concat(args));
_defineProperty(_this2, "state", {
graderFeedback: _this2.props.graderFeedback,
validationErrorsFromApi: {}
});
_defineProperty(_this2, "gradingBar", null);
_defineProperty(_this2, "_timeouts", []);
_defineProperty(_this2, "startFeedbackEdit", function () {
if (!_this2.props.isEditing) {
_this2.props.switchOnEditing();
}
});
_defineProperty(_this2, "closeFeedbackEdit", function () {
var _this2$gradingBar;
_this2.props.switchOffEditing();
(_this2$gradingBar = _this2.gradingBar) === null || _this2$gradingBar === void 0 || (_this2$gradingBar = _this2$gradingBar.getWrappedInstance()) === null || _this2$gradingBar === void 0 || _this2$gradingBar.focusFeedbackButton();
});
_defineProperty(_this2, "submitFeedbackEdit", function () {
_this2.props.handleChangeFeedback(_this2.props.sessionItem.id, _this2.props.item.id, {
graderFeedback: _this2.state.graderFeedback.toJS()
});
_this2.closeFeedbackEdit();
});
_defineProperty(_this2, "updateFeedbackEdit", function (e, _ref) {
var editorContent = _ref.editorContent;
_this2.setState({
graderFeedback: Map({
content: editorContent
})
});
});
// =============
// HANDLERS
// =============
_defineProperty(_this2, "setActiveItem", function () {
if (_this2.props.gradeByQuestionEnabled) {
_this2.props.setActiveItem(_this2.props.item.id);
}
});
_defineProperty(_this2, "handleRegradingEditModeToggle", function () {
_this2.props.toggleRegradingEditMode(_this2.props.regradingKey);
});
_defineProperty(_this2, "handleRegradingOnCancel", function (sessionItemId) {
_this2.clearValidationErrorsFromApi(CLEAR_ALL_INPUT_VALIDATION_ERRORS);
_this2._timeouts = _this2._timeouts.concat(setTimeout(function () {
var _this2$gradingBar2;
return (_this2$gradingBar2 = _this2.gradingBar) === null || _this2$gradingBar2 === void 0 || (_this2$gradingBar2 = _this2$gradingBar2.getWrappedInstance()) === null || _this2$gradingBar2 === void 0 ? void 0 : _this2$gradingBar2.focusRegradeButton();
}));
});
_defineProperty(_this2, "handleGradingBarRef", function (node) {
_this2.gradingBar = node;
});
_defineProperty(_this2, "handleValidationErrorsFromApi", function (errors) {
_this2.setState({
validationErrorsFromApi: errors
});
});
_defineProperty(_this2, "clearValidationErrorsFromApi", function (inputId) {
if (inputId === CLEAR_ALL_INPUT_VALIDATION_ERRORS) {
_this2.setState({
validationErrorsFromApi: {}
});
}
if (_this2.state.validationErrorsFromApi[inputId]) {
var newErrors = Object.assign({}, _this2.state.validationErrorsFromApi);
delete newErrors[inputId];
_this2.setState({
validationErrorsFromApi: newErrors
});
}
});
// =============
// RENDERING
// =============
_defineProperty(_this2, "renderRegradeOverride", function (sessionItem, item) {
return jsx(RegradeOverride, {
displayPosition: sessionItem.position,
guid: sessionItem.id,
onCancel: _this2.handleRegradingOnCancel,
itemId: item.id,
quizSessionId: _this2.props.quizSessionId,
sessionItem: sessionItem,
validationErrorsFromApi: _this2.state.validationErrorsFromApi,
handleValidationErrorsFromApi: _this2.handleValidationErrorsFromApi,
clearValidationErrorsFromApi: _this2.clearValidationErrorsFromApi
});
});
return _this2;
}
_inherits(SessionItemResultWrapper, _Component);
return _createClass(SessionItemResultWrapper, [{
key: "componentDidMount",
value: function componentDidMount() {
this.props.makeStyles();
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate() {
this.props.makeStyles();
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
this._timeouts.forEach(clearTimeout);
}
}, {
key: "isAutogradeable",
value: function isAutogradeable() {
var notAutogradeableTypes = ['essay', 'file-upload'];
return !notAutogradeableTypes.includes(this.props.item.getInteractionType().slug);
}
}, {
key: "isSubjective",
value: function isSubjective() {
return this.props.item.getInteractionType().isSubjective;
}
}, {
key: "renderResult",
value: function renderResult(sessionItem, item) {
var _this$props = this.props,
handleChangeGradeStatus = _this$props.handleChangeGradeStatus,
handleChangePoints = _this$props.handleChangePoints,
itemResultsModifications = _this$props.itemResultsModifications,
sessionItemResult = _this$props.sessionItemResult,
shouldRenderTopBorder = _this$props.shouldRenderTopBorder;
return jsx("div", {
css: this.props.styles.root,
"data-automation": "sdk-grading-result-wrapper",
tabIndex: "-1",
onFocus: this.setActiveItem
}, jsx("div", {
css: this.props.styles.result
}, jsx(SessionItemResult, {
appContainer: this.props.appContainer,
editGraderFeedback: this.startFeedbackEdit,
hideGraderFeedback: this.props.isEditing,
item: item,
sessionItem: sessionItem,
sessionItemResult: sessionItemResult,
shouldRenderTopBorder: shouldRenderTopBorder
})), jsx("div", {
css: this.props.styles.gradingBar
}, jsx(GradingBar, {
appContainer: this.props.appContainer,
ref: this.handleGradingBarRef,
cancelFeedbackEdit: this.closeFeedbackEdit,
graderFeedback: this.state.graderFeedback,
handleChangeGradeStatus: handleChangeGradeStatus,
handleChangePoints: handleChangePoints,
isAutogradeable: this.isAutogradeable(),
isEditing: this.props.isEditing,
isSubjective: this.isSubjective(),
itemResultsModifications: itemResultsModifications,
regradeToggleAction: this.handleRegradingEditModeToggle,
renderUpdateButton: this.props.renderUpdateButton,
sessionItem: sessionItem,
sessionItemResult: sessionItemResult,
startFeedbackEdit: this.startFeedbackEdit,
submitFeedbackEdit: this.submitFeedbackEdit,
updateFeedbackEdit: this.updateFeedbackEdit
})));
}
}, {
key: "render",
value: function render() {
var _this$props2 = this.props,
sessionItem = _this$props2.sessionItem,
item = _this$props2.item;
if (this.props.isRegrading && featureOn('regrading_from_speedgrader')) {
return this.renderRegradeOverride(sessionItem, item);
} else {
return this.renderResult(sessionItem, item);
}
}
}]);
}(Component), _defineProperty(_SessionItemResultWrapper, "displayName", 'SessionItemResultWrapper'), _defineProperty(_SessionItemResultWrapper, "componentId", "Quizzes".concat(_SessionItemResultWrapper.displayName)), _defineProperty(_SessionItemResultWrapper, "propTypes", {
activeItemId: PropTypes.string,
appContainer: CustomPropTypes.selectors.isRequired,
handleChangeFeedback: PropTypes.func.isRequired,
handleChangeGradeStatus: PropTypes.func.isRequired,
handleChangePoints: PropTypes.func.isRequired,
gradeByQuestionEnabled: PropTypes.bool,
graderFeedback: ImmutablePropTypes.map.isRequired,
isEditing: PropTypes.bool.isRequired,
isRegrading: PropTypes.bool.isRequired,
item: ImmutablePropTypes.record.isRequired,
itemResultsModifications: ImmutablePropTypes.map.isRequired,
quizSessionId: PropTypes.string.isRequired,
regradingKey: PropTypes.string.isRequired,
renderUpdateButton: PropTypes.func.isRequired,
sessionItem: ImmutablePropTypes.record.isRequired,
sessionItemResult: ImmutablePropTypes.record.isRequired,
setActiveItem: PropTypes.func.isRequired,
shouldRenderTopBorder: PropTypes.bool.isRequired,
switchOffEditing: PropTypes.func.isRequired,
switchOnEditing: PropTypes.func.isRequired,
toggleRegradingEditMode: PropTypes.func.isRequired,
makeStyles: PropTypes.func,
styles: PropTypes.object
}), _defineProperty(_SessionItemResultWrapper, "defaultProps", {
activeItemId: null,
gradeByQuestionEnabled: false
}), _SessionItemResultWrapper)) || _class);
export default SessionItemResultWrapper;