diff --git a/src/course-unit/CourseUnit.jsx b/src/course-unit/CourseUnit.jsx index 2b54f876e6..a6fd8ecb79 100644 --- a/src/course-unit/CourseUnit.jsx +++ b/src/course-unit/CourseUnit.jsx @@ -159,7 +159,7 @@ const CourseUnit = ({ courseId }) => { strategy={verticalListSortingStrategy} > {unitXBlocks.map(({ - name, id, blockType: type, shouldScroll, userPartitionInfo, validationMessages, + name, id, blockType: type, shouldScroll, userPartitionInfo, upstreamInfo, validationMessages, }) => ( { unitXBlockActions={unitXBlockActions} data-testid="course-xblock" userPartitionInfo={userPartitionInfo} + upstreamInfo={upstreamInfo} /> ))} diff --git a/src/course-unit/course-xblock/CourseXBlock.jsx b/src/course-unit/course-xblock/CourseXBlock.jsx index 2d8f6221e8..63cddfeff9 100644 --- a/src/course-unit/course-xblock/CourseXBlock.jsx +++ b/src/course-unit/course-xblock/CourseXBlock.jsx @@ -21,7 +21,7 @@ import XBlockMessages from './xblock-messages/XBlockMessages'; import messages from './messages'; const CourseXBlock = ({ - id, title, type, unitXBlockActions, shouldScroll, userPartitionInfo, + id, title, type, unitXBlockActions, shouldScroll, userPartitionInfo, upstreamInfo, handleConfigureSubmit, validationMessages, ...props }) => { const courseXBlockElementRef = useRef(null); @@ -126,6 +126,14 @@ const CourseXBlock = ({ {intl.formatMessage(messages.blockLabelButtonDelete)} + {upstreamInfo && + <> + + unitXBlockActions.handleSync(id, upstreamInfo.syncUrl)}> + Update from library + + + } } + */ +export async function syncUnitItem(itemId, XBlockId, syncUrl) { + const { data } = await getAuthenticatedHttpClient().post(`${getStudioBaseUrl()}${syncUrl}`); + return data; +} + /** * Sets the order list of XBlocks. * @param {string} blockId - The identifier of the course unit. diff --git a/src/course-unit/data/slice.js b/src/course-unit/data/slice.js index f0d5f8c3aa..69fa2f9a7f 100644 --- a/src/course-unit/data/slice.js +++ b/src/course-unit/data/slice.js @@ -100,6 +100,7 @@ const slice = createSlice({ }), }; }, + syncXBlock: (state, { payload }) => {}, fetchStaticFileNoticesSuccess: (state, { payload }) => { state.staticFileNotices = payload; }, diff --git a/src/course-unit/data/thunk.js b/src/course-unit/data/thunk.js index c2ac2be7c8..9bbc162154 100644 --- a/src/course-unit/data/thunk.js +++ b/src/course-unit/data/thunk.js @@ -18,6 +18,7 @@ import { handleCourseUnitVisibilityAndData, deleteUnitItem, duplicateUnitItem, + syncUnitItem, setXBlockOrderList, } from './api'; import { @@ -250,6 +251,24 @@ export function duplicateUnitItemQuery(itemId, xblockId) { }; } +export function syncUnitItemQuery(itemId, xblockId, syncUrl) { + return async (dispatch) => { + dispatch(updateSavingStatus({ status: RequestStatus.PENDING })); + + try { + await syncUnitItem(itemId, xblockId, syncUrl); + const newCourseVerticalChildren = await getCourseVerticalChildren(itemId); + dispatch(syncXBlock({})); + dispatch(fetchCourseItemSuccess(courseUnit)); + dispatch(hideProcessingNotification()); + dispatch(updateSavingStatus({ status: RequestStatus.SUCCESSFUL })); + } catch (error) { + dispatch(hideProcessingNotification()); + handleResponseErrors(error, dispatch, updateSavingStatus); + } + }; +} + export function setXBlockOrderListQuery(blockId, xblockListIds, restoreCallback) { return async (dispatch) => { dispatch(updateSavingStatus({ status: RequestStatus.PENDING })); diff --git a/src/course-unit/hooks.jsx b/src/course-unit/hooks.jsx index 66182ef1fd..22d70c8b8e 100644 --- a/src/course-unit/hooks.jsx +++ b/src/course-unit/hooks.jsx @@ -11,6 +11,7 @@ import { fetchCourseVerticalChildrenData, deleteUnitItemQuery, duplicateUnitItemQuery, + syncUnitItemQuery, setXBlockOrderListQuery, editCourseUnitVisibilityAndData, } from './data/thunk'; @@ -105,6 +106,9 @@ export const useCourseUnit = ({ courseId, blockId }) => { handleDuplicate: (XBlockId) => { dispatch(duplicateUnitItemQuery(blockId, XBlockId)); }, + handleSync: (XBlockId, syncUrl) => { + dispatch(syncUnitItemQuery(blockId, XBlockId, syncUrl)); + }, }; const handleXBlockDragAndDrop = (xblockListIds, restoreCallback) => { diff --git a/src/generic/clipboard/paste-component/index.jsx b/src/generic/clipboard/paste-component/index.jsx index 4d74c771b6..0a18091dda 100644 --- a/src/generic/clipboard/paste-component/index.jsx +++ b/src/generic/clipboard/paste-component/index.jsx @@ -30,10 +30,10 @@ const PasteComponent = ({ ); - + const textt = (clipboardData.sourceContextTitle || "").startsWith("lib:") ? "Link library component from clipboard" : text; return ( <> - +