Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Link-on-Paste for V2 Library Components #1202

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 (18)

'upstreamInfo' is missing in props validation

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

View workflow job for this annotation

GitHub Actions / tests (20)

'upstreamInfo' is missing in props validation
handleConfigureSubmit, validationMessages, ...props
}) => {
const courseXBlockElementRef = useRef(null);
Expand Down Expand Up @@ -126,6 +126,14 @@
<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 (18)

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

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

View workflow job for this annotation

GitHub Actions / tests (20)

'&&' 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 (18)

Missing parentheses around multilines JSX

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

View workflow job for this annotation

GitHub Actions / tests (20)

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 (18)

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 (18)

'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 (18)

'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 (20)

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 (20)

'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 (20)

'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 (18)

Unexpected newline before '}'

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

View workflow job for this annotation

GitHub Actions / tests (20)

Unexpected newline before '}'
</Dropdown.Menu>
</Dropdown>
<DeleteModal
Expand Down Expand Up @@ -170,6 +178,7 @@
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 @@
parent_locator: parentLocator,
display_name: displayName,
staged_content: stagedContent,
link_to_upstream: true,

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

View workflow job for this annotation

GitHub Actions / tests (18)

Unexpected tab character

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

View workflow job for this annotation

GitHub Actions / tests (18)

Expected indentation of 4 spaces but found 1 tab

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

View workflow job for this annotation

GitHub Actions / tests (20)

Unexpected tab character

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

View workflow job for this annotation

GitHub Actions / tests (20)

Expected indentation of 4 spaces but found 1 tab
};

const { data } = await getAuthenticatedHttpClient()
Expand Down Expand Up @@ -149,6 +150,16 @@
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 @@
}),
};
},
syncXBlock: (state, { payload }) => {},

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

View workflow job for this annotation

GitHub Actions / tests (18)

'state' is defined but never used

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

View workflow job for this annotation

GitHub Actions / tests (20)

'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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use isLibraryKey

Suggested change
const textt = (clipboardData.sourceContextTitle || "").startsWith("lib:") ? "Link library component from clipboard" : text;
const textt = isLibraryKey(clipboardData.sourceContextTitle) ? "Link library component from clipboard" /* TODO: needs i18n */ : text;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

return (
<>
<PasteButton className={className} onClick={onClick} text={text} />
<PasteButton className={className} onClick={onClick} text={textt} />
<OverlayTrigger
show={showPopover}
overlay={renderPopover}
Expand Down
Loading