Skip to content

Commit 9cfd1f0

Browse files
bradenmacdonaldAnas12091101
authored andcommitted
fix: (backport) enable markdown editor in libraries (openedx#2098)
* fix: enable markdown editor for problems in libraries too This fix is also achieved on master via 5991fd3 / openedx#2068 but this is a simpler fix, not a direct backport of that refactor. * fix: remove duplicate markdown_edited save request (openedx#2127) Removes the unnecessary duplicate save request of markdown_edited value to the backend. Part of: openedx#2099 Backports: 62589ae --------- Co-authored-by: Muhammad Anas <[email protected]>
1 parent 2e813e4 commit 9cfd1f0

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

src/editors/data/redux/thunkActions/problem.test.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
} from './problem';
1111
import { checkboxesOLXWithFeedbackAndHintsOLX, advancedProblemOlX, blankProblemOLX } from '../../../containers/ProblemEditor/data/mockData/olxTestData';
1212
import { ProblemTypeKeys } from '../../constants/problem';
13-
import * as requests from './requests';
1413

1514
const mockOlx = 'SOmEVALue';
1615
const mockBuildOlx = jest.fn(() => mockOlx);
@@ -72,22 +71,13 @@ describe('problem thunkActions', () => {
7271
);
7372
});
7473
test('switchToMarkdownEditor dispatches correct actions', () => {
75-
switchToMarkdownEditor()(dispatch, getState);
74+
switchToMarkdownEditor()(dispatch);
7675

7776
expect(dispatch).toHaveBeenCalledWith(
7877
actions.problem.updateField({
7978
isMarkdownEditorEnabled: true,
8079
}),
8180
);
82-
83-
expect(dispatch).toHaveBeenCalledWith(
84-
requests.saveBlock({
85-
content: {
86-
settings: { markdown_edited: true },
87-
olx: blockValue.data.data,
88-
},
89-
}),
90-
);
9181
});
9282

9383
describe('switchEditor', () => {
@@ -110,7 +100,7 @@ describe('problem thunkActions', () => {
110100

111101
test('dispatches switchToMarkdownEditor when editorType is markdown', () => {
112102
switchEditor('markdown')(dispatch, getState);
113-
expect(switchToMarkdownEditorMock).toHaveBeenCalledWith(dispatch, getState);
103+
expect(switchToMarkdownEditorMock).toHaveBeenCalledWith(dispatch);
114104
});
115105
});
116106

src/editors/data/redux/thunkActions/problem.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ export const switchToAdvancedEditor = () => (dispatch, getState) => {
2424
dispatch(actions.problem.updateField({ problemType: ProblemTypeKeys.ADVANCED, rawOLX }));
2525
};
2626

27-
export const switchToMarkdownEditor = () => (dispatch, getState) => {
28-
const state = getState();
27+
export const switchToMarkdownEditor = () => (dispatch) => {
2928
dispatch(actions.problem.updateField({ isMarkdownEditorEnabled: true }));
30-
const { blockValue } = state.app;
31-
const olx = get(blockValue, 'data.data', '');
32-
const content = { settings: { markdown_edited: true }, olx };
33-
// Sending a request to save the problem block with the updated markdown_edited value
34-
dispatch(requests.saveBlock({ content }));
3529
};
3630

37-
export const switchEditor = (editorType) => (dispatch, getState) => (editorType === 'advanced' ? switchToAdvancedEditor : switchToMarkdownEditor)()(dispatch, getState);
31+
export const switchEditor = (editorType) => (dispatch, getState) => {
32+
if (editorType === 'advanced') {
33+
switchToAdvancedEditor()(dispatch, getState);
34+
} else {
35+
switchToMarkdownEditor()(dispatch);
36+
}
37+
};
3838

3939
export const isBlankProblem = ({ rawOLX }) => {
4040
if (['<problem></problem>', '<problem/>'].includes(rawOLX.replace(/\s/g, ''))) {

src/library-authoring/components/ComponentEditorModal.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { getConfig } from '@edx/frontend-platform';
22
import React from 'react';
3-
3+
import { useSelector } from 'react-redux';
44
import { useQueryClient } from '@tanstack/react-query';
5+
6+
import { getWaffleFlags } from '../../data/selectors';
57
import EditorPage from '../../editors/EditorPage';
68
import { getBlockType } from '../../generic/key-utils';
79
import { useLibraryContext } from '../common/context/LibraryContext';
@@ -21,6 +23,7 @@ export function canEditComponent(usageKey: string): boolean {
2123
export const ComponentEditorModal: React.FC<Record<never, never>> = () => {
2224
const { componentBeingEdited, closeComponentEditor, libraryId } = useLibraryContext();
2325
const queryClient = useQueryClient();
26+
const { useReactMarkdownEditor } = useSelector(getWaffleFlags);
2427

2528
if (componentBeingEdited === undefined) {
2629
return null;
@@ -37,6 +40,7 @@ export const ComponentEditorModal: React.FC<Record<never, never>> = () => {
3740
courseId={libraryId}
3841
blockType={blockType}
3942
blockId={componentBeingEdited.usageKey}
43+
isMarkdownEditorEnabledForCourse={useReactMarkdownEditor}
4044
studioEndpointUrl={getConfig().STUDIO_BASE_URL}
4145
lmsEndpointUrl={getConfig().LMS_BASE_URL}
4246
onClose={onClose}

0 commit comments

Comments
 (0)