From c35df7ef600923a9fa8c752dda19deefb3001843 Mon Sep 17 00:00:00 2001 From: Carlos Muniz Date: Thu, 21 Apr 2022 13:43:37 -0400 Subject: [PATCH] feat: Add StudioHeader with optional AppMenu (#199) * feat: Add StudioHeader with optional AppMenu StudioHeader is a graft of Header with an additional optional AppMenu. Some Frontend Apps use Menus in their custom headers to provide more functionality in their apps. By adding this functionality in StudioHeader, it will be easier for frontend apps in Studio to adopt this component without it affecting the main Header component. * test: Add tests for StudioHeader and AppMenu * fix: Remove orderHistory * fix: Remove Responsive components * fix: Redefine User Menu for Studio The userMenu in StudioHeader will be used more for Studio related items such as Studio Home and Studio Maintenance. This requires new messages and reestablishing the url destinations of these menu items. * fix: Remove loggedOutItems * fix: Remove AUTHN_MINIMAL_HEADER items * fix: Remove unnecessary tests Anonymous sessions do not exist in the Studio. And Studio is not Mobile Ready. Tests of these kind are superfluous and have been removed. * feat: Turn mainMenu into an optional prop * test: Add test for optional mainMenu prop * feat: Update snapshots * fix: Remove ResponsiveContext * fix: Remove href and update appMenu prop Dropping the href because having a link that also works as a dropdown can be mildly confusing. Changing menu (type, href, content ) triplet to stick to the pattern; so we removed "menu". Also adding brackets around the triplet. Lastly, updating test and snapshot. Co-authored-by: Carlos Muniz --- .env.development | 1 + src/DesktopHeader.jsx | 42 ++ src/Header.messages.jsx | 15 + src/StudioHeader.jsx | 99 +++++ src/StudioHeader.test.jsx | 135 ++++++ src/__snapshots__/StudioHeader.test.jsx.snap | 425 +++++++++++++++++++ src/index.jsx | 3 +- 7 files changed, 719 insertions(+), 1 deletion(-) create mode 100644 src/StudioHeader.jsx create mode 100644 src/StudioHeader.test.jsx create mode 100644 src/__snapshots__/StudioHeader.test.jsx.snap diff --git a/.env.development b/.env.development index d57d063..e7560ff 100644 --- a/.env.development +++ b/.env.development @@ -5,6 +5,7 @@ CSRF_TOKEN_API_PATH=/csrf/api/v1/token ECOMMERCE_BASE_URL=http://localhost:18130 LANGUAGE_PREFERENCE_COOKIE_NAME=openedx-language-preference LMS_BASE_URL=http://localhost:18000 +STUDIO_BASE_URL=http://localhost:18010 LOGIN_URL=http://localhost:18000/login LOGOUT_URL=http://localhost:18000/logout MARKETING_SITE_BASE_URL=http://localhost:18000 diff --git a/src/DesktopHeader.jsx b/src/DesktopHeader.jsx index 8da9977..8bd142f 100644 --- a/src/DesktopHeader.jsx +++ b/src/DesktopHeader.jsx @@ -54,6 +54,24 @@ class DesktopHeader extends React.Component { }); } + // Renders an optional App Menu for + renderAppMenu() { + const { appMenu } = this.props; + const { content: appMenuContent, menuItems } = appMenu; + return ( + + + {appMenuContent} + + + {menuItems.map(({ type, href, content }) => ( + {content} + ))} + + + ); + } + renderUserMenu() { const { userMenu, @@ -102,6 +120,7 @@ class DesktopHeader extends React.Component { logoDestination, loggedIn, intl, + appMenu, } = this.props; const logoProps = { src: logo, alt: logoAltText, href: logoDestination }; const logoClasses = getConfig().AUTHN_MINIMAL_HEADER ? 'mw-100' : null; @@ -118,6 +137,14 @@ class DesktopHeader extends React.Component { > {this.renderMainMenu()} + {appMenu ? ( + + ) : null}