From 5a99ca5c91f2ace15145453d4778aa7266557c93 Mon Sep 17 00:00:00 2001 From: Leangseu Kim Date: Wed, 31 May 2023 11:10:28 -0400 Subject: [PATCH] fix: breadcrumb jump nav styling --- src/courseware/course/CourseBreadcrumbs.jsx | 118 +++++++++++------- .../course/CourseBreadcrumbs.test.jsx | 2 +- src/courseware/course/JumpNavMenuItem.jsx | 19 ++- .../course/JumpNavMenuItem.test.jsx | 1 + 4 files changed, 89 insertions(+), 51 deletions(-) diff --git a/src/courseware/course/CourseBreadcrumbs.jsx b/src/courseware/course/CourseBreadcrumbs.jsx index 0a1e73493d..f0a05eea7b 100644 --- a/src/courseware/course/CourseBreadcrumbs.jsx +++ b/src/courseware/course/CourseBreadcrumbs.jsx @@ -1,57 +1,80 @@ -import React, { useMemo } from 'react'; +import React, { useMemo, useState } from 'react'; import PropTypes from 'prop-types'; import { getConfig } from '@edx/frontend-platform'; import { FormattedMessage } from '@edx/frontend-platform/i18n'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faHome } from '@fortawesome/free-solid-svg-icons'; import { useSelector } from 'react-redux'; -import { SelectMenu } from '@edx/paragon'; +import { useToggle, ModalPopup, Menu } from '@edx/paragon'; import { Link } from 'react-router-dom'; import { useModel, useModels } from '../../generic/model-store'; import JumpNavMenuItem from './JumpNavMenuItem'; const CourseBreadcrumb = ({ - content, withSeparator, courseId, sequenceId, unitId, isStaff, + content, + withSeparator, + courseId, + sequenceId, + unitId, + isStaff, }) => { - const defaultContent = content.filter(destination => destination.default)[0] || { id: courseId, label: '', sequences: [] }; + const defaultContent = content.filter( + (destination) => destination.default, + )[0] || { id: courseId, label: '', sequences: [] }; + + const showRegularLink = getConfig().ENABLE_JUMPNAV !== 'true' || content.length < 2 || !isStaff; + const [isOpen, open, close] = useToggle(false); + const [target, setTarget] = useState(null); return ( <> {withSeparator && (
  • /
  • )} -
  • - { getConfig().ENABLE_JUMPNAV !== 'true' || content.length < 2 || !isStaff - ? ( - - {defaultContent.label} - - ) - : ( - - {content.map(item => ( - - ))} - - )} - + : `/course/${courseId}/${defaultContent.id}` + } + > + {defaultContent.label} + + ) : ( + <> + { + // eslint-disable-next-line + + {defaultContent.label} + + } + + + {content.map((item) => ( + + ))} + + + + )}
  • ); @@ -87,14 +110,21 @@ const CourseBreadcrumbs = ({ isStaff, }) => { const course = useModel('coursewareMeta', courseId); - const courseStatus = useSelector(state => state.courseware.courseStatus); - const sequenceStatus = useSelector(state => state.courseware.sequenceStatus); + const courseStatus = useSelector((state) => state.courseware.courseStatus); + const sequenceStatus = useSelector( + (state) => state.courseware.sequenceStatus, + ); - const allSequencesInSections = Object.fromEntries(useModels('sections', course.sectionIds).map(section => [section.id, { - default: section.id === sectionId, - title: section.title, - sequences: useModels('sequences', section.sequenceIds), - }])); + const allSequencesInSections = Object.fromEntries( + useModels('sections', course.sectionIds).map((section) => [ + section.id, + { + default: section.id === sectionId, + title: section.title, + sequences: useModels('sequences', section.sequenceIds), + }, + ]), + ); const links = useMemo(() => { const chapters = []; @@ -108,7 +138,7 @@ const CourseBreadcrumbs = ({ sequences: section.sequences, }); if (section.default) { - section.sequences.forEach(sequence => { + section.sequences.forEach((sequence) => { sequentials.push({ id: sequence.id, label: sequence.title, @@ -124,7 +154,7 @@ const CourseBreadcrumbs = ({ return (