fix: remove duplicate markdown_edited save request (#2112)

Removes the unnecessary duplicate save  request of markdown_edited
value to the backend.

Part of: https://github.com/openedx/frontend-app-authoring/issues/2099
Will be backported to Teak.
This commit is contained in:
Muhammad Anas
2025-06-10 16:59:23 +01:00
committed by GitHub
parent 73ac6d725a
commit d440394067
2 changed files with 10 additions and 20 deletions

View File

@@ -10,7 +10,6 @@ import {
} from './problem';
import { checkboxesOLXWithFeedbackAndHintsOLX, advancedProblemOlX, blankProblemOLX } from '../../../containers/ProblemEditor/data/mockData/olxTestData';
import { ProblemTypeKeys } from '../../constants/problem';
import * as requests from './requests';
const mockOlx = 'SOmEVALue';
const mockBuildOlx = jest.fn(() => mockOlx);
@@ -72,22 +71,13 @@ describe('problem thunkActions', () => {
);
});
test('switchToMarkdownEditor dispatches correct actions', () => {
switchToMarkdownEditor()(dispatch, getState);
switchToMarkdownEditor()(dispatch);
expect(dispatch).toHaveBeenCalledWith(
actions.problem.updateField({
isMarkdownEditorEnabled: true,
}),
);
expect(dispatch).toHaveBeenCalledWith(
requests.saveBlock({
content: {
settings: { markdown_edited: true },
olx: blockValue.data.data,
},
}),
);
});
describe('switchEditor', () => {
@@ -110,7 +100,7 @@ describe('problem thunkActions', () => {
test('dispatches switchToMarkdownEditor when editorType is markdown', () => {
switchEditor('markdown')(dispatch, getState);
expect(switchToMarkdownEditorMock).toHaveBeenCalledWith(dispatch, getState);
expect(switchToMarkdownEditorMock).toHaveBeenCalledWith(dispatch);
});
});

View File

@@ -24,17 +24,17 @@ export const switchToAdvancedEditor = () => (dispatch, getState) => {
dispatch(actions.problem.updateField({ problemType: ProblemTypeKeys.ADVANCED, rawOLX }));
};
export const switchToMarkdownEditor = () => (dispatch, getState) => {
const state = getState();
export const switchToMarkdownEditor = () => (dispatch) => {
dispatch(actions.problem.updateField({ isMarkdownEditorEnabled: true }));
const { blockValue } = state.app;
const olx = get(blockValue, 'data.data', '');
const content = { settings: { markdown_edited: true }, olx };
// Sending a request to save the problem block with the updated markdown_edited value
dispatch(requests.saveBlock({ content }));
};
export const switchEditor = (editorType) => (dispatch, getState) => (editorType === 'advanced' ? switchToAdvancedEditor : switchToMarkdownEditor)()(dispatch, getState);
export const switchEditor = (editorType) => (dispatch, getState) => {
if (editorType === 'advanced') {
switchToAdvancedEditor()(dispatch, getState);
} else {
switchToMarkdownEditor()(dispatch);
}
};
export const isBlankProblem = ({ rawOLX }) => {
if (['<problem></problem>', '<problem/>'].includes(rawOLX.replace(/\s/g, ''))) {