feat: tolerance Setting Widget (#286)
* feat: tolerance Setting Widget * fix: tolerance position and percent summary
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 ? '' : '%'}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user