From 60433cb76885d5f28ed519ca4c7d5c64e536ffa6 Mon Sep 17 00:00:00 2001 From: KristinAoki Date: Thu, 25 Jul 2024 14:33:20 -0400 Subject: [PATCH] feat: add conditional for new parser beta testing --- .../ProblemEditor/components/SelectTypeModal/hooks.js | 1 + .../components/SelectTypeModal/hooks.test.js | 1 + src/editors/containers/ProblemEditor/data/OLXParser.js | 9 +++++++++ src/editors/data/redux/thunkActions/problem.js | 7 ++++++- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/editors/containers/ProblemEditor/components/SelectTypeModal/hooks.js b/src/editors/containers/ProblemEditor/components/SelectTypeModal/hooks.js index 5854ea2e8..ef70a3613 100644 --- a/src/editors/containers/ProblemEditor/components/SelectTypeModal/hooks.js +++ b/src/editors/containers/ProblemEditor/components/SelectTypeModal/hooks.js @@ -37,6 +37,7 @@ export const onSelect = ({ attempts_before_showanswer_button: 0, show_reset_button: null, showanswer: null, + defaultToAdvanced: false, }, defaultSettings: snakeCaseKeys(defaultSettings), }); diff --git a/src/editors/containers/ProblemEditor/components/SelectTypeModal/hooks.test.js b/src/editors/containers/ProblemEditor/components/SelectTypeModal/hooks.test.js index baa57670d..2970c87b3 100644 --- a/src/editors/containers/ProblemEditor/components/SelectTypeModal/hooks.test.js +++ b/src/editors/containers/ProblemEditor/components/SelectTypeModal/hooks.test.js @@ -78,6 +78,7 @@ describe('SelectTypeModal hooks', () => { attempts_before_showanswer_button: 0, show_reset_button: null, showanswer: null, + defaultToAdvanced: false, }, defaultSettings: mockDefaultSettings, }); diff --git a/src/editors/containers/ProblemEditor/data/OLXParser.js b/src/editors/containers/ProblemEditor/data/OLXParser.js index 7f7f11c9b..0a3d0ff6a 100644 --- a/src/editors/containers/ProblemEditor/data/OLXParser.js +++ b/src/editors/containers/ProblemEditor/data/OLXParser.js @@ -738,4 +738,13 @@ export class OLXParser { groupFeedbackList, }; } + + getBetaParsedOLXData() { + /* TODO: Replace olxParser.getParsedOLXData() with new parser function + * and remove console.log() + */ + // eslint-disable-next-line no-console + console.log('Should default to the advanced editor'); + return this.getParsedOLXData(); + } } diff --git a/src/editors/data/redux/thunkActions/problem.js b/src/editors/data/redux/thunkActions/problem.js index 9edf656b5..16bebedf6 100644 --- a/src/editors/data/redux/thunkActions/problem.js +++ b/src/editors/data/redux/thunkActions/problem.js @@ -28,9 +28,14 @@ export const isBlankProblem = ({ rawOLX }) => { export const getDataFromOlx = ({ rawOLX, rawSettings, defaultSettings }) => { let olxParser; let parsedProblem; + const { default_to_advanced: defaultToAdvanced } = rawSettings; try { olxParser = new OLXParser(rawOLX); - parsedProblem = olxParser.getParsedOLXData(); + if (defaultToAdvanced) { + parsedProblem = olxParser.getBetaParsedOLXData(); + } else { + parsedProblem = olxParser.getParsedOLXData(); + } } catch (error) { // eslint-disable-next-line no-console console.error('The Problem Could Not Be Parsed from OLX. redirecting to Advanced editor.', error);