feat: tolerance Setting Widget (#286)

* feat: tolerance Setting Widget

* fix: tolerance position and percent summary
This commit is contained in:
connorhaugh
2023-03-22 14:31:02 -04:00
committed by GitHub
parent 16003a7f4a
commit df5af3efd9
8 changed files with 335 additions and 2 deletions

View File

@@ -462,6 +462,16 @@ export class OLXParser {
}
const { answers } = answersObject;
const settings = { hints };
if (ProblemTypeKeys.NUMERIC === problemType && _.has(answers[0], 'tolerance')) {
const toleranceValue = answers[0].tolerance;
if (!toleranceValue || toleranceValue.length === 0) {
settings.tolerance = { value: null, type: 'None' };
} else if (toleranceValue.includes('%')) {
settings.tolerance = { value: parseInt(toleranceValue.slice(0, -1)), type: 'Percent' };
} else {
settings.tolerance = { value: parseInt(toleranceValue), type: 'Number' };
}
}
if (solutionExplanation) { settings.solutionExplanation = solutionExplanation; }
return {

View File

@@ -1,6 +1,7 @@
import _ from 'lodash-es';
import { XMLParser, XMLBuilder } from 'fast-xml-parser';
import { ProblemTypeKeys } from '../../../data/constants/problem';
import { ToleranceTypes } from '../components/EditProblemView/SettingsWidget/settingsComponents/Tolerance/constants';
class ReactStateOLXParser {
constructor(problemState) {
@@ -306,6 +307,7 @@ class ReactStateOLXParser {
buildNumericalResponse() {
const { answers } = this.problemState;
const { tolerance } = this.problemState.settings;
const { selectedFeedback } = this.editorObject;
let answerObject = {};
const additionalAnswers = [];
@@ -316,11 +318,11 @@ class ReactStateOLXParser {
if (answer.correct && !firstCorrectAnswerParsed) {
firstCorrectAnswerParsed = true;
let responseParam = {};
if (_.has(answer, 'tolerance')) {
if (tolerance?.value) {
responseParam = {
responseparam: {
'@_type': 'tolerance',
'@_default': _.get(answer, 'tolerance', 0),
'@_default': `${tolerance.value}${tolerance.type === ToleranceTypes.number.type ? '' : '%'}`,
},
};
}