diff --git a/src/course-unit/CourseUnit.test.jsx b/src/course-unit/CourseUnit.test.jsx
index 6d64615de..1fae368da 100644
--- a/src/course-unit/CourseUnit.test.jsx
+++ b/src/course-unit/CourseUnit.test.jsx
@@ -243,7 +243,7 @@ describe('', () => {
);
simulatePostMessageEvent(messageTypes.deleteXBlock, {
- id: courseVerticalChildrenMock.children[0].block_id,
+ usageId: courseVerticalChildrenMock.children[0].block_id,
});
expect(getByText(/Delete this component?/i)).toBeInTheDocument();
@@ -257,10 +257,10 @@ describe('', () => {
const deleteButton = getAllByRole('button', { name: /Delete/i })
.find(({ classList }) => classList.contains('btn-primary'));
- userEvent.click(cancelButton);
+ expect(cancelButton).toBeInTheDocument();
simulatePostMessageEvent(messageTypes.deleteXBlock, {
- id: courseVerticalChildrenMock.children[0].block_id,
+ usageId: courseVerticalChildrenMock.children[0].block_id,
});
expect(getByRole('dialog')).toBeInTheDocument();
@@ -296,8 +296,12 @@ describe('', () => {
axiosMock
.onDelete(getXBlockBaseApiUrl(courseVerticalChildrenMock.children[0].block_id))
- .replyOnce(200, { dummy: 'value' });
- await executeThunk(deleteUnitItemQuery(courseId, blockId), store.dispatch);
+ .reply(200, { dummy: 'value' });
+ await executeThunk(deleteUnitItemQuery(
+ courseId,
+ courseVerticalChildrenMock.children[0].block_id,
+ simulatePostMessageEvent,
+ ), store.dispatch);
const updatedCourseVerticalChildren = courseVerticalChildrenMock.children.filter(
child => child.block_id !== courseVerticalChildrenMock.children[0].block_id,
@@ -1617,6 +1621,8 @@ describe('', () => {
callbackFn: requestData.callbackFn,
}), store.dispatch);
+ simulatePostMessageEvent(messageTypes.rollbackMovedXBlock, { locator: requestData.sourceLocator });
+
const dismissButton = queryByRole('button', {
name: /dismiss/i, hidden: true,
});
diff --git a/src/course-unit/data/thunk.js b/src/course-unit/data/thunk.js
index b0f693074..464111ed2 100644
--- a/src/course-unit/data/thunk.js
+++ b/src/course-unit/data/thunk.js
@@ -9,6 +9,7 @@ import { RequestStatus } from '../../data/constants';
import { NOTIFICATION_MESSAGES } from '../../constants';
import { updateModel, updateModels } from '../../generic/model-store';
import { updateClipboardData } from '../../generic/data/slice';
+import { messageTypes } from '../constants';
import {
getCourseUnitData,
editUnitDisplayName,
@@ -162,7 +163,7 @@ export function editCourseUnitVisibilityAndData(
};
}
-export function createNewCourseXBlock(body, callback, blockId) {
+export function createNewCourseXBlock(body, callback, blockId, sendMessageToIframe) {
return async (dispatch) => {
if (body.stagedContent) {
dispatch(showProcessingNotification(NOTIFICATION_MESSAGES.pasting));
@@ -191,6 +192,8 @@ export function createNewCourseXBlock(body, callback, blockId) {
dispatch(hideProcessingNotification());
if (callback) {
callback(result);
+ } else {
+ sendMessageToIframe(messageTypes.addXBlock, { data: result });
}
const currentBlockId = body.category === 'vertical' ? formattedResult.locator : blockId;
const courseUnit = await getCourseUnitData(currentBlockId);
@@ -219,14 +222,14 @@ export function fetchCourseVerticalChildrenData(itemId) {
};
}
-export function deleteUnitItemQuery(itemId, xblockId, callback) {
+export function deleteUnitItemQuery(itemId, xblockId, sendMessageToIframe) {
return async (dispatch) => {
dispatch(updateSavingStatus({ status: RequestStatus.PENDING }));
dispatch(showProcessingNotification(NOTIFICATION_MESSAGES.deleting));
try {
await deleteUnitItem(xblockId);
- callback();
+ sendMessageToIframe(messageTypes.completeXBlockDeleting, null);
const { userClipboard } = await getCourseSectionVerticalData(itemId);
dispatch(updateClipboardData(userClipboard));
const courseUnit = await getCourseUnitData(itemId);
@@ -301,8 +304,12 @@ export function patchUnitItemQuery({
dispatch(updateMovedXBlockParams(xBlockParams));
dispatch(updateCourseOutlineInfo({}));
dispatch(updateCourseOutlineInfoLoadingStatus({ status: RequestStatus.IN_PROGRESS }));
- const courseUnit = await getCourseUnitData(currentParentLocator);
- dispatch(fetchCourseItemSuccess(courseUnit));
+ try {
+ const courseUnit = await getCourseUnitData(currentParentLocator);
+ dispatch(fetchCourseItemSuccess(courseUnit));
+ } catch (error) {
+ handleResponseErrors(error, dispatch, updateSavingStatus);
+ }
callbackFn(sourceLocator);
} catch (error) {
handleResponseErrors(error, dispatch, updateSavingStatus);
diff --git a/src/course-unit/hooks.jsx b/src/course-unit/hooks.jsx
index 7fb8edaff..d28aaa600 100644
--- a/src/course-unit/hooks.jsx
+++ b/src/course-unit/hooks.jsx
@@ -113,22 +113,13 @@ export const useCourseUnit = ({ courseId, blockId }) => {
}
};
- const handleCreateNewCourseXBlock = (
- body,
- callback = (result) => {
- sendMessageToIframe(messageTypes.addXBlock, { data: result });
- },
- ) => (
- dispatch(createNewCourseXBlock(body, callback, blockId))
+ const handleCreateNewCourseXBlock = (body, callback) => (
+ dispatch(createNewCourseXBlock(body, callback, blockId, sendMessageToIframe))
);
const unitXBlockActions = {
handleDelete: (XBlockId) => {
- dispatch(deleteUnitItemQuery(
- blockId,
- XBlockId,
- () => sendMessageToIframe(messageTypes.completeXBlockDeleting, null),
- ));
+ dispatch(deleteUnitItemQuery(blockId, XBlockId, sendMessageToIframe));
},
handleDuplicate: (XBlockId) => {
dispatch(duplicateUnitItemQuery(