feat: [FC-0044] Course unit - Copy/paste functionality (#884)

Implement copy/paste.

Co-authored-by: monteri <36768631+monteri@users.noreply.github.com>
Co-authored-by: ihor-romaniuk <ihor.romaniuk@raccoongang.com>
This commit is contained in:
Peter Kulko
2024-04-24 21:27:29 +03:00
committed by GitHub
parent bef6796da4
commit 5686dee43b
69 changed files with 1621 additions and 404 deletions

View File

@@ -7,6 +7,7 @@ import {
import { RequestStatus } from '../../data/constants';
import { NOTIFICATION_MESSAGES } from '../../constants';
import { updateModel, updateModels } from '../../generic/model-store';
import { updateClipboardData } from '../../generic/data/slice';
import {
getCourseUnitData,
editUnitDisplayName,
@@ -32,6 +33,7 @@ import {
updateQueryPendingStatus,
deleteXBlock,
duplicateXBlock,
fetchStaticFileNoticesSuccess,
} from './slice';
import { getNotificationMessage } from './utils';
@@ -68,6 +70,9 @@ export function fetchCourseSectionVerticalData(courseId, sequenceId) {
modelType: 'units',
models: courseSectionVerticalData.units,
}));
dispatch(fetchStaticFileNoticesSuccess(JSON.parse(localStorage.getItem('staticFileNotices'))));
localStorage.removeItem('staticFileNotices');
dispatch(updateClipboardData(courseSectionVerticalData.userClipboard));
dispatch(fetchSequenceSuccess({ sequenceId }));
return true;
} catch (error) {
@@ -139,9 +144,14 @@ export function editCourseUnitVisibilityAndData(itemId, type, isVisible, groupAc
export function createNewCourseXBlock(body, callback, blockId) {
return async (dispatch) => {
dispatch(updateLoadingCourseXblockStatus({ status: RequestStatus.IN_PROGRESS }));
dispatch(showProcessingNotification(NOTIFICATION_MESSAGES.adding));
dispatch(updateSavingStatus({ status: RequestStatus.PENDING }));
if (body.stagedContent) {
dispatch(showProcessingNotification(NOTIFICATION_MESSAGES.pasting));
} else {
dispatch(showProcessingNotification(NOTIFICATION_MESSAGES.adding));
}
try {
await createCourseXblock(body).then(async (result) => {
if (result) {
@@ -150,6 +160,14 @@ export function createNewCourseXBlock(body, callback, blockId) {
const courseSectionVerticalData = await getCourseSectionVerticalData(formattedResult.locator);
dispatch(fetchCourseSectionVerticalDataSuccess(courseSectionVerticalData));
}
if (body.stagedContent) {
localStorage.setItem('staticFileNotices', JSON.stringify(formattedResult.staticFileNotices));
dispatch(fetchStaticFileNoticesSuccess(formattedResult.staticFileNotices));
if (body.parentLocator.includes('vertical')) {
localStorage.removeItem('staticFileNotices');
}
}
const courseVerticalChildrenData = await getCourseVerticalChildren(blockId);
dispatch(updateCourseVerticalChildren(courseVerticalChildrenData));
dispatch(hideProcessingNotification());
@@ -162,8 +180,6 @@ export function createNewCourseXBlock(body, callback, blockId) {
const courseUnit = await getCourseUnitData(currentBlockId);
dispatch(fetchCourseItemSuccess(courseUnit));
}
const courseUnit = await getCourseUnitData(blockId);
dispatch(fetchCourseItemSuccess(courseUnit));
});
} catch (error) {
dispatch(hideProcessingNotification());
@@ -195,6 +211,8 @@ export function deleteUnitItemQuery(itemId, xblockId) {
try {
await deleteUnitItem(xblockId);
dispatch(deleteXBlock(xblockId));
const { userClipboard } = await getCourseSectionVerticalData(itemId);
dispatch(updateClipboardData(userClipboard));
const courseUnit = await getCourseUnitData(itemId);
dispatch(fetchCourseItemSuccess(courseUnit));
dispatch(hideProcessingNotification());