Skip to content

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

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
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 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';

interface CourseTabsNavigationProps {
activeTabSlug?: string;
className?: string | null;
tabs: Array<{
title: string;
slug: string;
url: string;
}>;
}

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

return (
<div id="courseTabsNavigation" className={classNames('course-tabs-navigation', className)}>
Expand All @@ -22,15 +35,17 @@ 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="search-toggle">
Expand All @@ -43,20 +58,4 @@ const CourseTabsNavigation = ({
);
};

CourseTabsNavigation.propTypes = {
activeTabSlug: PropTypes.string,
className: PropTypes.string,
tabs: PropTypes.arrayOf(PropTypes.shape({
title: PropTypes.string.isRequired,
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 @@ -4,6 +4,7 @@
getConfig,
} from '@edx/frontend-platform';
import { AppProvider, ErrorPage, PageWrap } from '@edx/frontend-platform/react';
import { PluginSlot } from '@openedx/frontend-plugin-framework';
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
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;