@instructure/quiz-grading
Version:
The Quiz React SDK by Instructure Inc.
81 lines (74 loc) • 3 kB
JavaScript
import {Map, Set} from 'immutable'
import RegradeOverridePresenter from './presenter'
import {connect} from '@instructure/quiz-core/common/react-redux'
import {makeEditable} from '@instructure/quiz-core/common/components/shared/functionality/makeEditable'
import {addError, screenreaderNotification} from '@instructure/quiz-core/common/actions/alerts'
import {
changeItemState,
changeQuizEntryPoints,
changeQuizEntryProperties,
clearModifications,
} from '@instructure/quiz-core/common/actions/modifications'
import {showError, hideError} from '@instructure/quiz-core/common/actions/errorsShowing'
import {openModal} from '@instructure/quiz-core/common/actions/modal'
import {
setRegradingPayload,
toggleRegradingEditMode,
} from '@instructure/quiz-core/common/actions/regrading'
import {getItem} from '@instructure/quiz-core/building/api/items'
import {getQuizEntry} from '@instructure/quiz-core/building/api/quizEntries'
import {interactionFileUpload, setOneAtATimeType} from '@instructure/quiz-core/building/api/quizzes'
import {
getActiveQuizId,
getQuizEntryById,
isActiveQuizWorkingInstanceOneQuestionAtATime,
} from '@instructure/quiz-core/common/selectors/quizzes'
import {getItemById} from '@instructure/quiz-core/common/selectors/items'
function mapStateToProps(state, props) {
const errorsShowing = state.errorsShowing ?? Map()
const errorsAreShowing = errorsShowing.get(props.guid)
const quizEntry = getQuizEntryById(state, props.sessionItem.quizEntryId)
const entry = getItemById(state, props.itemId)
const workingQuizEntry = quizEntry.getWorkingInstance()
const regradeAdjustedScoringData = workingQuizEntry.regradeAdjustedScoringData(props.itemId)
const itemOverrides = regradeAdjustedScoringData
? {
scoringData: regradeAdjustedScoringData,
scoringAlgorithm: workingQuizEntry.regradeScoringAlgorithm(props.itemId),
}
: null
const features = state.features ?? Set()
return {
appContainer: state.ui.get('appContainer'),
entry,
errorsAreShowing: errorsAreShowing,
oneQuestionAtATime: isActiveQuizWorkingInstanceOneQuestionAtATime(state),
partialScoringEnabled: features.includes('partial_scoring'),
partialDeepScoringEnabled: features.includes('partial_deep_scoring'),
quizEntry,
quizId: getActiveQuizId(state),
workingEntry: entry.getWorkingInstance(itemOverrides),
workingQuizEntry,
}
}
const mapDispatchToProps = {
hideError,
showError,
addError,
changeItemState: changeItemState,
changeQuizEntryPoints: changeQuizEntryPoints,
changeQuizEntryProperties: changeQuizEntryProperties,
clearModifications: clearModifications,
getItem,
getQuizEntry,
interactionFileUpload,
openModal,
screenreaderNotification,
setOneQuestionAtATime: setOneAtATimeType,
setRegradingPayload,
toggleRegradingEditMode,
}
export const RegradeOverride = makeEditable(
connect(mapStateToProps, mapDispatchToProps)(RegradeOverridePresenter),
)
export default RegradeOverride