@instructure/quiz-interactions
Version:
A React UI component Library for quiz interaction types.
144 lines • 4.06 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import { DragDropContext } from 'react-dnd';
import HTML5Backend from 'react-dnd-html5-backend';
import FillBlankResult from './index';
var scoredDataFromBlank = function scoredDataFromBlank(blank, correctAnswer) {
if (blank.answerType === 'openEntry') {
return {
resultScore: correctAnswer === 'one',
// fitb result component should respect/display whitespace between words
userResponse: 'one word ʃ̬',
correctAnswer: correctAnswer
};
}
if (correctAnswer === 'one') {
return {
value: _defineProperty(_defineProperty(_defineProperty({}, blank.choices[0].id, {
resultScore: 1,
userResponded: true
}), blank.choices[1].id, {
resultScore: 0,
userResponded: false
}), blank.choices[2].id, {
resultScore: 0,
userResponded: false
})
};
} else if (correctAnswer === 'one or two') {
return {
value: _defineProperty(_defineProperty(_defineProperty({}, blank.choices[0].id, {
resultScore: 1,
userResponded: false
}), blank.choices[1].id, {
resultScore: 1,
userResponded: true
}), blank.choices[2].id, {
resultScore: 0,
userResponded: false
})
};
} else if (correctAnswer === 'three') {
return {
value: _defineProperty(_defineProperty(_defineProperty({}, blank.choices[0].id, {
resultScore: 0,
userResponded: true
}), blank.choices[1].id, {
resultScore: 0,
userResponded: false
}), blank.choices[2].id, {
resultScore: 1,
userResponded: false
})
};
} else if (correctAnswer === 'no scores') {
return {
value: _defineProperty(_defineProperty(_defineProperty({}, blank.choices[0].id, {
userResponded: false
}), blank.choices[1].id, {
userResponded: true
}), blank.choices[2].id, {
userResponded: false
})
};
} else if (correctAnswer === 'no responses') {
return {
value: _defineProperty(_defineProperty(_defineProperty({}, blank.choices[0].id, {
resultScore: 0
}), blank.choices[1].id, {
resultScore: 0
}), blank.choices[2].id, {
resultScore: 0
})
};
} else {
return {
value: {}
};
}
};
export default {
component: DragDropContext(HTML5Backend)(FillBlankResult),
propValues: {
blank: [{
id: 'fitb_uuid1',
answerType: 'openEntry'
}, {
id: 'fitb_uuid1',
answerType: 'wordbank',
choices: [{
id: 'choice_uuid1',
position: 1,
itemBody: 'one'
}, {
id: 'choice_uuid2',
position: 2,
itemBody: 'two'
}, {
id: 'choice_uuid3',
position: 3,
itemBody: 'three'
}]
}, {
id: 'fitb_uuid1',
answerType: 'dropdown',
choices: [{
id: 'choice_uuid1',
position: 1,
itemBody: 'one'
}, {
id: 'choice_uuid2',
position: 2,
itemBody: 'two'
}, {
id: 'choice_uuid3',
position: 3,
itemBody: 'three'
}]
}],
correctAnswer: ['one', 'one or two', 'three', 'no scores', 'no responses', 'responses hidden']
},
getComponentProps: function getComponentProps(props) {
return {
interactionData: {
prompt: "<p><strong>Please</strong> fill in all the blanks (".concat(props.blank.answerType, ", ").concat(props.correctAnswer, ")</p>"),
stemItems: [{
id: 'stem_uuid0',
position: 1,
type: 'text',
value: 'Write a number word here: '
}, {
id: 'stem_uuid1',
position: 2,
type: 'blank',
blankId: 'fitb_uuid1'
}],
blanks: [props.blank]
},
scoredData: {
value: props.correctAnswer === 'responses hidden' ? null : {
fitb_uuid1: scoredDataFromBlank(props.blank, props.correctAnswer)
}
}
};
}
};