Skip to content

Commit 8956242

Browse files
committed
feat: Add slots to add tab links and add mechanism for plugin routes
1 parent f39a50e commit 8956242

File tree

3 files changed

+50
-39
lines changed

3 files changed

+50
-39
lines changed
Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
1-
import React from 'react';
2-
import PropTypes from 'prop-types';
3-
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
1+
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, intl,
13-
}) => {
22+
activeTabSlug = undefined,
23+
className = null,
24+
tabs,
25+
}:CourseTabsNavigationProps) => {
1426
const { show } = useCoursewareSearchState();
27+
const intl = useIntl();
1528

1629
return (
1730
<div id="courseTabsNavigation" className={classNames('course-tabs-navigation', className)}>
@@ -22,15 +35,17 @@ const CourseTabsNavigation = ({
2235
className="nav-underline-tabs"
2336
aria-label={intl.formatMessage(messages.courseMaterial)}
2437
>
25-
{tabs.map(({ url, title, slug }) => (
26-
<a
27-
key={slug}
28-
className={classNames('nav-item flex-shrink-0 nav-link', { active: slug === activeTabSlug })}
29-
href={url}
30-
>
31-
{title}
32-
</a>
33-
))}
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>
3449
</Tabs>
3550
</div>
3651
<div className="search-toggle">
@@ -43,20 +58,4 @@ const CourseTabsNavigation = ({
4358
);
4459
};
4560

46-
CourseTabsNavigation.propTypes = {
47-
activeTabSlug: PropTypes.string,
48-
className: PropTypes.string,
49-
tabs: PropTypes.arrayOf(PropTypes.shape({
50-
title: PropTypes.string.isRequired,
51-
slug: PropTypes.string.isRequired,
52-
url: PropTypes.string.isRequired,
53-
})).isRequired,
54-
intl: intlShape.isRequired,
55-
};
56-
57-
CourseTabsNavigation.defaultProps = {
58-
activeTabSlug: undefined,
59-
className: null,
60-
};
61-
62-
export default injectIntl(CourseTabsNavigation);
61+
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 ReactDOM from 'react-dom';
89
import { Routes, Route } from 'react-router-dom';
910

@@ -62,7 +63,7 @@ subscribe(APP_READY, () => {
6263
<OutlineTab />
6364
</TabContainer>
6465
</DecodePageRoute>
65-
)}
66+
)}
6667
/>
6768
<Route
6869
path={DECODE_ROUTES.LIVE}
@@ -133,6 +134,17 @@ subscribe(APP_READY, () => {
133134
)}
134135
/>
135136
))}
137+
{getConfig()?.PLUGIN_ROUTES?.map((route) => (
138+
<Route
139+
key={route}
140+
path={route}
141+
element={(
142+
<DecodePageRoute>
143+
<PluginSlot id="course_page_route_slot" pluginProps={{ route }} />
144+
</DecodePageRoute>
145+
)}
146+
/>
147+
))}
136148
</Routes>
137149
</UserMessagesProvider>
138150
</NoticesProvider>

src/tab-page/TabPage.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
3+
import { useIntl } from '@edx/frontend-platform/i18n';
44
import { useDispatch, useSelector } from 'react-redux';
55
import { Navigate } from 'react-router-dom';
66

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

20-
const TabPage = ({ intl, ...props }) => {
20+
const TabPage = ({ ...props }) => {
21+
const intl = useIntl();
2122
const {
2223
activeTabSlug,
2324
courseId,
@@ -92,11 +93,10 @@ TabPage.defaultProps = {
9293

9394
TabPage.propTypes = {
9495
activeTabSlug: PropTypes.string.isRequired,
95-
intl: intlShape.isRequired,
9696
courseId: PropTypes.string,
9797
courseStatus: PropTypes.string.isRequired,
9898
metadataModel: PropTypes.string.isRequired,
9999
unitId: PropTypes.string,
100100
};
101101

102-
export default injectIntl(TabPage);
102+
export default TabPage;

0 commit comments

Comments
 (0)