Skip to content

Commit d440394

Browse files
authored
fix: remove duplicate markdown_edited save request (openedx#2112)
Removes the unnecessary duplicate save request of markdown_edited value to the backend. Part of: openedx#2099 Will be backported to Teak.
1 parent 73ac6d7 commit d440394

2 files changed

Lines changed: 10 additions & 20 deletions

File tree

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, ''))) {

0 commit comments

Comments
 (0)