UNPKG

@instructure/quiz-interactions

Version:

A React UI component Library for quiz interaction types.

118 lines 4.4 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 _inherits from "@babel/runtime/helpers/esm/inherits"; import _get from "@babel/runtime/helpers/esm/get"; import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf"; import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; 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)); } import React from 'react'; import compact from 'lodash/compact'; import { v4 as uuid } from 'uuid'; import { rule, each } from 'instructure-validations'; import { RichContentRenderer } from '@instructure/quiz-rce'; import { ORDERING_SLUG } from '../../interaction_slugs'; import InteractionType from '../InteractionType'; import { noDuplicatesMessage, presenceMessage } from '../../util/validationHelpers'; import t from '@instructure/quiz-i18n/es/format-message'; var OrderingInteractionType = /*#__PURE__*/function (_InteractionType) { function OrderingInteractionType(obj) { var _this2; _classCallCheck(this, OrderingInteractionType); _this2 = _callSuper(this, OrderingInteractionType); _defineProperty(_this2, "slug", ORDERING_SLUG); _defineProperty(_this2, "translatedName", t('Ordering')); _defineProperty(_this2, "defaultProperties", { includeLabels: true, displayAnswersParagraph: false, topLabel: '', bottomLabel: '' }); _defineProperty(_this2, "getDefaultInteractionData", function () { var choiceIdA = uuid(); var choiceIdB = uuid(); var choiceIdC = uuid(); var choiceIdD = uuid(); return { itemBody: '', choices: _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, choiceIdA, { id: choiceIdA, itemBody: '' }), choiceIdB, { id: choiceIdB, itemBody: '' }), choiceIdC, { id: choiceIdC, itemBody: '' }), choiceIdD, { id: choiceIdD, itemBody: '' }) }; }); _defineProperty(_this2, "getDefaultScoringData", function (intData) { return { value: Object.keys(intData.choices).map(function (uuid) { return uuid; }) }; }); _defineProperty(_this2, "getRenderedResponse", function (responseValue) { var interactionData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { choices: {} }; return compact(responseValue.map(function (id) { var choice = interactionData.choices[id]; if (choice !== void 0) { return /*#__PURE__*/React.createElement(RichContentRenderer, { key: id, content: choice.itemBody }); } else { return null; } })); }); _get((_this2, _getPrototypeOf(OrderingInteractionType.prototype)), "initializeProps", _this2).call(_this2, obj); return _this2; } _inherits(OrderingInteractionType, _InteractionType); return _createClass(OrderingInteractionType, [{ key: "getDefaultUserResponse", value: function getDefaultUserResponse(intData) { return { value: intData.shuffledOrder || Object.keys(intData.choices) }; } }], [{ key: "validations", value: function validations() { return { interactionData: { choices: [each({ itemBody: [rule('presence', { message: presenceMessage(t('Choice')) })] }), rule('noDuplicates', { field: 'itemBody', message: noDuplicatesMessage(t('Choice')) })] } }; } }]); }(InteractionType); export { OrderingInteractionType as default };