@instructure/quiz-interactions
Version:
A React UI component Library for quiz interaction types.
94 lines • 3.66 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 _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 { rule } from 'instructure-validations';
import { Text } from '@instructure/ui-text';
import InteractionType from '../InteractionType';
import { FILE_UPLOAD_SLUG } from '../../interaction_slugs';
import t from '@instructure/quiz-i18n/es/format-message';
var FileUploadInteractionType = /*#__PURE__*/function (_InteractionType) {
function FileUploadInteractionType(obj) {
var _this2;
_classCallCheck(this, FileUploadInteractionType);
_this2 = _callSuper(this, FileUploadInteractionType);
_defineProperty(_this2, "slug", FILE_UPLOAD_SLUG);
_defineProperty(_this2, "translatedName", t('File Upload'));
_defineProperty(_this2, "isSubjective", true);
_defineProperty(_this2, "defaultProperties", {
restrictTypes: false
});
_defineProperty(_this2, "getDefaultScoringData", function () {
return {
value: ''
};
});
_defineProperty(_this2, "getDefaultInteractionData", function () {
return {
restrictCount: false,
filesCount: '1'
};
});
_defineProperty(_this2, "getRenderedResponse", function (responseValue, interactionData) {
return /*#__PURE__*/React.createElement(Text, {
color: "primary"
}, responseValue.map(function (value) {
return value.name;
}).join(', '));
});
_get((_this2, _getPrototypeOf(FileUploadInteractionType.prototype)), "initializeProps", _this2).call(_this2, obj);
return _this2;
}
_inherits(FileUploadInteractionType, _InteractionType);
return _createClass(FileUploadInteractionType, [{
key: "getDefaultUserResponse",
value: function getDefaultUserResponse() {
return {
value: []
};
}
}, {
key: "hasResponse",
value: function hasResponse(resp) {
return resp.length > 0;
}
}]);
}(InteractionType);
_defineProperty(FileUploadInteractionType, "validations", function () {
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var properties = data.properties || {};
var interactionData = data.interactionData || {};
var restrictTypes = properties.restrictTypes;
var restrictCount = interactionData.restrictCount;
return {
properties: {
allowedTypes: restrictTypes ? [rule('fileAccept', {
message: t('Invalid file type restriction')
})] : []
},
interactionData: {
filesCount: restrictCount ? [rule('numeric', {
min: 1
})] : []
}
};
});
export { FileUploadInteractionType as default };