Skip to content

feat: Add slots to add tab links and add mechanism for plugin routes #77

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

Merged
merged 2 commits into from
Jun 24, 2025
Merged
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
45 changes: 25 additions & 20 deletions src/course-tabs/CourseTabsNavigation.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import React from 'react';
import PropTypes from 'prop-types';
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { useIntl } from '@edx/frontend-platform/i18n';
import { PluginSlot } from '@openedx/frontend-plugin-framework';
import classNames from 'classnames';

import messages from './messages';
import Tabs from '../generic/tabs/Tabs';
import PropTypes from 'prop-types';
import React from 'react';
import { CoursewareSearch, CoursewareSearchToggle } from '../course-home/courseware-search';
import { useCoursewareSearchState } from '../course-home/courseware-search/hooks';
import Tabs from '../generic/tabs/Tabs';

import messages from './messages';

const CourseTabsNavigation = ({
activeTabSlug, className, tabs, intl,
}) => {
const CourseTabsNavigation = ({ activeTabSlug, className, tabs }) => {
const { show } = useCoursewareSearchState();
const intl = useIntl();

return (
<div id="courseTabsNavigation" className={classNames('course-tabs-navigation', className)}>
Expand All @@ -20,15 +20,21 @@ const CourseTabsNavigation = ({
className="nav-underline-tabs"
aria-label={intl.formatMessage(messages.courseMaterial)}
>
{tabs.map(({ url, title, slug }) => (
<a
key={slug}
className={classNames('nav-item flex-shrink-0 nav-link', { active: slug === activeTabSlug })}
href={url}
>
{title}
</a>
))}
<PluginSlot id="course_tab_links_slot">
{tabs.map(({
url,
title,
slug,
}) => (
<a
key={slug}
className={classNames('nav-item flex-shrink-0 nav-link', { active: slug === activeTabSlug })}
href={url}
>
{title}
</a>
))}
</PluginSlot>
</Tabs>
</div>
<div className="course-tabs-navigation__search-toggle">
Expand All @@ -47,12 +53,11 @@ CourseTabsNavigation.propTypes = {
slug: PropTypes.string.isRequired,
url: PropTypes.string.isRequired,
})).isRequired,
intl: intlShape.isRequired,
};

CourseTabsNavigation.defaultProps = {
activeTabSlug: undefined,
className: null,
};

export default injectIntl(CourseTabsNavigation);
export default CourseTabsNavigation;
14 changes: 13 additions & 1 deletion src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
getConfig,
} from '@edx/frontend-platform';
import { AppProvider, ErrorPage, PageWrap } from '@edx/frontend-platform/react';
import { PluginSlot } from '@openedx/frontend-plugin-framework';
import React from 'react';
import ReactDOM from 'react-dom';
import { Routes, Route } from 'react-router-dom';
Expand Down Expand Up @@ -62,7 +63,7 @@
<OutlineTab />
</TabContainer>
</DecodePageRoute>
)}
)}
/>
<Route
path={DECODE_ROUTES.LIVE}
Expand Down Expand Up @@ -133,6 +134,17 @@
)}
/>
))}
{getConfig()?.PLUGIN_ROUTES?.map((route) => (
<Route

Check warning on line 138 in src/index.jsx

View check run for this annotation

Codecov / codecov/patch

src/index.jsx#L138

Added line #L138 was not covered by tests
key={route}
path={route}
element={(
<DecodePageRoute>
<PluginSlot id="course_page_route_slot" pluginProps={{ route }} />
</DecodePageRoute>
)}
/>
))}
</Routes>
</UserMessagesProvider>
</NoticesProvider>
Expand Down
6 changes: 0 additions & 6 deletions src/setupTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ import { appendBrowserTimezoneToUrl, executeThunk } from './utils';
import buildSimpleCourseAndSequenceMetadata from './courseware/data/__factories__/sequenceMetadata.factory';
import { buildOutlineFromBlocks } from './courseware/data/__factories__/learningSequencesOutline.factory';

jest.mock('@openedx/frontend-plugin-framework', () => ({
...jest.requireActual('@openedx/frontend-plugin-framework'),
Plugin: () => 'Plugin',
PluginSlot: () => 'PluginSlot',
}));

jest.mock('@src/generic/plugin-store', () => ({
...jest.requireActual('@src/generic/plugin-store'),
usePluginsCallback: jest.fn((_, cb) => cb),
Expand Down
8 changes: 4 additions & 4 deletions src/tab-page/TabPage.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { useIntl } from '@edx/frontend-platform/i18n';
import { useDispatch, useSelector } from 'react-redux';
import { Navigate } from 'react-router-dom';

Expand All @@ -17,7 +17,8 @@ import LoadedTabPage from './LoadedTabPage';
import { setCallToActionToast } from '../course-home/data/slice';
import LaunchCourseHomeTourButton from '../product-tours/newUserCourseHomeTour/LaunchCourseHomeTourButton';

const TabPage = ({ intl, ...props }) => {
const TabPage = ({ ...props }) => {
const intl = useIntl();
const {
activeTabSlug,
courseId,
Expand Down Expand Up @@ -92,11 +93,10 @@ TabPage.defaultProps = {

TabPage.propTypes = {
activeTabSlug: PropTypes.string.isRequired,
intl: intlShape.isRequired,
courseId: PropTypes.string,
courseStatus: PropTypes.string.isRequired,
metadataModel: PropTypes.string.isRequired,
unitId: PropTypes.string,
};

export default injectIntl(TabPage);
export default TabPage;
Loading