Skip to content

Commit 02c7321

Browse files
authored
Merge pull request #78 from open-craft/kshitij/tab-slots.redwood
feat: Add slots to add tab links and add mechanism for plugin route
2 parents 4cca633 + fc20c94 commit 02c7321

File tree

4 files changed

+42
-31
lines changed

4 files changed

+42
-31
lines changed
Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
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 PropTypes from 'prop-types';
5+
import React from 'react';
86
import { CoursewareSearch, CoursewareSearchToggle } from '../course-home/courseware-search';
97
import { useCoursewareSearchState } from '../course-home/courseware-search/hooks';
8+
import Tabs from '../generic/tabs/Tabs';
9+
10+
import messages from './messages';
1011

11-
const CourseTabsNavigation = ({
12-
activeTabSlug, className, tabs, intl,
13-
}) => {
12+
const CourseTabsNavigation = ({ activeTabSlug, className, tabs }) => {
1413
const { show } = useCoursewareSearchState();
14+
const intl = useIntl();
1515

1616
return (
1717
<div id="courseTabsNavigation" className={classNames('course-tabs-navigation', className)}>
@@ -20,15 +20,21 @@ const CourseTabsNavigation = ({
2020
className="nav-underline-tabs"
2121
aria-label={intl.formatMessage(messages.courseMaterial)}
2222
>
23-
{tabs.map(({ url, title, slug }) => (
24-
<a
25-
key={slug}
26-
className={classNames('nav-item flex-shrink-0 nav-link', { active: slug === activeTabSlug })}
27-
href={url}
28-
>
29-
{title}
30-
</a>
31-
))}
23+
<PluginSlot id="course_tab_links_slot">
24+
{tabs.map(({
25+
url,
26+
title,
27+
slug,
28+
}) => (
29+
<a
30+
key={slug}
31+
className={classNames('nav-item flex-shrink-0 nav-link', { active: slug === activeTabSlug })}
32+
href={url}
33+
>
34+
{title}
35+
</a>
36+
))}
37+
</PluginSlot>
3238
</Tabs>
3339
</div>
3440
<div className="course-tabs-navigation__search-toggle">
@@ -47,12 +53,11 @@ CourseTabsNavigation.propTypes = {
4753
slug: PropTypes.string.isRequired,
4854
url: PropTypes.string.isRequired,
4955
})).isRequired,
50-
intl: intlShape.isRequired,
5156
};
5257

5358
CourseTabsNavigation.defaultProps = {
5459
activeTabSlug: undefined,
5560
className: null,
5661
};
5762

58-
export default injectIntl(CourseTabsNavigation);
63+
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/setupTest.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ import { appendBrowserTimezoneToUrl, executeThunk } from './utils';
3030
import buildSimpleCourseAndSequenceMetadata from './courseware/data/__factories__/sequenceMetadata.factory';
3131
import { buildOutlineFromBlocks } from './courseware/data/__factories__/learningSequencesOutline.factory';
3232

33-
jest.mock('@openedx/frontend-plugin-framework', () => ({
34-
...jest.requireActual('@openedx/frontend-plugin-framework'),
35-
Plugin: () => 'Plugin',
36-
PluginSlot: () => 'PluginSlot',
37-
}));
38-
3933
jest.mock('@src/generic/plugin-store', () => ({
4034
...jest.requireActual('@src/generic/plugin-store'),
4135
usePluginsCallback: jest.fn((_, cb) => cb),

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)