-
Notifications
You must be signed in to change notification settings - Fork 129
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
feat: introduced LearningHeader for frontend-app-learning #133
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 && ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here too. |
||
<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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davidjoy FYI, I kept the OrderHistory conditional on basis of
ORDER_HISTORY_URL