Skip to content

Commit 83693c3

Browse files
committed
feat: Add slots to add tab links and add mechanism for plugin routes
1 parent 24c9437 commit 83693c3

File tree

2 files changed

+43
-32
lines changed

2 files changed

+43
-32
lines changed
Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
1-
import React from 'react';
2-
import PropTypes from 'prop-types';
31
import { useIntl } from '@edx/frontend-platform/i18n';
2+
import { PluginSlot } from '@openedx/frontend-plugin-framework';
43
import classNames from 'classnames';
5-
6-
import messages from './messages';
7-
import Tabs from '../generic/tabs/Tabs';
4+
import React from 'react';
85
import { CoursewareSearch, CoursewareSearchToggle } from '../course-home/courseware-search';
96
import { useCoursewareSearchState } from '../course-home/courseware-search/hooks';
7+
import Tabs from '../generic/tabs/Tabs';
8+
9+
import messages from './messages';
10+
11+
interface CourseTabsNavigationProps {
12+
activeTabSlug?: string;
13+
className?: string | null;
14+
tabs: Array<{
15+
title: string;
16+
slug: string;
17+
url: string;
18+
}>;
19+
}
1020

1121
const CourseTabsNavigation = ({
12-
activeTabSlug, className, tabs,
13-
}) => {
22+
activeTabSlug = undefined,
23+
className = null,
24+
tabs,
25+
}:CourseTabsNavigationProps) => {
1426
const intl = useIntl();
1527
const { show } = useCoursewareSearchState();
1628

@@ -23,15 +35,17 @@ const CourseTabsNavigation = ({
2335
className="nav-underline-tabs"
2436
aria-label={intl.formatMessage(messages.courseMaterial)}
2537
>
26-
{tabs.map(({ url, title, slug }) => (
27-
<a
28-
key={slug}
29-
className={classNames('nav-item flex-shrink-0 nav-link', { active: slug === activeTabSlug })}
30-
href={url}
31-
>
32-
{title}
33-
</a>
34-
))}
38+
<PluginSlot id="course_tab_links_slot">
39+
{tabs.map(({ url, title, slug }) => (
40+
<a
41+
key={slug}
42+
className={classNames('nav-item flex-shrink-0 nav-link', { active: slug === activeTabSlug })}
43+
href={url}
44+
>
45+
{title}
46+
</a>
47+
))}
48+
</PluginSlot>
3549
</Tabs>
3650
</div>
3751
<div className="search-toggle">
@@ -44,19 +58,4 @@ const CourseTabsNavigation = ({
4458
);
4559
};
4660

47-
CourseTabsNavigation.propTypes = {
48-
activeTabSlug: PropTypes.string,
49-
className: PropTypes.string,
50-
tabs: PropTypes.arrayOf(PropTypes.shape({
51-
title: PropTypes.string.isRequired,
52-
slug: PropTypes.string.isRequired,
53-
url: PropTypes.string.isRequired,
54-
})).isRequired,
55-
};
56-
57-
CourseTabsNavigation.defaultProps = {
58-
activeTabSlug: undefined,
59-
className: null,
60-
};
61-
6261
export default CourseTabsNavigation;

src/index.jsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
getConfig,
55
} from '@edx/frontend-platform';
66
import { AppProvider, ErrorPage, PageWrap } from '@edx/frontend-platform/react';
7+
import { PluginSlot } from '@openedx/frontend-plugin-framework';
78
import { StrictMode } from 'react';
89
import { createRoot } from 'react-dom/client';
910
import { Routes, Route } from 'react-router-dom';
@@ -71,7 +72,7 @@ subscribe(APP_READY, () => {
7172
<OutlineTab />
7273
</TabContainer>
7374
</DecodePageRoute>
74-
)}
75+
)}
7576
/>
7677
<Route
7778
path={DECODE_ROUTES.LIVE}
@@ -140,6 +141,17 @@ subscribe(APP_READY, () => {
140141
<CoursewareContainer />
141142
</DecodePageRoute>
142143
)}
144+
/>
145+
))}
146+
{getConfig()?.PLUGIN_ROUTES?.map((route) => (
147+
<Route
148+
key={route}
149+
path={route}
150+
element={(
151+
<DecodePageRoute>
152+
<PluginSlot id="course_page_route_slot" pluginProps={{ route }} />
153+
</DecodePageRoute>
154+
)}
143155
/>
144156
))}
145157
</Routes>

0 commit comments

Comments
 (0)