@instructure/quiz-grading
Version:
The Quiz React SDK by Instructure Inc.
231 lines (230 loc) • 10.2 kB
JavaScript
/** @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 _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 partial from 'lodash/partial';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { jsx } from '@instructure/emotion';
import { View } from '@instructure/ui-view';
import { IconArrowOpenEndLine } from '@instructure/ui-icons';
import { ResultStimulus } from '@instructure/quiz-core/common/components/resources/sessionItemResult/ResultStimulus/index';
import { generateDisplayPositions } from '@instructure/quiz-core/common/util/generateDisplayPositions';
import { Flex } from '@instructure/quiz-common/components/Flex/index';
import { GRADE_BY_QUESTION_NEXT } from '@instructure/quiz-common/constants';
import { withStyleOverrides } from '@instructure/quiz-common/util/withStyleOverrides';
import SessionItemResultWrapper from '../SessionItemResultWrapper';
import generateStyle from './styles';
import t from '@instructure/quiz-i18n/format-message';
var BaseSessionItemResultList = /*#__PURE__*/ function(Component) {
"use strict";
_inherits(BaseSessionItemResultList, Component);
function BaseSessionItemResultList() {
_class_call_check(this, BaseSessionItemResultList);
var _this;
_this = _call_super(this, BaseSessionItemResultList, arguments), _define_property(_this, "nextStudent", function() {
_this.props.postToParent({
subject: GRADE_BY_QUESTION_NEXT
});
}), _define_property(_this, "renderSessionItemResultWrapper", function(sessionItem, shouldRenderTopBorder) {
var _this_props = _this.props, handleChangePoints = _this_props.handleChangePoints, handleChangeFeedback = _this_props.handleChangeFeedback, handleChangeGradeStatus = _this_props.handleChangeGradeStatus, quizSessionId = _this_props.quizSessionId, regradingIdentifier = _this_props.regradingIdentifier, renderUpdateButton = _this_props.renderUpdateButton;
var result = sessionItem.sessionItemResult;
var item = sessionItem.getItem();
return /*#__PURE__*/ jsx(SessionItemResultWrapper, {
handleChangeFeedback: handleChangeFeedback,
handleChangeGradeStatus: partial(handleChangeGradeStatus, result.id, item.id),
handleChangePoints: partial(handleChangePoints, result.id, item.id),
item: item,
key: sessionItem.id,
quizSessionId: quizSessionId,
isRegrading: sessionItem.id === regradingIdentifier,
regradingKey: sessionItem.id,
renderUpdateButton: renderUpdateButton,
sessionItem: sessionItem,
shouldRenderTopBorder: shouldRenderTopBorder
});
});
return _this;
}
_create_class(BaseSessionItemResultList, [
{
key: "componentDidMount",
value: function componentDidMount() {
this.scrollToActiveItem();
}
},
{
key: "componentDidUpdate",
value: function componentDidUpdate(prevProps) {
if (prevProps.quizSessionId !== this.props.quizSessionId) {
this.scrollToActiveItem();
}
}
},
{
key: "scrollToActiveItem",
value: function scrollToActiveItem() {
var _this_props = this.props, activeItemId = _this_props.activeItemId, gradeByQuestionEnabled = _this_props.gradeByQuestionEnabled, sessionItems = _this_props.sessionItems;
if (gradeByQuestionEnabled && activeItemId) {
var sessionItem = sessionItems.find(function(si) {
return si.itemRecord.id === activeItemId;
});
if (sessionItem) {
this.props.scrollToItem(sessionItem.id);
} else {
var continueText = /*#__PURE__*/ jsx(Flex, {
alignItems: "center"
}, /*#__PURE__*/ jsx(View, {
margin: "0 x-small 0 0"
}, t('Next Student')), /*#__PURE__*/ jsx(IconArrowOpenEndLine, null));
this.props.withConfirm(this.nextStudent, {
continueText: continueText,
text: t('The active student does not have this question. Please use the Next Student button to proceed.'),
title: t('Question Not Available')
});
}
}
}
},
{
key: "renderItem",
value: function renderItem(sessionItem) {
if (sessionItem.stimulus) {
return /*#__PURE__*/ jsx(ResultStimulus, {
key: sessionItem.id,
stimulus: sessionItem.stimulusRecord,
renderItem: this.renderSessionItemResultWrapper,
sessionItem: sessionItem,
// This prop is necessary to rerender the child items when we enter regrading mode
regradingIdentifier: this.props.regradingIdentifier
});
}
return this.renderSessionItemResultWrapper(sessionItem, true);
}
},
{
key: "renderItems",
value: function renderItems() {
var _this = this;
return generateDisplayPositions(this.props.sessionItems).map(function(si) {
return _this.renderItem(si.record);
});
}
},
{
key: "render",
value: function render() {
return /*#__PURE__*/ jsx("div", {
css: this.props.styles.root
}, this.renderItems());
}
}
]);
return BaseSessionItemResultList;
}(Component);
_define_property(BaseSessionItemResultList, "displayName", 'SessionItemResultList');
_define_property(BaseSessionItemResultList, "componentId", "Quizzes".concat(BaseSessionItemResultList.displayName));
_define_property(BaseSessionItemResultList, "propTypes", {
activeItemId: PropTypes.string,
gradeByQuestionEnabled: PropTypes.bool,
handleChangePoints: PropTypes.func.isRequired,
handleChangeFeedback: PropTypes.func.isRequired,
handleChangeGradeStatus: PropTypes.func.isRequired,
postToParent: PropTypes.func.isRequired,
quizSessionId: PropTypes.string.isRequired,
regradingIdentifier: PropTypes.string.isRequired,
renderUpdateButton: PropTypes.func.isRequired,
scrollToItem: PropTypes.func.isRequired,
sessionItems: ImmutablePropTypes.list.isRequired,
withConfirm: PropTypes.func.isRequired,
styles: PropTypes.object
});
_define_property(BaseSessionItemResultList, "defaultProps", {
activeItemId: null,
gradeByQuestionEnabled: false
});
export var SessionItemResultList = withStyleOverrides(generateStyle)(BaseSessionItemResultList);
export default SessionItemResultList;