-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Introduced Learning Course Header in Header MFE. (#133)
Co-authored-by: asadiqbal08 <[email protected]>
- Loading branch information
1 parent
7e33da4
commit 2db0fd5
Showing
21 changed files
with
5,390 additions
and
4,964 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
const { createConfig } = require('@edx/frontend-build'); | ||
|
||
module.exports = createConfig('jest', { | ||
setupFiles: [ | ||
setupFilesAfterEnv: [ | ||
'<rootDir>/src/setupTest.js', | ||
], | ||
}); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { defineMessages } from '@edx/frontend-platform/i18n'; | ||
|
||
const messages = defineMessages({ | ||
registerSentenceCase: { | ||
id: 'general.register.sentenceCase', | ||
defaultMessage: 'Register', | ||
description: 'Text in a button, prompting the user to register.', | ||
}, | ||
signInSentenceCase: { | ||
id: 'general.signIn.sentenceCase', | ||
defaultMessage: 'Sign in', | ||
description: 'Text in a button, prompting the user to log in.', | ||
}, | ||
}); | ||
|
||
export default messages; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import Header from './Header'; | ||
import LearningHeader from './learning-header/LearningHeader'; | ||
import messages from './i18n/index'; | ||
|
||
export { messages }; | ||
export { LearningHeader, messages }; | ||
|
||
export default Header; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
|
||
import { getConfig } from '@edx/frontend-platform'; | ||
import { getLoginRedirectUrl } from '@edx/frontend-platform/auth'; | ||
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; | ||
import { Button } from '@edx/paragon'; | ||
|
||
import genericMessages from '../generic/messages'; | ||
|
||
function AnonymousUserMenu({ intl }) { | ||
return ( | ||
<div> | ||
<Button | ||
className="mr-3" | ||
variant="outline-primary" | ||
href={`${getConfig().LMS_BASE_URL}/register?next=${encodeURIComponent(global.location.href)}`} | ||
> | ||
{intl.formatMessage(genericMessages.registerSentenceCase)} | ||
</Button> | ||
<Button | ||
variant="primary" | ||
href={`${getLoginRedirectUrl(global.location.href)}`} | ||
> | ||
{intl.formatMessage(genericMessages.signInSentenceCase)} | ||
</Button> | ||
</div> | ||
); | ||
} | ||
|
||
AnonymousUserMenu.propTypes = { | ||
intl: intlShape.isRequired, | ||
}; | ||
|
||
export default injectIntl(AnonymousUserMenu); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { faUserCircle } from '@fortawesome/free-solid-svg-icons'; | ||
|
||
import { getConfig } from '@edx/frontend-platform'; | ||
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; | ||
import { Dropdown } from '@edx/paragon'; | ||
|
||
import messages from './messages'; | ||
|
||
function AuthenticatedUserDropdown({ intl, username }) { | ||
const dashboardMenuItem = ( | ||
<Dropdown.Item href={`${getConfig().LMS_BASE_URL}/dashboard`}> | ||
{intl.formatMessage(messages.dashboard)} | ||
</Dropdown.Item> | ||
); | ||
|
||
return ( | ||
<> | ||
<a className="text-gray-700 mr-3" href={`${getConfig().SUPPORT_URL}`}>{intl.formatMessage(messages.help)}</a> | ||
<Dropdown className="user-dropdown"> | ||
<Dropdown.Toggle variant="outline-primary"> | ||
<FontAwesomeIcon icon={faUserCircle} className="d-md-none" size="lg" /> | ||
<span data-hj-suppress className="d-none d-md-inline"> | ||
{username} | ||
</span> | ||
</Dropdown.Toggle> | ||
<Dropdown.Menu className="dropdown-menu-right"> | ||
{dashboardMenuItem} | ||
<Dropdown.Item href={`${getConfig().LMS_BASE_URL}/u/${username}`}> | ||
{intl.formatMessage(messages.profile)} | ||
</Dropdown.Item> | ||
<Dropdown.Item href={`${getConfig().LMS_BASE_URL}/account/settings`}> | ||
{intl.formatMessage(messages.account)} | ||
</Dropdown.Item> | ||
{ getConfig().ORDER_HISTORY_URL && ( | ||
<Dropdown.Item href={getConfig().ORDER_HISTORY_URL}> | ||
{intl.formatMessage(messages.orderHistory)} | ||
</Dropdown.Item> | ||
)} | ||
<Dropdown.Item href={getConfig().LOGOUT_URL}> | ||
{intl.formatMessage(messages.signOut)} | ||
</Dropdown.Item> | ||
</Dropdown.Menu> | ||
</Dropdown> | ||
</> | ||
); | ||
} | ||
|
||
AuthenticatedUserDropdown.propTypes = { | ||
intl: intlShape.isRequired, | ||
username: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default injectIntl(AuthenticatedUserDropdown); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import React, { useContext } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { getConfig } from '@edx/frontend-platform'; | ||
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; | ||
import { AppContext } from '@edx/frontend-platform/react'; | ||
|
||
import AnonymousUserMenu from './AnonymousUserMenu'; | ||
import AuthenticatedUserDropdown from './AuthenticatedUserDropdown'; | ||
import messages from './messages'; | ||
|
||
function LinkedLogo({ | ||
href, | ||
src, | ||
alt, | ||
...attributes | ||
}) { | ||
return ( | ||
<a href={href} {...attributes}> | ||
<img className="d-block" src={src} alt={alt} /> | ||
</a> | ||
); | ||
} | ||
|
||
LinkedLogo.propTypes = { | ||
href: PropTypes.string.isRequired, | ||
src: PropTypes.string.isRequired, | ||
alt: PropTypes.string.isRequired, | ||
}; | ||
|
||
function LearningHeader({ | ||
courseOrg, courseNumber, courseTitle, intl, showUserDropdown, | ||
}) { | ||
const { authenticatedUser } = useContext(AppContext); | ||
|
||
const headerLogo = ( | ||
<LinkedLogo | ||
className="logo" | ||
href={`${getConfig().LMS_BASE_URL}/dashboard`} | ||
src={getConfig().LOGO_URL} | ||
alt={getConfig().SITE_NAME} | ||
/> | ||
); | ||
|
||
return ( | ||
<header className="learning-header"> | ||
<a className="sr-only sr-only-focusable" href="#main-content">{intl.formatMessage(messages.skipNavLink)}</a> | ||
<div className="container-xl py-2 d-flex align-items-center"> | ||
{headerLogo} | ||
<div className="flex-grow-1 course-title-lockup" style={{ lineHeight: 1 }}> | ||
<span className="d-block small m-0">{courseOrg} {courseNumber}</span> | ||
<span className="d-block m-0 font-weight-bold course-title">{courseTitle}</span> | ||
</div> | ||
{showUserDropdown && authenticatedUser && ( | ||
<AuthenticatedUserDropdown | ||
username={authenticatedUser.username} | ||
/> | ||
)} | ||
{showUserDropdown && !authenticatedUser && ( | ||
<AnonymousUserMenu /> | ||
)} | ||
</div> | ||
</header> | ||
); | ||
} | ||
|
||
LearningHeader.propTypes = { | ||
courseOrg: PropTypes.string, | ||
courseNumber: PropTypes.string, | ||
courseTitle: PropTypes.string, | ||
intl: intlShape.isRequired, | ||
showUserDropdown: PropTypes.bool, | ||
}; | ||
|
||
LearningHeader.defaultProps = { | ||
courseOrg: null, | ||
courseNumber: null, | ||
courseTitle: null, | ||
showUserDropdown: true, | ||
}; | ||
|
||
export default injectIntl(LearningHeader); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import { | ||
authenticatedUser, initializeMockApp, render, screen, | ||
} from '../setupTest'; | ||
import { LearningHeader as Header } from '../index'; | ||
|
||
describe('Header', () => { | ||
beforeAll(async () => { | ||
// We need to mock AuthService to implicitly use `getAuthenticatedUser` within `AppContext.Provider`. | ||
await initializeMockApp(); | ||
}); | ||
|
||
it('displays user button', () => { | ||
render(<Header />); | ||
expect(screen.getByRole('button')).toHaveTextContent(authenticatedUser.username); | ||
}); | ||
|
||
it('displays course data', () => { | ||
const courseData = { | ||
courseOrg: 'course-org', | ||
courseNumber: 'course-number', | ||
courseTitle: 'course-title', | ||
}; | ||
render(<Header {...courseData} />); | ||
|
||
expect(screen.getByText(`${courseData.courseOrg} ${courseData.courseNumber}`)).toBeInTheDocument(); | ||
expect(screen.getByText(courseData.courseTitle)).toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.