Skip to content

Commit

Permalink
refactor: remove unused code and do some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ihor-romaniuk committed Apr 23, 2024
1 parent 8778378 commit e5ba0f7
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 53 deletions.
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,5 @@
},
"peerDependencies": {
"decode-uri-component": ">=0.2.2"
},
"overrides": {
"react-intl": "^6.4.0"
}
}
2 changes: 1 addition & 1 deletion src/__mocks__/clipboardUnit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
content: {
id: 67,
userId: 3,
Expand Down
2 changes: 1 addition & 1 deletion src/__mocks__/clipboardXBlock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
content: {
id: 69,
userId: 3,
Expand Down
2 changes: 1 addition & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ export const CLIPBOARD_STATUS = {
error: 'error',
};

export const NOT_XBLOCK_TYPES = ['vertical', 'sequential', 'chapter', 'course'];
export const STRUCTURAL_XBLOCK_TYPES = ['vertical', 'sequential', 'chapter', 'course'];
39 changes: 17 additions & 22 deletions src/course-unit/CourseUnit.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import courseXBlockMessages from './course-xblock/messages';
import addComponentMessages from './add-component/messages';
import { PUBLISH_TYPES, UNIT_VISIBILITY_STATES } from './constants';
import messages from './messages';
import { copyToClipboard } from '../generic/data/thunks';
import { getContentTaxonomyTagsApiUrl, getContentTaxonomyTagsCountApiUrl } from '../content-tags-drawer/data/api';

let axiosMock;
Expand Down Expand Up @@ -1174,8 +1173,16 @@ describe('<CourseUnit />', () => {
user_clipboard: clipboardXBlock,
});

axiosMock
.onGet(getCourseUnitApiUrl(courseId))
.reply(200, {
...courseUnitIndexMock,
enable_copy_paste_units: true,
});

await executeThunk(fetchCourseUnitQuery(courseId), store.dispatch);
await executeThunk(fetchCourseSectionVerticalData(blockId), store.dispatch);
await executeThunk(copyToClipboard(blockId), store.dispatch);

expect(getByRole('button', { name: messages.pasteButtonText.defaultMessage })).toBeInTheDocument();
});

Expand All @@ -1191,20 +1198,17 @@ describe('<CourseUnit />', () => {
enable_copy_paste_units: true,
});

await executeThunk(fetchCourseUnitQuery(courseId), store.dispatch);

userEvent.click(getByRole('button', { name: sidebarMessages.actionButtonCopyUnitTitle.defaultMessage }));

axiosMock
.onGet(getCourseSectionVerticalApiUrl(blockId))
.reply(200, {
...courseSectionVerticalMock,
user_clipboard: clipboardUnit,
});

await executeThunk(fetchCourseUnitQuery(courseId), store.dispatch);
await executeThunk(fetchCourseSectionVerticalData(blockId), store.dispatch);
await executeThunk(copyToClipboard(blockId), store.dispatch);

userEvent.click(getByRole('button', { name: sidebarMessages.actionButtonCopyUnitTitle.defaultMessage }));
userEvent.click(getByRole('button', { name: courseSequenceMessages.pasteAsNewUnitLink.defaultMessage }));

let units = null;
Expand Down Expand Up @@ -1252,20 +1256,17 @@ describe('<CourseUnit />', () => {
enable_copy_paste_units: true,
});

await executeThunk(fetchCourseUnitQuery(courseId), store.dispatch);

userEvent.click(getByRole('button', { name: sidebarMessages.actionButtonCopyUnitTitle.defaultMessage }));

axiosMock
.onGet(getCourseSectionVerticalApiUrl(blockId))
.reply(200, {
...courseSectionVerticalMock,
user_clipboard: clipboardUnit,
});

await executeThunk(fetchCourseUnitQuery(courseId), store.dispatch);
await executeThunk(fetchCourseSectionVerticalData(blockId), store.dispatch);
await executeThunk(copyToClipboard(blockId), store.dispatch);

userEvent.click(getByRole('button', { name: sidebarMessages.actionButtonCopyUnitTitle.defaultMessage }));
userEvent.click(getByRole('button', { name: courseSequenceMessages.pasteAsNewUnitLink.defaultMessage }));

const updatedCourseSectionVerticalData = cloneDeep(courseSectionVerticalMock);
Expand Down Expand Up @@ -1316,20 +1317,17 @@ describe('<CourseUnit />', () => {
enable_copy_paste_units: true,
});

await executeThunk(fetchCourseUnitQuery(courseId), store.dispatch);

userEvent.click(getByRole('button', { name: sidebarMessages.actionButtonCopyUnitTitle.defaultMessage }));

axiosMock
.onGet(getCourseSectionVerticalApiUrl(blockId))
.reply(200, {
...courseSectionVerticalMock,
user_clipboard: clipboardUnit,
});

await executeThunk(fetchCourseUnitQuery(courseId), store.dispatch);
await executeThunk(fetchCourseSectionVerticalData(blockId), store.dispatch);
await executeThunk(copyToClipboard(blockId), store.dispatch);

userEvent.click(getByRole('button', { name: sidebarMessages.actionButtonCopyUnitTitle.defaultMessage }));
userEvent.click(getByRole('button', { name: courseSequenceMessages.pasteAsNewUnitLink.defaultMessage }));

const updatedCourseSectionVerticalData = cloneDeep(courseSectionVerticalMock);
Expand Down Expand Up @@ -1380,20 +1378,17 @@ describe('<CourseUnit />', () => {
enable_copy_paste_units: true,
});

await executeThunk(fetchCourseUnitQuery(courseId), store.dispatch);

userEvent.click(getByRole('button', { name: sidebarMessages.actionButtonCopyUnitTitle.defaultMessage }));

axiosMock
.onGet(getCourseSectionVerticalApiUrl(blockId))
.reply(200, {
...courseSectionVerticalMock,
user_clipboard: clipboardUnit,
});

await executeThunk(fetchCourseUnitQuery(courseId), store.dispatch);
await executeThunk(fetchCourseSectionVerticalData(blockId), store.dispatch);
await executeThunk(copyToClipboard(blockId), store.dispatch);

userEvent.click(getByRole('button', { name: sidebarMessages.actionButtonCopyUnitTitle.defaultMessage }));
userEvent.click(getByRole('button', { name: courseSequenceMessages.pasteAsNewUnitLink.defaultMessage }));

const updatedCourseSectionVerticalData = cloneDeep(courseSectionVerticalMock);
Expand Down
2 changes: 1 addition & 1 deletion src/course-unit/__mocks__/clipboardResponse.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
locator: 'block-v1:edX+DemoX+Demo_Course+type@vertical+block@vertical_0270f6de40fc',
courseKey: 'course-v1:edX+L153+3T2023',
staticFileNotices: {
Expand Down
14 changes: 14 additions & 0 deletions src/course-unit/clipboard/paste-notification/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,48 @@ const messages = defineMessages({
hasConflictingErrorsTitle: {
id: 'course-authoring.course-unit.paste-notification.has-conflicting-errors.title',
defaultMessage: 'Files need to be updated manually.',
description: 'Title for a notification indicating that files need manual updates '
+ 'due to a conflict in the clipboard.',
},
hasConflictingErrorsDescription: {
id: 'course-authoring.course-unit.paste-notification.has-conflicting-errors.description',
defaultMessage: 'The following files must be updated manually for components to work as intended:',
description: 'Description for the notification indicating which files need manual '
+ 'updates due to a clipboard conflict.',
},
hasConflictingErrorsButtonText: {
id: 'course-authoring.course-unit.paste-notification.has-conflicting-errors.button.text',
defaultMessage: 'Upload files',
description: 'Button text prompting users to upload files to resolve a clipboard conflict.',
},
hasErrorsTitle: {
id: 'course-authoring.course-unit.paste-notification.has-errors.title',
defaultMessage: 'Some errors occurred',
description: 'Title for a notification indicating that some errors occurred, likely '
+ 'related to file conflicts.',
},
hasErrorsDescription: {
id: 'course-authoring.course-unit.paste-notification.has-errors.description',
defaultMessage: 'The following required files could not be added to the course:',
description: 'Description for the notification indicating which required files '
+ 'couldn\'t be added to the course due to errors.',
},
hasNewFilesTitle: {
id: 'course-authoring.course-unit.paste-notification.has-new-files.title',
defaultMessage: 'New file(s) added to Files & Uploads.',
description: 'Title for a notification indicating that new files have been added to '
+ 'the Files & Uploads section.',
},
hasNewFilesDescription: {
id: 'course-authoring.course-unit.paste-notification.has-new-files.description',
defaultMessage: 'The following required files were imported to this course:',
description: 'Description for the notification indicating which required files '
+ 'were imported to the course.',
},
hasNewFilesButtonText: {
id: 'course-authoring.course-unit.paste-notification.has-new-files.button.text',
defaultMessage: 'View files',
description: 'Button text prompting users to view new files imported to the course.',
},
});

Expand Down
16 changes: 0 additions & 16 deletions src/course-unit/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,6 @@ import addComponentMessages from './add-component/messages';

export const UNIT_ICON_TYPES = ['video', 'other', 'vertical', 'problem', 'lock'];

export const NOT_XBLOCK_TYPES = ['vertical', 'sequential', 'chapter', 'course'];

export const STUDIO_CLIPBOARD_CHANNEL = 'studio_clipboard_channel';

/**
* Enum for clipboard status.
* @readonly
* @enum {string}
*/
export const CLIPBOARD_STATUS = {
loading: 'loading',
ready: 'ready',
expired: 'expired',
error: 'error',
};

export const COMPONENT_TYPES = {
advanced: 'advanced',
discussion: 'discussion',
Expand Down
2 changes: 1 addition & 1 deletion src/course-unit/data/slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const slice = createSlice({
},
unit: {},
courseSectionVertical: {},
courseVerticalChildren: {},
courseVerticalChildren: { children: [], isPublished: true },
staticFileNotices: {},
},
reducers: {
Expand Down
4 changes: 2 additions & 2 deletions src/generic/clipboard/hooks/useCopyToClipboard.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from 'react';
import { useSelector } from 'react-redux';

import { CLIPBOARD_STATUS, NOT_XBLOCK_TYPES, STUDIO_CLIPBOARD_CHANNEL } from '../../../constants';
import { CLIPBOARD_STATUS, STRUCTURAL_XBLOCK_TYPES, STUDIO_CLIPBOARD_CHANNEL } from '../../../constants';
import { getClipboardData } from '../../data/selectors';

/**
Expand All @@ -23,7 +23,7 @@ const useCopyToClipboard = (canEdit = true) => {
// Function to refresh the paste button's visibility
const refreshPasteButton = (data) => {
const isPasteable = canEdit && data?.content && data.content.status !== CLIPBOARD_STATUS.expired;
const isPasteableXBlock = isPasteable && !NOT_XBLOCK_TYPES.includes(data.content.blockType);
const isPasteableXBlock = isPasteable && !STRUCTURAL_XBLOCK_TYPES.includes(data.content.blockType);
const isPasteableUnit = isPasteable && data.content.blockType === 'vertical';

setShowPasteXBlock(!!isPasteableXBlock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const WhatsInClipboard = ({

const handleKeyDown = ({ key }) => {
if (key === 'Tab') {
popoverElementRef.current.focus();
popoverElementRef.current?.focus();
handlePopoverToggle(true);

Check warning on line 18 in src/generic/clipboard/paste-component/components/WhatsInClipboard.jsx

View check run for this annotation

Codecov / codecov/patch

src/generic/clipboard/paste-component/components/WhatsInClipboard.jsx#L17-L18

Added lines #L17 - L18 were not covered by tests
}
};
Expand Down
3 changes: 1 addition & 2 deletions src/generic/clipboard/paste-component/constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import PropTypes from 'prop-types';

/* eslint-disable import/prefer-default-export */
export const clipboardPropsTypes = {
sourceEditUrl: PropTypes.string.isRequired,
content: PropTypes.shape({
Expand All @@ -8,5 +9,3 @@ export const clipboardPropsTypes = {
}).isRequired,
sourceContextTitle: PropTypes.string.isRequired,
};

export const OVERLAY_TRIGGERS = ['hover', 'focus'];
3 changes: 1 addition & 2 deletions src/generic/clipboard/paste-component/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import { OverlayTrigger, Popover } from '@openedx/paragon';

import { PopoverContent, PasteButton, WhatsInClipboard } from './components';
import { clipboardPropsTypes, OVERLAY_TRIGGERS } from './constants';
import { clipboardPropsTypes } from './constants';

const PasteComponent = ({
onClick, clipboardData, text, className,
Expand Down Expand Up @@ -36,7 +36,6 @@ const PasteComponent = ({
<PasteButton className={className} onClick={onClick} text={text} />
<OverlayTrigger
show={showPopover}
trigger={OVERLAY_TRIGGERS}
overlay={renderPopover}
>
<WhatsInClipboard
Expand Down

0 comments on commit e5ba0f7

Please sign in to comment.