-
Notifications
You must be signed in to change notification settings - Fork 8
Introduce courseNavigationBar on header slot #106
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
Open
diana-villalvazo-wgu
wants to merge
2
commits into
openedx:main
Choose a base branch
from
WGU-Open-edX:courseNavigationBar
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
shell/header/course-navigation-bar/CourseTabsNavigation.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import { useQuery } from '@tanstack/react-query'; | ||
| import { Slot, useIntl } from '../../../runtime'; | ||
| import classNames from 'classnames'; | ||
| import { getCourseHomeCourseMetadata } from './data/service'; | ||
| import { Tab, Tabs } from '@openedx/paragon'; | ||
| import messages from './messages'; | ||
| import { useNavigate, useLocation } from 'react-router-dom'; | ||
| import './course-tabs-navigation.scss'; | ||
|
|
||
| interface CourseMetaData { | ||
| tabs: { | ||
| title: string, | ||
| slug: string, | ||
| url: string, | ||
| }[], | ||
| isMasquerading: boolean, | ||
| } | ||
|
|
||
| const CourseTabsNavigation = () => { | ||
| const location = useLocation(); | ||
| const intl = useIntl(); | ||
| const navigate = useNavigate(); | ||
|
|
||
| const extractCourseId = (pathname: string): string => { | ||
| const courseRegex = /\/courses?\/([^/]+)/; | ||
| const courseMatch = courseRegex.exec(pathname); | ||
| return courseMatch ? courseMatch[1] : ''; | ||
| }; | ||
|
|
||
| const courseId = extractCourseId(location.pathname); | ||
|
|
||
| const { data } = useQuery({ | ||
| queryKey: ['org.openedx.frontend.app.header.course-meta', courseId], | ||
| queryFn: () => getCourseHomeCourseMetadata(courseId), | ||
| retry: 2, | ||
| }); | ||
|
|
||
| if (!courseId) { | ||
| return null; | ||
| } | ||
|
|
||
| const { tabs = [] }: CourseMetaData = data ?? {}; | ||
|
|
||
| const handleSelectedTab = (eventKey) => { | ||
| const selectedUrl = tabs.find(tab => tab.slug === eventKey)?.url ?? '/'; | ||
|
|
||
| try { | ||
| if (selectedUrl.startsWith('http://') || selectedUrl.startsWith('https://')) { | ||
| const url = new URL(selectedUrl); | ||
| if (url.origin === window.location.origin) { | ||
| navigate(url.pathname + url.search + url.hash); | ||
| } else { | ||
| window.location.href = selectedUrl; | ||
| } | ||
| } else { | ||
| navigate(selectedUrl); | ||
| } | ||
| } catch (error) { | ||
| navigate(selectedUrl); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <div id="courseTabsNavigation" className={classNames('course-tabs-navigation')}> | ||
| <div className="container-xl"> | ||
| <div className="nav-bar"> | ||
| <div className="nav-menu"> | ||
| <Tabs className="nav-underline-tabs" aria-label={intl.formatMessage(messages.courseMaterial)} onSelect={handleSelectedTab}> | ||
| {tabs.map(({ title, slug }) => ( | ||
| <Tab eventKey={slug} title={title} key={slug} /> | ||
| ))} | ||
| </Tabs> | ||
| </div> | ||
| <Slot id="org.openedx.frontend.slot.header.courseNavigationBar.extraContent.v1" /> | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This slot was added because on current learning MFE this nav bar has some extra content related to |
||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default CourseTabsNavigation; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export const activeRolesForCourseNavigationBar = [ | ||
| 'org.openedx.frontend.role.learning', | ||
| 'org.openedx.frontend.role.discussions', | ||
| 'org.openedx.frontend.role.instructor', | ||
| ]; |
7 changes: 7 additions & 0 deletions
7
shell/header/course-navigation-bar/course-tabs-navigation.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| .course-tabs-navigation { | ||
| border-bottom: 2px solid rgb(232.5, 229.5, 228); // var(--pgn-color-nav-tabs-base-border-base) | ||
|
|
||
| .nav-tabs { | ||
| border-bottom: none; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { getSiteConfig, getAuthenticatedHttpClient, camelCaseObject } from '../../../../runtime'; | ||
|
|
||
| export const getCourseMetadataApiUrl = (courseId) => `${getSiteConfig().lmsBaseUrl}/api/course_home/course_metadata/${courseId}`; | ||
|
|
||
| function normalizeCourseHomeCourseMetadata(metadata) { | ||
| const data = camelCaseObject(metadata); | ||
| return { | ||
| ...data, | ||
| tabs: data.tabs.map(tab => ({ | ||
| slug: tab.tabId === 'courseware' ? 'outline' : tab.tabId, | ||
| title: tab.title, | ||
| url: tab.url, | ||
| })), | ||
| isMasquerading: data.originalUserIsStaff && !data.isStaff, | ||
| }; | ||
| } | ||
|
|
||
| export async function getCourseHomeCourseMetadata(courseId) { | ||
| const url = getCourseMetadataApiUrl(courseId); | ||
| const { data } = await getAuthenticatedHttpClient().get(url); | ||
|
|
||
| return normalizeCourseHomeCourseMetadata(data); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { defineMessages } from '../../../runtime'; | ||
|
|
||
| const messages = defineMessages({ | ||
| courseMaterial: { | ||
| id: 'org.openedx.frontend.slot.header.courseNavigationBar.tabs.label', | ||
| defaultMessage: 'Course Material', | ||
| description: 'The accessible label for course tabs navigation', | ||
| }, | ||
| }); | ||
|
|
||
| export default messages; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tried to use navigate as much as possible so we can preserve app state and avoid unneeded full page load