Skip to content

docs: example of adding Marketing links via the plugin slots #598

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 8 additions & 2 deletions src/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ subscribe(APP_CONFIG_INITIALIZED, () => {
* See the documentation for the structure of secondary menu item.
* @param {list} userMenuItems - The list of user menu items to display.
* See the documentation for the structure of user menu item.
* @param {string} logoDestination - The destination of the logo.
*/
const Header = ({
intl, mainMenuItems, secondaryMenuItems, userMenuItems,
intl, mainMenuItems, secondaryMenuItems, userMenuItems, logoDestination,
}) => {
const { authenticatedUser, config } = useContext(AppContext);

Expand Down Expand Up @@ -110,7 +111,7 @@ const Header = ({
const props = {
logo: config.LOGO_URL,
logoAltText: config.SITE_NAME,
logoDestination: `${config.LMS_BASE_URL}/dashboard`,
logoDestination: logoDestination || `${config.LMS_BASE_URL}/dashboard`,
loggedIn: authenticatedUser !== null,
username: authenticatedUser !== null ? authenticatedUser.username : null,
avatar: authenticatedUser !== null ? authenticatedUser.avatar : null,
Expand All @@ -136,6 +137,7 @@ Header.defaultProps = {
mainMenuItems: null,
secondaryMenuItems: null,
userMenuItems: null,
logoDestination: null,
};

Header.propTypes = {
Expand All @@ -157,6 +159,10 @@ Header.propTypes = {
isActive: PropTypes.bool,
})),
})),
logoDestination: PropTypes.oneOfType([
PropTypes.string,
PropTypes.oneOf([false, null]),
]),
};

export default injectIntl(Header);
26 changes: 26 additions & 0 deletions src/Header.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,30 @@ describe('<Header />', () => {

expect(wrapper.toJSON()).toMatchSnapshot();
});

it('renders correctly with custom logoDestination', () => {
const contextValue = {
authenticatedUser: null,
config: {
LMS_BASE_URL: process.env.LMS_BASE_URL,
SITE_NAME: process.env.SITE_NAME,
LOGIN_URL: process.env.LOGIN_URL,
LOGOUT_URL: process.env.LOGOUT_URL,
LOGO_URL: process.env.LOGO_URL,
},
};
const customLogoDestination = '/custom-destination';
const component = (
<ResponsiveContext.Provider value={{ width: 1280 }}>
<IntlProvider locale="en" messages={{}}>
<AppContext.Provider value={contextValue}>
<Header logoDestination={customLogoDestination} />
</AppContext.Provider>
</IntlProvider>
</ResponsiveContext.Provider>
);

const wrapper = TestRenderer.create(component);
expect(wrapper.toJSON()).toMatchSnapshot();
});
});
60 changes: 60 additions & 0 deletions src/__snapshots__/Header.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -443,3 +443,63 @@ exports[`<Header /> renders correctly for authenticated mobile 1`] = `
</div>
</header>
`;

exports[`<Header /> renders correctly with custom logoDestination 1`] = `
<header
className="site-header-desktop"
>
<a
className="nav-skip sr-only sr-only-focusable"
href="#main"
>
Skip to main content
</a>
<div
className="container-fluid null"
>
<div
className="nav-container position-relative d-flex align-items-center"
>
<a
className="logo"
href="/custom-destination"
>
<img
alt="edX"
className="d-block"
src="https://edx-cdn.org/v3/default/logo.svg"
/>
</a>
<nav
aria-label="Main"
className="nav main-nav"
>
<a
className="nav-link"
href="http://localhost:18000/dashboard"
onClick={null}
>
Courses
</a>
</nav>
<nav
aria-label="Secondary"
className="nav secondary-menu-container align-items-center ml-auto"
>
<a
className="btn mr-2 btn-link"
href="http://localhost:18000/login"
>
Login
</a>
<a
className="btn mr-2 btn-outline-primary"
href="http://localhost:18000/register"
>
Sign Up
</a>
</nav>
</div>
</div>
</header>
`;
7 changes: 5 additions & 2 deletions src/desktop-header/DesktopHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ export const desktopHeaderDataShape = {
loggedOutItems: desktopLoggedOutItemsDataShape,
logo: PropTypes.string,
logoAltText: PropTypes.string,
logoDestination: PropTypes.string,
logoDestination: PropTypes.oneOfType([
PropTypes.string,
PropTypes.oneOf([false, null]),
]),
avatar: PropTypes.string,
username: PropTypes.string,
loggedIn: PropTypes.bool,
Expand All @@ -128,7 +131,7 @@ DesktopHeader.propTypes = {
loggedOutItems: desktopHeaderDataShape.loggedOutItemsmainMenu,
logo: desktopHeaderDataShape.logomainMenu,
logoAltText: desktopHeaderDataShape.logoAltTextmainMenu,
logoDestination: desktopHeaderDataShape.logoDestinationmainMenu,
logoDestination: desktopHeaderDataShape.logoDestination,
avatar: desktopHeaderDataShape.avatarmainMenu,
username: desktopHeaderDataShape.usernamemainMenu,
loggedIn: desktopHeaderDataShape.loggedInmainMenu,
Expand Down
5 changes: 4 additions & 1 deletion src/mobile-header/MobileHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ export const mobileHeaderDataShape = {
loggedOutItems: mobileHeaderLoggedOutItemsDataShape,
logo: PropTypes.string,
logoAltText: PropTypes.string,
logoDestination: PropTypes.string,
logoDestination: PropTypes.oneOfType([
PropTypes.string,
PropTypes.oneOf([false, null]),
]),
avatar: PropTypes.string,
username: PropTypes.string,
loggedIn: PropTypes.bool,
Expand Down
51 changes: 51 additions & 0 deletions src/plugin-slots/DesktopMainMenuSlot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,54 @@ const config = {
export default config;
```

### Add Custom Marketing links

This `env.config.jsx` will add new custom **Marketing links** to the desktop main menu.

![Screenshot of custom marketing links](./images/desktop_main_menu_marketing_links.png)

```jsx
import { PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';

const modifyMainMenu = (widget) => {
const existingMenu = widget.RenderWidget.props.menu || [];

const newMarketingLinks = [
{
type: 'item',
href: 'https://example.com/how-it-works',
content: 'How it works',
},
{
type: 'item',
href: 'https://example.com/courses',
content: 'Courses',
},
{
type: 'item',
href: 'https://example.com/schools',
content: 'Schools',
}
];

widget.content.menu = [...existingMenu, ...newMarketingLinks];
return widget;
};

const config = {
pluginSlots: {
'org.openedx.frontend.layout.header_desktop_main_menu.v1': {
keepDefault: true,
plugins: [
{
op: PLUGIN_OPERATIONS.Modify,
widgetId: 'default_contents',
fn: modifyMainMenu,
},
]
},
},
}

export default config;
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.