Skip to content

Commit

Permalink
[BUGFIX] | Rolling back changes done in Delivery side for MER-2245
Browse files Browse the repository at this point in the history
[BUG] | Rolling back changes done in Delivery side for MER-2245
  • Loading branch information
darrensiegel authored Dec 21, 2023
2 parents 554a2c2 + 4b2e481 commit e3d9ac9
Showing 1 changed file with 40 additions and 40 deletions.
80 changes: 40 additions & 40 deletions assets/src/adaptivity/scripting.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { EntityId } from '@reduxjs/toolkit';
import { Environment, Evaluator, Lexer, Parser } from 'janus-script';
import flatten from 'lodash/flatten';
import uniq from 'lodash/uniq';
// import flatten from 'lodash/flatten';
// import uniq from 'lodash/uniq';
import { parseArray, parseBoolean } from 'utils/common';
import { CapiVariableTypes, getCapiType } from './capi';
import { janus_std } from './janus-scripts/builtin_functions';

let conditionsNeedEvaluation: string[] = [];
//const conditionsNeedEvaluation: string[] = [];
export const setConditionsWithExpression = (facts: string[]) => {
conditionsNeedEvaluation.push(...facts);
conditionsNeedEvaluation = uniq(flatten(Array.from(new Set(conditionsNeedEvaluation))));
const script = `let session.conditionsNeedEvaluation = ${JSON.stringify(
conditionsNeedEvaluation,
)}`;
evalScript(script, defaultGlobalEnv);
// conditionsNeedEvaluation.push(...facts);
// conditionsNeedEvaluation = uniq(flatten(Array.from(new Set(conditionsNeedEvaluation))));
// const script = `let session.conditionsNeedEvaluation = ${JSON.stringify(
// conditionsNeedEvaluation,
// )}`;
// evalScript(script, defaultGlobalEnv);
};

export const looksLikeJson = (str: string) => {
Expand Down Expand Up @@ -53,20 +53,20 @@ export const getExpressionStringForValue = (
v: { type: CapiVariableTypes; value: any; key?: string },
env: Environment = defaultGlobalEnv,
): string => {
let shouldEvaluateExpression = true;
const shouldEvaluateExpression = true;
//To improve the performance, when a lesson is opened in authoring, we generate a list of variables that contains expression and needs evaluation
// we stored them in conditionsNeedEvaluation in activity.content.custom.conditionsNeedEvaluation. When this function is called
// we only process variables that is present in conditionsNeedEvaluation array and ignore others.
try {
const conditionsNeedEvaluations = getValue('session.conditionsNeedEvaluation', env);
// if they key is not passed then it means that this function was called from the janu-text component so this logic will not apply
// we need to process it with the old behaviour
if (conditionsNeedEvaluations?.length && v.key) {
shouldEvaluateExpression = conditionsNeedEvaluations.includes(v.key);
}
} catch (er) {
console.warn('Error at getExpressionStringForValue for ', { key: v.key });
}
// try {
// const conditionsNeedEvaluations = getValue('session.conditionsNeedEvaluation', env);
// // if they key is not passed then it means that this function was called from the janu-text component so this logic will not apply
// // we need to process it with the old behaviour
// if (conditionsNeedEvaluations?.length && v.key) {
// shouldEvaluateExpression = conditionsNeedEvaluations.includes(v.key);
// }
// } catch (er) {
// console.warn('Error at getExpressionStringForValue for ', { key: v.key });
// }
let val: any = v.value;
let isValueVar = false;
let isEverAppArrayObject = false;
Expand Down Expand Up @@ -612,26 +612,26 @@ export const templatizeText = (
useFormattedText = true,
key?: string,
): string => {
let shouldEvaluateExpression = true;
try {
//To improve the performance, when a lesson is opened in authoring, we generate a list of variables that contains expression and needs evaluation
// we stored them in conditionsNeedEvaluation in activity.content.custom.conditionsNeedEvaluation. When this function is called
// we only process variables that is present in conditionsNeedEvaluation array and ignore others.
const conditionsNeedEvaluations = Object.keys(locals)?.length
? locals['session.conditionsNeedEvaluation']
: getValue('session.conditionsNeedEvaluation', defaultGlobalEnv);

// if they key is not passed then it means that this function was called from the janu-text component so this logic will not apply
// we need to process it with the old behaviour
if (conditionsNeedEvaluations?.length && key) {
shouldEvaluateExpression = conditionsNeedEvaluations.includes(key);
}
if (!shouldEvaluateExpression) {
return text;
}
} catch (er) {
console.warn('Error at templatizeText for key', { key });
}
//const shouldEvaluateExpression = true;
// try {
// //To improve the performance, when a lesson is opened in authoring, we generate a list of variables that contains expression and needs evaluation
// // we stored them in conditionsNeedEvaluation in activity.content.custom.conditionsNeedEvaluation. When this function is called
// // we only process variables that is present in conditionsNeedEvaluation array and ignore others.
// const conditionsNeedEvaluations = Object.keys(locals)?.length
// ? locals['session.conditionsNeedEvaluation']
// : getValue('session.conditionsNeedEvaluation', defaultGlobalEnv);

// // if they key is not passed then it means that this function was called from the janu-text component so this logic will not apply
// // we need to process it with the old behaviour
// if (conditionsNeedEvaluations?.length && key) {
// shouldEvaluateExpression = conditionsNeedEvaluations.includes(key);
// }
// if (!shouldEvaluateExpression) {
// return text;
// }
// } catch (er) {
// console.warn('Error at templatizeText for key', { key });
// }
let innerEnv = new Environment(env);
// if the text contains backslash, it is probably a math exprs like: '16^{\\frac{1}{2}}=\\sqrt {16}={\\editable{}}'
// and we should just return it as is; if it has variables inside, then we still need to evaluate it
Expand Down

0 comments on commit e3d9ac9

Please sign in to comment.