Skip to content

Commit a7465f6

Browse files
committed
feat: Add slots to add tab links and add mechanism for plugin routes
(cherry picked from commit 02afdac3de1fffccfc08f0ae96cb4544b9101e7f)
1 parent 8356505 commit a7465f6

File tree

3 files changed

+41
-32
lines changed

3 files changed

+41
-32
lines changed
Lines changed: 24 additions & 27 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)}>
@@ -20,15 +33,15 @@ const CourseTabsNavigation = ({
2033
className="nav-underline-tabs"
2134
aria-label={intl.formatMessage(messages.courseMaterial)}
2235
>
23-
{tabs.map(({ url, title, slug }) => (
36+
<PluginSlot id="course_tab_links_slot">{tabs.map(({ url, title, slug }) => (
2437
<a
2538
key={slug}
2639
className={classNames('nav-item flex-shrink-0 nav-link', { active: slug === activeTabSlug })}
2740
href={url}
2841
>
2942
{title}
3043
</a>
31-
))}
44+
))}</PluginSlot>
3245
</Tabs>
3346
</div>
3447
<div className="course-tabs-navigation__search-toggle">
@@ -39,20 +52,4 @@ const CourseTabsNavigation = ({
3952
);
4053
};
4154

42-
CourseTabsNavigation.propTypes = {
43-
activeTabSlug: PropTypes.string,
44-
className: PropTypes.string,
45-
tabs: PropTypes.arrayOf(PropTypes.shape({
46-
title: PropTypes.string.isRequired,
47-
slug: PropTypes.string.isRequired,
48-
url: PropTypes.string.isRequired,
49-
})).isRequired,
50-
intl: intlShape.isRequired,
51-
};
52-
53-
CourseTabsNavigation.defaultProps = {
54-
activeTabSlug: undefined,
55-
className: null,
56-
};
57-
58-
export default injectIntl(CourseTabsNavigation);
55+
export default CourseTabsNavigation;

src/index.jsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
getConfig,
88
} from '@edx/frontend-platform';
99
import { AppProvider, ErrorPage, PageWrap } from '@edx/frontend-platform/react';
10+
import { PluginSlot } from '@openedx/frontend-plugin-framework';
1011
import React from 'react';
1112
import ReactDOM from 'react-dom';
1213
import { Routes, Route } from 'react-router-dom';
@@ -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)