Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions shell/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ export default function Header() {
const intl = useIntl();

return (
<header className="border-bottom py-2">
<nav className="py-2">
<a className="sr-only sr-only-focusable" href="#main-content">{intl.formatMessage(messages.skipNavLink)}</a>
<Slot id="org.openedx.frontend.slot.header.desktop.v1" />
<Slot id="org.openedx.frontend.slot.header.mobile.v1" />
</nav>
</header>
<>
<header className="border-bottom py-2">
<nav className="py-2">
<a className="sr-only sr-only-focusable" href="#main-content">{intl.formatMessage(messages.skipNavLink)}</a>
<Slot id="org.openedx.frontend.slot.header.desktop.v1" />
<Slot id="org.openedx.frontend.slot.header.mobile.v1" />
</nav>
</header>
<Slot id="org.openedx.frontend.slot.header.courseNavigationBar.v1" />
</>
);
}
12 changes: 11 additions & 1 deletion shell/header/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import MobileLayout from './mobile/MobileLayout';
import MobileNavLinks from './mobile/MobileNavLinks';

import messages from '../Shell.messages';
import CourseTabsNavigation from './course-navigation-bar/CourseTabsNavigation';
import { activeRolesForCourseNavigationBar } from './course-navigation-bar/constants';

const config: App = {
appId: 'org.openedx.frontend.app.header',
slots: [

// Layouts
{
slotId: 'org.openedx.frontend.slot.header.desktop.v1',
Expand Down Expand Up @@ -136,6 +137,15 @@ const config: App = {
authenticated: false,
}
},
{
slotId: 'org.openedx.frontend.slot.header.courseNavigationBar.v1',
id: 'org.openedx.frontend.widget.header.courseTabsNavigation.v1',
op: WidgetOperationTypes.APPEND,
component: CourseTabsNavigation,
condition: {
active: activeRolesForCourseNavigationBar,
}
}
]
};

Expand Down
82 changes: 82 additions & 0 deletions shell/header/course-navigation-bar/CourseTabsNavigation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { useNavigate, useLocation } from 'react-router-dom';
import classNames from 'classnames';
import { useQuery } from '@tanstack/react-query';
import { Tab, Tabs } from '@openedx/paragon';
import { Slot, useIntl } from '../../../runtime';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if possible make it absolute

import { getCourseHomeCourseMetadata } from './data/service';
import messages from './messages';
import './course-tabs-navigation.scss';

interface CourseMetaData {
tabs: {
title: string,
slug: string,
url: string,
}[],
isMasquerading: boolean,
}

const extractCourseId = (pathname: string): string => {
const courseRegex = /\/courses?\/([^/]+)/;
const courseMatch = courseRegex.exec(pathname);
return courseMatch ? courseMatch[1] : '';
};

const CourseTabsNavigation = () => {
const location = useLocation();
const intl = useIntl();
const navigate = useNavigate();

const courseId = extractCourseId(location.pathname);

const { data } = useQuery({
queryKey: ['org.openedx.frontend.app.header.course-meta', courseId],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this base ID be a constant?

queryFn: () => getCourseHomeCourseMetadata(courseId),
retry: 2,
enabled: !!courseId,
});

if (!courseId) {
return null;
}

const { tabs = [] }: CourseMetaData = data ?? {};

const handleSelectedTab = (eventKey: string | null) => {
const selectedUrl = tabs.find(tab => tab.slug === eventKey)?.url ?? '/';

try {
if (selectedUrl.startsWith('http://') || selectedUrl.startsWith('https://')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to understand in which case the selectedUrl woudln't have http or https?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a case could be a custom implementation that just points to a route on same domain for example if someone sent /cohorts and with navigate will go to that page 🤔 but not sure if im overcomplicating this

const url = new URL(selectedUrl);
if (url.origin === window.location.origin) {
navigate(url.pathname + url.search + url.hash);
Copy link
Author

@diana-villalvazo-wgu diana-villalvazo-wgu Oct 15, 2025

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks for the explanation

} else {
window.location.href = selectedUrl;
}
} else {
navigate(selectedUrl);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there's an issue with the URL you are trying to parse why are you navigating to it?

}
} catch (error) {
navigate(selectedUrl);
}
};

return (
<div id="courseTabsNavigation" className={classNames('course-tabs-navigation')}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason we need classNames here?

<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} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might want to use activeKey too, here, no? To give the user indication of which one is active.

))}
</Tabs>
</div>
<Slot id="org.openedx.frontend.slot.header.courseNavigationBar.extraContent.v1" />

Choose a reason for hiding this comment

The 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 courseware search

</div>
</div>
</div>
);
};

export default CourseTabsNavigation;
5 changes: 5 additions & 0 deletions shell/header/course-navigation-bar/constants.ts
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',
];
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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you remove the variable for a hardcoded color?

maybe you could create a variable something like
$border-base-tabs-color: rgb(232.5, 229.5, 228)
and use that

Copy link
Author

@diana-villalvazo-wgu diana-villalvazo-wgu Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when i created this PR, design tokens on frontend base wasn't ready, so didn't work, i left the comment to remember that and update it when that was ready


.nav-tabs {
border-bottom: none;
}
}
23 changes: 23 additions & 0 deletions shell/header/course-navigation-bar/data/service.ts
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);
}
11 changes: 11 additions & 0 deletions shell/header/course-navigation-bar/messages.ts
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;
Loading