Skip to content

Commit

Permalink
refactor: after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang committed May 7, 2024
1 parent cacc6af commit cc0f5d6
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 70 deletions.
11 changes: 4 additions & 7 deletions src/course-unit/CourseUnit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { useIntl, injectIntl } from '@edx/frontend-platform/i18n';
import { DraggableList, ErrorAlert } from '@edx/frontend-lib-content-components';
import {
Warning as WarningIcon,
ArrowDropDown as ArrowDownIcon,
ArrowDropUp as ArrowUpIcon,
CheckCircle as CheckCircleIcon,
} from '@openedx/paragon/icons';
import { SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable';
Expand Down Expand Up @@ -67,9 +65,6 @@ const CourseUnit = ({ courseId }) => {
courseVerticalChildren,
handleXBlockDragAndDrop,
canPasteComponent,
isXBlocksExpanded,
isXBlocksRendered,
handleExpandAll,
movedXBlockParams,
handleRollbackMovedXBlock,
handleCloseXBlockMovedAlert,
Expand Down Expand Up @@ -142,6 +137,9 @@ const CourseUnit = ({ courseId }) => {
/>
) : null}
</TransitionReplace>
<ErrorAlert hideHeading isError={savingStatus === RequestStatus.FAILED && isErrorAlert}>
{intl.formatMessage(messages.alertFailedGeneric, { actionName: 'save', type: 'changes' })}
</ErrorAlert>
<SubHeader
hideBorder
title={(
Expand Down Expand Up @@ -203,7 +201,7 @@ const CourseUnit = ({ courseId }) => {
strategy={verticalListSortingStrategy}
>
{unitXBlocks.map(({
name, id, blockType: type, shouldScroll, userPartitionInfo, validationMessages, actions,
name, id, blockType: type, shouldScroll, userPartitionInfo, validationMessages,
}) => (
<CourseXBlock
id={id}
Expand All @@ -217,7 +215,6 @@ const CourseUnit = ({ courseId }) => {
unitXBlockActions={unitXBlockActions}
data-testid="course-xblock"
userPartitionInfo={userPartitionInfo}
actions={actions}
/>
))}
</SortableContext>
Expand Down
58 changes: 18 additions & 40 deletions src/course-unit/course-xblock/CourseXBlock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,41 @@ import {
import { EditOutline as EditIcon, MoreVert as MoveVertIcon } from '@openedx/paragon/icons';
import { useIntl } from '@edx/frontend-platform/i18n';
import { useNavigate, useSearchParams } from 'react-router-dom';
import { find } from 'lodash';
import classNames from 'classnames';

import { useOverflowControl } from '../../generic/hooks';
import DeleteModal from '../../generic/delete-modal/DeleteModal';
import ConfigureModal from '../../generic/configure-modal/ConfigureModal';
import SortableItem from '../../generic/drag-helper/SortableItem';
import { scrollToElement } from '../../course-outline/utils';
import { COURSE_BLOCK_NAMES } from '../../constants';
import { getCourseId } from '../data/selectors';
import { getCanEdit, getCourseId } from '../data/selectors';
import { copyToClipboard } from '../../generic/data/thunks';
import { fetchCourseVerticalChildrenData } from '../data/thunk';
import { fetchCourseUnitQuery, fetchCourseVerticalChildrenData } from '../data/thunk';
import { updateMovedXBlockParams } from '../data/slice';
import { COMPONENT_TYPES } from '../constants';
import XBlockMessages from './xblock-messages/XBlockMessages';
import messages from './messages';
import { extractStylesWithContent, getXBlockActionsBasePath } from './utils';
import { getXBlockActionsBasePath } from './utils';
import CourseIFrame from './CourseIFrame';

const XBLOCK_LEGACY_MODAL_CLASS_NAME = 'xblock-edit-modal';

const CourseXBlock = ({
id, title, type, unitXBlockActions, shouldScroll, userPartitionInfo,
handleConfigureSubmit, validationMessages, renderError, actions, blockId, ...props
handleConfigureSubmit, validationMessages, renderError, blockId, ...props
}) => {
const courseXBlockElementRef = useRef(null);
const [isDeleteModalOpen, openDeleteModal, closeDeleteModal] = useToggle(false);
const [isConfigureModalOpen, openConfigureModal, closeConfigureModal] = useToggle(false);
const dispatch = useDispatch();
const navigate = useNavigate();
const canEdit = useSelector(getCanEdit);
const courseId = useSelector(getCourseId);
const intl = useIntl();
const [showLegacyEditModal, toggleLegacyEditModal] = useState(false);
const [showLegacyMoveModal, toggleLegacyMoveModal] = useState(false);
const xblockLegacyModalRef = useRef(null);

const {
canCopy, canDelete, canDuplicate, canManageAccess, canMove,
} = actions;

useOverflowControl(`.${XBLOCK_LEGACY_MODAL_CLASS_NAME}`);

useEffect(() => {
Expand All @@ -57,7 +52,6 @@ const CourseXBlock = ({
if (method === 'close_modal') {
toggleLegacyEditModal(false);
dispatch(fetchCourseVerticalChildrenData(blockId));
dispatch(fetchXBlockIFrameHtmlAndResourcesQuery(id));
dispatch(fetchCourseUnitQuery(blockId));
} else if (method === 'move_xblock') {
toggleLegacyMoveModal(false);
Expand Down Expand Up @@ -193,31 +187,23 @@ const CourseXBlock = ({
iconAs={Icon}
/>
<Dropdown.Menu>
{canDuplicate && (
<Dropdown.Item onClick={() => unitXBlockActions.handleDuplicate(id)}>
{intl.formatMessage(messages.blockLabelButtonDuplicate)}
</Dropdown.Item>
)}
{canMove && (
<Dropdown.Item onClick={handleXBlockMove}>
{intl.formatMessage(messages.blockLabelButtonMove)}
</Dropdown.Item>
)}
{canCopy && (
<Dropdown.Item onClick={() => unitXBlockActions.handleDuplicate(id)}>
{intl.formatMessage(messages.blockLabelButtonDuplicate)}
</Dropdown.Item>
<Dropdown.Item onClick={handleXBlockMove}>
{intl.formatMessage(messages.blockLabelButtonMove)}
</Dropdown.Item>
{canEdit && (
<Dropdown.Item onClick={() => dispatch(copyToClipboard(id))}>
{intl.formatMessage(messages.blockLabelButtonCopyToClipboard)}
</Dropdown.Item>
)}
{canManageAccess && (
<Dropdown.Item onClick={openConfigureModal}>
{intl.formatMessage(messages.blockLabelButtonManageAccess)}
</Dropdown.Item>
)}
{canDelete && (
<Dropdown.Item onClick={openDeleteModal}>
{intl.formatMessage(messages.blockLabelButtonDelete)}
</Dropdown.Item>
)}
<Dropdown.Item onClick={openConfigureModal}>
{intl.formatMessage(messages.blockLabelButtonManageAccess)}
</Dropdown.Item>
<Dropdown.Item onClick={openDeleteModal}>
{intl.formatMessage(messages.blockLabelButtonDelete)}
</Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
<DeleteModal
Expand Down Expand Up @@ -283,14 +269,6 @@ CourseXBlock.propTypes = {
selectedGroupsLabel: PropTypes.string,
}).isRequired,
handleConfigureSubmit: PropTypes.func.isRequired,
actions: PropTypes.shape({
canCopy: PropTypes.bool,
canDelete: PropTypes.bool,
canDuplicate: PropTypes.bool,
canManageAccess: PropTypes.bool,
canManageTags: PropTypes.bool,
canMove: PropTypes.bool,
}).isRequired,
};

export default CourseXBlock;
20 changes: 1 addition & 19 deletions src/course-unit/course-xblock/utils.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
import { getConfig } from '@edx/frontend-platform';

import { STYLE_TAG_PATTERN } from './constants';

/**
* Extracts content of <style> tags from the given HTML string.
* @param {string} htmlString - The HTML string to extract styles from.
* @returns {string[]} An array containing the content of <style> tags.
*/
export function extractStylesWithContent(htmlString) {
const matches = [];
let match = STYLE_TAG_PATTERN.exec(htmlString);

while (match !== null) {
matches.push(match[1]); // Pushing content of <style> tag
match = STYLE_TAG_PATTERN.exec(htmlString);
}

return matches;
}

/**
* Retrieves the base path for XBlock actions.
* @param {string} xblockId - The ID of the XBlock.
* @returns {string} The base path for XBlock actions.
*/
// eslint-disable-next-line import/prefer-default-export
export function getXBlockActionsBasePath(xblockId) {
return `${getConfig().STUDIO_BASE_URL}/xblock/${xblockId}/actions`;
}
1 change: 0 additions & 1 deletion src/course-unit/data/slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ export const {
duplicateXBlock,
fetchStaticFileNoticesSuccess,
reorderXBlockList,
fetchXBlockIFrameResources,
updateMovedXBlockParams,
} = slice.actions;

Expand Down
2 changes: 1 addition & 1 deletion src/course-unit/data/thunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export function rollbackUnitItemQuery(itemId, xblockId, title) {
dispatch(updateMovedXBlockParams({ title, isSuccess: true, isUndo: true }));
} catch (error) {
dispatch(hideProcessingNotification());
handleResponseErrors(error, dispatch, updateSavingStatus);
dispatch(updateSavingStatus({ status: RequestStatus.FAILED }));
}
};
}
Expand Down
2 changes: 0 additions & 2 deletions src/course-unit/hooks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ export const useCourseUnit = ({ courseId, blockId }) => {
const courseUnit = useSelector(getCourseUnitData);
const savingStatus = useSelector(getSavingStatus);
const isLoading = useSelector(getIsLoading);
const isLoadingFailed = useSelector(getIsLoadingFailed);
const errorMessage = useSelector(getErrorMessage);
const movedXBlockParams = useSelector(getMovedXBlockParams);
const sequenceStatus = useSelector(getSequenceStatus);
const { draftPreviewLink, publishedPreviewLink } = useSelector(getCourseSectionVertical);
Expand Down

0 comments on commit cc0f5d6

Please sign in to comment.