@instructure/quiz-interactions
Version:
A React UI component Library for quiz interaction types.
56 lines (46 loc) • 1.49 kB
JavaScript
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/format-message'
export default class FileUploadInteractionType extends InteractionType {
constructor(obj) {
super()
super.initializeProps(obj)
}
slug = FILE_UPLOAD_SLUG
translatedName = t('File Upload')
isSubjective = true
defaultProperties = {restrictTypes: false}
getDefaultScoringData = () => ({value: ''})
getDefaultInteractionData = () => ({
restrictCount: false,
filesCount: '1',
})
getRenderedResponse = (responseValue, interactionData) => {
return <Text color="primary">{responseValue.map(value => value.name).join(', ')}</Text>
}
static validations = (data = {}) => {
const properties = data.properties || {}
const interactionData = data.interactionData || {}
const restrictTypes = properties.restrictTypes
const restrictCount = interactionData.restrictCount
return {
properties: {
allowedTypes: restrictTypes
? [rule('fileAccept', {message: t('Invalid file type restriction')})]
: [],
},
interactionData: {
filesCount: restrictCount ? [rule('numeric', {min: 1})] : [],
},
}
}
getDefaultUserResponse() {
return {value: []}
}
hasResponse(resp) {
return resp.length > 0
}
}