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,16 +1,28 @@
import React from 'react';
import PropTypes from 'prop-types';
import { useIntl } from '@edx/frontend-platform/i18n';
import classNames from 'classnames';

import messages from './messages';
import Tabs from '../generic/tabs/Tabs';
import { useIntl } from '@edx/frontend-platform/i18n';
import { PluginSlot } from '@openedx/frontend-plugin-framework';
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,
}) => {
activeTabSlug = undefined,
className = null,
tabs,
}:CourseTabsNavigationProps) => {
const intl = useIntl();
const { show } = useCoursewareSearchState();

Expand All @@ -23,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 @@ -44,19 +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,
};

CourseTabsNavigation.defaultProps = {
activeTabSlug: undefined,
className: null,
};

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 { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import { Routes, Route } from 'react-router-dom';
Expand Down Expand Up @@ -71,7 +72,7 @@
<OutlineTab />
</TabContainer>
</DecodePageRoute>
)}
)}
/>
<Route
path={DECODE_ROUTES.LIVE}
Expand Down Expand Up @@ -142,6 +143,17 @@
)}
/>
))}
{getConfig()?.PLUGIN_ROUTES?.map((route) => (
<Route

Check warning on line 147 in src/index.jsx

View check run for this annotation

Codecov / codecov/patch

src/index.jsx#L147

Added line #L147 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