Skip to content

Commit

Permalink
feat: upstream link & sync prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
kdmccormick committed Aug 16, 2024
1 parent 95ac098 commit 4324413
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/course-unit/CourseUnit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}) => (
<CourseXBlock
id={id}
Expand All @@ -173,6 +173,7 @@ const CourseUnit = ({ courseId }) => {
unitXBlockActions={unitXBlockActions}
data-testid="course-xblock"
userPartitionInfo={userPartitionInfo}
upstreamInfo={upstreamInfo}
/>
))}
</SortableContext>
Expand Down
11 changes: 10 additions & 1 deletion src/course-unit/course-xblock/CourseXBlock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Check failure on line 24 in src/course-unit/course-xblock/CourseXBlock.jsx

View workflow job for this annotation

GitHub Actions / tests

'upstreamInfo' is missing in props validation
handleConfigureSubmit, validationMessages, ...props
}) => {
const courseXBlockElementRef = useRef(null);
Expand Down Expand Up @@ -126,6 +126,14 @@ const CourseXBlock = ({
<Dropdown.Item onClick={openDeleteModal}>
{intl.formatMessage(messages.blockLabelButtonDelete)}
</Dropdown.Item>
{upstreamInfo &&

Check failure on line 129 in src/course-unit/course-xblock/CourseXBlock.jsx

View workflow job for this annotation

GitHub Actions / tests

'&&' should be placed at the beginning of the line
<>

Check failure on line 130 in src/course-unit/course-xblock/CourseXBlock.jsx

View workflow job for this annotation

GitHub Actions / tests

Missing parentheses around multilines JSX
<Dropdown.Divider />
<Dropdown.Item disabled={!upstreamInfo.syncUrl} onClick={() => unitXBlockActions.handleSync(id, upstreamInfo.syncUrl)}>

Check failure on line 132 in src/course-unit/course-xblock/CourseXBlock.jsx

View workflow job for this annotation

GitHub Actions / tests

This line has a length of 141. Maximum allowed is 120

Check failure on line 132 in src/course-unit/course-xblock/CourseXBlock.jsx

View workflow job for this annotation

GitHub Actions / tests

'upstreamInfo.syncUrl' is missing in props validation

Check failure on line 132 in src/course-unit/course-xblock/CourseXBlock.jsx

View workflow job for this annotation

GitHub Actions / tests

'upstreamInfo.syncUrl' is missing in props validation
Update from library
</Dropdown.Item>
</>
}

Check failure on line 136 in src/course-unit/course-xblock/CourseXBlock.jsx

View workflow job for this annotation

GitHub Actions / tests

Unexpected newline before '}'
</Dropdown.Menu>
</Dropdown>
<DeleteModal
Expand Down Expand Up @@ -170,6 +178,7 @@ CourseXBlock.propTypes = {
unitXBlockActions: PropTypes.shape({
handleDelete: PropTypes.func,
handleDuplicate: PropTypes.func,
handleSync: PropTypes.func,
}).isRequired,
userPartitionInfo: PropTypes.shape({
selectablePartitions: PropTypes.arrayOf(PropTypes.shape({
Expand Down
11 changes: 11 additions & 0 deletions src/course-unit/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export async function createCourseXblock({
parent_locator: parentLocator,
display_name: displayName,
staged_content: stagedContent,
link_if_library_content: true,

Check failure on line 77 in src/course-unit/data/api.js

View workflow job for this annotation

GitHub Actions / tests

Unexpected tab character

Check failure on line 77 in src/course-unit/data/api.js

View workflow job for this annotation

GitHub Actions / tests

Expected indentation of 4 spaces but found 1 tab
};

const { data } = await getAuthenticatedHttpClient()
Expand Down Expand Up @@ -149,6 +150,16 @@ export async function duplicateUnitItem(itemId, XBlockId) {
return data;
}

/**
* Sync a unit item to its upstream library item.
* @param {string} itemId
* @returns {Promise<Object>}
*/
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.
Expand Down
1 change: 1 addition & 0 deletions src/course-unit/data/slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const slice = createSlice({
}),
};
},
syncXBlock: (state, { payload }) => {},

Check failure on line 103 in src/course-unit/data/slice.js

View workflow job for this annotation

GitHub Actions / tests

'state' is defined but never used
fetchStaticFileNoticesSuccess: (state, { payload }) => {
state.staticFileNotices = payload;
},
Expand Down
19 changes: 19 additions & 0 deletions src/course-unit/data/thunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
handleCourseUnitVisibilityAndData,
deleteUnitItem,
duplicateUnitItem,
syncUnitItem,
setXBlockOrderList,
} from './api';
import {
Expand Down Expand Up @@ -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 }));
Expand Down
4 changes: 4 additions & 0 deletions src/course-unit/hooks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
fetchCourseVerticalChildrenData,
deleteUnitItemQuery,
duplicateUnitItemQuery,
syncUnitItemQuery,
setXBlockOrderListQuery,
editCourseUnitVisibilityAndData,
} from './data/thunk';
Expand Down Expand Up @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions src/generic/clipboard/paste-component/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ const PasteComponent = ({
</Popover>
</div>
);

const textt = (clipboardData.sourceContextTitle || "").startsWith("lib:") ? "Link library component from clipboard" : text;
return (
<>
<PasteButton className={className} onClick={onClick} text={text} />
<PasteButton className={className} onClick={onClick} text={textt} />
<OverlayTrigger
show={showPopover}
overlay={renderPopover}
Expand Down

0 comments on commit 4324413

Please sign in to comment.