From 50c580cca2b403137b637144fdb7b72a0d077067 Mon Sep 17 00:00:00 2001 From: Jesper Hodge <19345795+jesperhodge@users.noreply.github.com> Date: Wed, 20 Dec 2023 16:44:27 -0500 Subject: [PATCH] fix editor deleting description (#444) internal issue: https://2u-internal.atlassian.net/browse/TNL-11311 This fixes a bug where the editor was deleting the OLX tag when editing in the simple editor and then saving. Also the description was being converted to em for the simple editor, but then not converted back. However, the xblock renders label and then em in reverse order for some reason. To fix it, the em gets converted back to description now, but not for every em tag (added a class "olx_description" for the tags that should be converted). --- .../ProblemEditor/data/OLXParser.js | 7 +++- .../ProblemEditor/data/OLXParser.test.js | 2 +- .../ProblemEditor/data/ReactStateOLXParser.js | 41 ++++++++++++------- .../data/ReactStateOLXParser.test.js | 38 +++++++++++++++-- .../data/mockData/olxTestData.js | 12 +++--- 5 files changed, 75 insertions(+), 25 deletions(-) diff --git a/src/editors/containers/ProblemEditor/data/OLXParser.js b/src/editors/containers/ProblemEditor/data/OLXParser.js index ccedbefbf..918aa4958 100644 --- a/src/editors/containers/ProblemEditor/data/OLXParser.js +++ b/src/editors/containers/ProblemEditor/data/OLXParser.js @@ -487,7 +487,12 @@ export class OLXParser { } }); const questionString = this.richTextBuilder.build(questionArray); - return questionString.replace(//gm, '').replace(/<\/description>/gm, ''); + const res = this.replaceOlxDescriptionTag(questionString); + return res; + } + + replaceOlxDescriptionTag(questionString) { + return questionString.replace(//gm, '').replace(/<\/description>/gm, ''); } /** getHints() diff --git a/src/editors/containers/ProblemEditor/data/OLXParser.test.js b/src/editors/containers/ProblemEditor/data/OLXParser.test.js index 65a42eaba..ed5dbe83f 100644 --- a/src/editors/containers/ProblemEditor/data/OLXParser.test.js +++ b/src/editors/containers/ProblemEditor/data/OLXParser.test.js @@ -329,7 +329,7 @@ describe('OLXParser', () => { const olxparser = new OLXParser(labelDescriptionQuestionOLX.rawOLX); const problemType = olxparser.getProblemType(); const question = olxparser.parseQuestions(problemType); - it('should append the label/description to the question', () => { + it('should append the label/description to the question, converting description to with "olx_description" class', () => { expect(question.trim()).toBe(labelDescriptionQuestionOLX.question); }); }); diff --git a/src/editors/containers/ProblemEditor/data/ReactStateOLXParser.js b/src/editors/containers/ProblemEditor/data/ReactStateOLXParser.js index 4532308b0..8b0f01d1f 100644 --- a/src/editors/containers/ProblemEditor/data/ReactStateOLXParser.js +++ b/src/editors/containers/ProblemEditor/data/ReactStateOLXParser.js @@ -193,29 +193,31 @@ class ReactStateOLXParser { /** addQuestion() * The editorObject saved to the class constuctor is parsed for the attribute question. The question is parsed and - * checked for label tags. After the question is fully updated, the questionObject is returned. + * checked for label and em tags. After the question is fully updated, the questionObject is returned. + * TODO: this is very brittle and unreliable. Needs improvement. * @return {object} object representaion of question */ addQuestion() { const { question } = this.editorObject; const questionObject = this.richTextParser.parse(question); - /* Removes block tags like

or

that surround the