Skip to content

Commit

Permalink
refactor: refactoring after review
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang authored and arbrandes committed Mar 8, 2024
1 parent 423a3f3 commit 642b4e4
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/course-unit/CourseUnit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const CourseUnit = ({ courseId }) => {
<Layout.Element>
<Stack gap={3}>
<Sidebar blockId={blockId} data-testid="course-unit-sidebar" />
<Sidebar isDisplayUnitLocation data-testid="course-unit-location-sidebar" />
<Sidebar displayUnitLocation data-testid="course-unit-location-sidebar" />
</Stack>
</Layout.Element>
</Layout>
Expand Down
2 changes: 1 addition & 1 deletion src/course-unit/CourseUnit.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@import "./breadcrumbs/Breadcrumbs";
@import "./course-sequence/CourseSequence";
@import "./add-component/AddComponent";
@import "./course-xblock/CourseXblock";
@import "./course-xblock/CourseXBlock";
@import "./sidebar/Sidebar";
4 changes: 2 additions & 2 deletions src/course-unit/CourseUnit.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const courseId = '123';
const blockId = '567890';
const unitDisplayName = courseUnitIndexMock.metadata.display_name;
const mockedUsedNavigate = jest.fn();
const userName = 'edx';
const userName = 'openedx';

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
Expand Down Expand Up @@ -719,7 +719,7 @@ describe('<CourseUnit />', () => {
expect(discardChangesBtn).not.toBeInTheDocument();
});

it('checks whether xblock is removed when the corresponding delete button is clicked and sidebar is the updated', async () => {
it('checks whether xblock is removed when the corresponding delete button is clicked and the sidebar is the updated', async () => {
const {
getByText,
getAllByLabelText,
Expand Down
4 changes: 2 additions & 2 deletions src/course-unit/__mocks__/courseVerticalChildren.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ module.exports = {
children: [
{
name: 'Discussion',
block_id: 'block-v1:edX+L153+3T2023+type@discussion+block@fecd20842dd24f50bdc06643e791b013',
block_id: 'block-v1:OpenedX+L153+3T2023+type@discussion+block@fecd20842dd24f50bdc06643e791b013',
block_type: 'discussion',
},
{
name: 'Drag and Drop',
block_id: 'block-v1:edX+L153+3T2023+type@drag-and-drop-v2+block@b33cf1f6df4c41639659bc91132eeb02',
block_id: 'block-v1:OpenedX+L153+3T2023+type@drag-and-drop-v2+block@b33cf1f6df4c41639659bc91132eeb02',
block_type: 'drag-and-drop-v2',
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/course-unit/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const UNIT_VISIBILITY_STATES = {
ready: 'ready',
};

export const COLORS = {
export const ICON_COLOR_VARIANTS = {
BLACK: '#000',
GREEN: '#0D7D4D',
};
Expand Down
8 changes: 4 additions & 4 deletions src/course-unit/sidebar/components/SidebarBody.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getPublishInfo } from '../utils';
import messages from '../messages';
import ReleaseInfoComponent from './ReleaseInfoComponent';

const SidebarBody = ({ releaseLabel, isDisplayUnitLocation, locationId }) => {
const SidebarBody = ({ releaseLabel, displayUnitLocation, locationId }) => {
const intl = useIntl();
const {
editedOn,
Expand All @@ -21,7 +21,7 @@ const SidebarBody = ({ releaseLabel, isDisplayUnitLocation, locationId }) => {
return (
<Card.Body className="course-unit-sidebar-date">
<Stack>
{isDisplayUnitLocation ? (
{displayUnitLocation ? (
<span>
<h5 className="course-unit-sidebar-date-stage m-0">
{intl.formatMessage(messages.unitLocationTitle)}
Expand Down Expand Up @@ -53,12 +53,12 @@ const SidebarBody = ({ releaseLabel, isDisplayUnitLocation, locationId }) => {

SidebarBody.propTypes = {
releaseLabel: PropTypes.string.isRequired,
isDisplayUnitLocation: PropTypes.bool,
displayUnitLocation: PropTypes.bool,
locationId: PropTypes.string,
};

SidebarBody.defaultProps = {
isDisplayUnitLocation: false,
displayUnitLocation: false,
locationId: null,
};

Expand Down
10 changes: 5 additions & 5 deletions src/course-unit/sidebar/components/SidebarHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ import { getCourseUnitData } from '../../data/selectors';
import { getIconVariant } from '../utils';
import messages from '../messages';

const SidebarHeader = ({ title, visibilityState, isDisplayUnitLocation }) => {
const SidebarHeader = ({ title, visibilityState, displayUnitLocation }) => {
const intl = useIntl();
const { hasChanges, published } = useSelector(getCourseUnitData);
const { iconSrc, colorVariant } = getIconVariant(visibilityState, published, hasChanges);

return (
<Stack className="course-unit-sidebar-header" direction="horizontal">
{!isDisplayUnitLocation && (
{!displayUnitLocation && (
<Icon
className="course-unit-sidebar-header-icon"
svgAttrs={{ color: colorVariant }}
src={iconSrc}
/>
)}
<h3 className="course-unit-sidebar-header-title m-0">
{isDisplayUnitLocation ? intl.formatMessage(messages.sidebarHeaderUnitLocationTitle) : title}
{displayUnitLocation ? intl.formatMessage(messages.sidebarHeaderUnitLocationTitle) : title}
</h3>
</Stack>
);
Expand All @@ -31,11 +31,11 @@ const SidebarHeader = ({ title, visibilityState, isDisplayUnitLocation }) => {
SidebarHeader.propTypes = {
title: PropTypes.string.isRequired,
visibilityState: PropTypes.string.isRequired,
isDisplayUnitLocation: PropTypes.bool,
displayUnitLocation: PropTypes.bool,
};

SidebarHeader.defaultProps = {
isDisplayUnitLocation: false,
displayUnitLocation: false,
};

export default SidebarHeader;
8 changes: 4 additions & 4 deletions src/course-unit/sidebar/components/sidebar-footer/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ const SidebarFooter = ({
handlePublishing,
openDiscardModal,
visibleToStaffOnly,
isDisplayUnitLocation,
displayUnitLocation,
}) => {
const intl = useIntl();

return (
<Card.Footer className="course-unit-sidebar-footer" orientation="horizontal">
<Stack className="course-unit-sidebar-visibility">
{isDisplayUnitLocation ? (
{displayUnitLocation ? (
<small className="course-unit-sidebar-location-description">
{intl.formatMessage(messages.unitLocationDescription, { id: locationId })}
</small>
Expand All @@ -42,15 +42,15 @@ const SidebarFooter = ({

SidebarFooter.propTypes = {
locationId: PropTypes.string,
isDisplayUnitLocation: PropTypes.bool,
displayUnitLocation: PropTypes.bool,
openDiscardModal: PropTypes.func.isRequired,
openVisibleModal: PropTypes.func.isRequired,
handlePublishing: PropTypes.func.isRequired,
visibleToStaffOnly: PropTypes.bool.isRequired,
};

SidebarFooter.defaultProps = {
isDisplayUnitLocation: false,
displayUnitLocation: false,
locationId: null,
};

Expand Down
20 changes: 10 additions & 10 deletions src/course-unit/sidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { SidebarBody, SidebarFooter, SidebarHeader } from './components';
import useCourseUnitData from './hooks';
import messages from './messages';

const Sidebar = ({ blockId, isDisplayUnitLocation, ...props }) => {
const Sidebar = ({ blockId, displayUnitLocation, ...props }) => {
const {
title,
locationId,
Expand All @@ -23,8 +23,8 @@ const Sidebar = ({ blockId, isDisplayUnitLocation, ...props }) => {
} = useCourseUnitData(useSelector(getCourseUnitData));
const intl = useIntl();
const dispatch = useDispatch();
const [isOpenDiscardModal, openDiscardModal, closeDiscardModal] = useToggle(false);
const [isOpenVisibleModal, openVisibleModal, closeVisibleModal] = useToggle(false);
const [isDiscardModalOpen, openDiscardModal, closeDiscardModal] = useToggle(false);
const [isVisibleModalOpen, openVisibleModal, closeVisibleModal] = useToggle(false);

const handleCourseUnitVisibility = () => {
closeVisibleModal();
Expand All @@ -50,24 +50,24 @@ const Sidebar = ({ blockId, isDisplayUnitLocation, ...props }) => {
<SidebarHeader
title={title}
visibilityState={visibilityState}
isDisplayUnitLocation={isDisplayUnitLocation}
displayUnitLocation={displayUnitLocation}
/>
<SidebarBody
locationId={locationId}
releaseLabel={releaseLabel}
isDisplayUnitLocation={isDisplayUnitLocation}
displayUnitLocation={displayUnitLocation}
/>
<SidebarFooter
locationId={locationId}
openDiscardModal={openDiscardModal}
openVisibleModal={openVisibleModal}
isDisplayUnitLocation={isDisplayUnitLocation}
displayUnitLocation={displayUnitLocation}
handlePublishing={handleCourseUnitPublish}
visibleToStaffOnly={visibleToStaffOnly}
/>
<ModalNotification
title={intl.formatMessage(messages.modalDiscardUnitChangesTitle)}
isOpen={isOpenDiscardModal}
isOpen={isDiscardModalOpen}
actionButtonText={intl.formatMessage(messages.modalDiscardUnitChangesActionButtonText)}
cancelButtonText={intl.formatMessage(messages.modalDiscardUnitChangesCancelButtonText)}
handleAction={handleCourseUnitDiscardChanges}
Expand All @@ -77,7 +77,7 @@ const Sidebar = ({ blockId, isDisplayUnitLocation, ...props }) => {
/>
<ModalNotification
title={intl.formatMessage(messages.modalMakeVisibilityTitle)}
isOpen={isOpenVisibleModal}
isOpen={isVisibleModalOpen}
actionButtonText={intl.formatMessage(messages.modalMakeVisibilityActionButtonText)}
cancelButtonText={intl.formatMessage(messages.modalMakeVisibilityCancelButtonText)}
handleAction={handleCourseUnitVisibility}
Expand All @@ -91,12 +91,12 @@ const Sidebar = ({ blockId, isDisplayUnitLocation, ...props }) => {

Sidebar.propTypes = {
blockId: PropTypes.string,
isDisplayUnitLocation: PropTypes.bool,
displayUnitLocation: PropTypes.bool,
};

Sidebar.defaultProps = {
blockId: null,
isDisplayUnitLocation: false,
displayUnitLocation: false,
};

export default Sidebar;
12 changes: 6 additions & 6 deletions src/course-unit/sidebar/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
InfoOutline as InfoOutlineIcon,
} from '@openedx/paragon/icons';

import { COLORS, UNIT_VISIBILITY_STATES } from '../constants';
import { ICON_COLOR_VARIANTS, UNIT_VISIBILITY_STATES } from '../constants';
import messages from './messages';

/**
Expand Down Expand Up @@ -79,11 +79,11 @@ export const getVisibilityTitle = (intl, releasedToStudents, published, hasChang
*/
export const getIconVariant = (visibilityState, published, hasChanges) => {
const iconVariants = {
[UNIT_VISIBILITY_STATES.staffOnly]: { iconSrc: InfoOutlineIcon, colorVariant: COLORS.BLACK },
[UNIT_VISIBILITY_STATES.live]: { iconSrc: CheckCircleIcon, colorVariant: COLORS.GREEN },
publishedNoChanges: { iconSrc: CheckCircleOutlineIcon, colorVariant: COLORS.BLACK },
publishedWithChanges: { iconSrc: InfoOutlineIcon, colorVariant: COLORS.BLACK },
default: { iconSrc: InfoOutlineIcon, colorVariant: COLORS.BLACK },
[UNIT_VISIBILITY_STATES.staffOnly]: { iconSrc: InfoOutlineIcon, colorVariant: ICON_COLOR_VARIANTS.BLACK },
[UNIT_VISIBILITY_STATES.live]: { iconSrc: CheckCircleIcon, colorVariant: ICON_COLOR_VARIANTS.GREEN },
publishedNoChanges: { iconSrc: CheckCircleOutlineIcon, colorVariant: ICON_COLOR_VARIANTS.BLACK },
publishedWithChanges: { iconSrc: InfoOutlineIcon, colorVariant: ICON_COLOR_VARIANTS.BLACK },
default: { iconSrc: InfoOutlineIcon, colorVariant: ICON_COLOR_VARIANTS.BLACK },
};
if (visibilityState in iconVariants) {
return iconVariants[visibilityState];
Expand Down

0 comments on commit 642b4e4

Please sign in to comment.