Skip to content

Commit 35287fc

Browse files
asadiqbal08asadali145
authored andcommitted
feat: configureable header links
* Added user full name option * nit
1 parent 432dbb5 commit 35287fc

File tree

9 files changed

+57
-25
lines changed

9 files changed

+57
-25
lines changed

.env.development

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ ACCOUNT_SETTINGS_URL=http://localhost:1997
44
BASE_URL=localhost:8080
55
CREDENTIALS_BASE_URL=http://localhost:18150
66
CSRF_TOKEN_API_PATH=/csrf/api/v1/token
7+
DASHBOARD_URL=null
78
ECOMMERCE_BASE_URL=http://localhost:18130
9+
EXTERNAL_ACCOUNT_PROFILE_URL=null
810
LANGUAGE_PREFERENCE_COOKIE_NAME=openedx-language-preference
911
LMS_BASE_URL=http://localhost:18000
1012
STUDIO_BASE_URL=http://localhost:18010
@@ -14,6 +16,8 @@ MARKETING_SITE_BASE_URL=http://localhost:18000
1416
ORDER_HISTORY_URL=localhost:1996/orders
1517
REFRESH_ACCESS_TOKEN_ENDPOINT=http://localhost:18000/login_refresh
1618
SEGMENT_KEY=null
19+
SHOW_FULLNAME='false'
20+
SHOW_SETTINGS_LABEL='false'
1721
SITE_NAME=Open edX
1822
USER_INFO_COOKIE_NAME=edx-user-info
1923
LOGO_URL=https://edx-cdn.org/v3/default/logo.svg

README.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ Environment Variables
5151
* ``AUTHN_MINIMAL_HEADER`` - A boolean flag which hides the main menu, user menu, and logged-out
5252
menu items when truthy. This is intended to be used in micro-frontends like
5353
frontend-app-authentication in which these menus are considered distractions from the user's task.
54-
54+
* ``DASHBOARD_URL`` - The URL of the dashboard page. If not set the default ``<LMS_BASE_URL>/dashboard`` is used.
55+
* ``EXTERNAL_ACCOUNT_PROFILE_URL`` - An optional URL to the external profile page. If not set then default
56+
internal profile page ``<ACCOUNT_PROFILE_URL>/u/<username>`` is used.
57+
* ``SHOW_FULLNAME`` - A boolean flag to display ``full name`` of the user in the header.
58+
Defaults to ``false`` and ``username`` is displayed.
59+
* ``SHOW_SETTINGS_LABEL`` - A boolean flag to use `Settings` label instead of `Account` for the Account Settings page.
60+
Defaults to ``false`` and uses the ``Account`` label.
5561
Installation
5662
============
5763

@@ -184,4 +190,4 @@ Please do not report security issues in public. Please email [email protected]
184190
.. |license| image:: https://img.shields.io/npm/l/@edx/frontend-component-header.svg
185191
:target: @edx/frontend-component-header
186192
.. |semantic-release| image:: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
187-
:target: https://github.com/semantic-release/semantic-release
193+
:target: https://github.com/semantic-release/semantic-release

package-lock.json

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Header.jsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,21 @@ ensureConfig([
2727
subscribe(APP_CONFIG_INITIALIZED, () => {
2828
mergeConfig({
2929
AUTHN_MINIMAL_HEADER: !!process.env.AUTHN_MINIMAL_HEADER,
30+
DASHBOARD_URL: process.env.DASHBOARD_URL,
31+
EXTERNAL_ACCOUNT_PROFILE_URL: process.env.EXTERNAL_ACCOUNT_PROFILE_URL,
32+
SHOW_FULLNAME: process.env.SHOW_FULLNAME,
33+
SHOW_SETTINGS_LABEL: process.env.SHOW_SETTINGS_LABEL,
3034
}, 'Header additional config');
3135
});
3236

3337
const Header = ({ intl }) => {
3438
const { authenticatedUser, config } = useContext(AppContext);
3539

40+
const dashboardURL = config.DASHBOARD_URL ? config.DASHBOARD_URL : `${config.LMS_BASE_URL}/dashboard`;
3641
const mainMenu = [
3742
{
3843
type: 'item',
39-
href: `${config.LMS_BASE_URL}/dashboard`,
44+
href: dashboardURL,
4045
content: intl.formatMessage(messages['header.links.courses']),
4146
},
4247
];
@@ -50,18 +55,18 @@ const Header = ({ intl }) => {
5055
const userMenu = authenticatedUser === null ? [] : [
5156
{
5257
type: 'item',
53-
href: `${config.LMS_BASE_URL}/dashboard`,
58+
href: dashboardURL,
5459
content: intl.formatMessage(messages['header.user.menu.dashboard']),
5560
},
5661
{
5762
type: 'item',
58-
href: `${config.ACCOUNT_PROFILE_URL}/u/${authenticatedUser.username}`,
63+
href: config.EXTERNAL_ACCOUNT_PROFILE_URL ? config.EXTERNAL_ACCOUNT_PROFILE_URL : `${config.ACCOUNT_PROFILE_URL}/u/${authenticatedUser.username}`,
5964
content: intl.formatMessage(messages['header.user.menu.profile']),
6065
},
6166
{
6267
type: 'item',
6368
href: config.ACCOUNT_SETTINGS_URL,
64-
content: intl.formatMessage(messages['header.user.menu.account.settings']),
69+
content: config.SHOW_SETTINGS_LABEL === 'true' ? intl.formatMessage(messages['header.user.menu.settings']) : intl.formatMessage(messages['header.user.menu.account']),
6570
},
6671
{
6772
type: 'item',
@@ -88,12 +93,19 @@ const Header = ({ intl }) => {
8893
},
8994
];
9095

96+
let name = null;
97+
if (authenticatedUser !== null && config.SHOW_FULLNAME === 'true') {
98+
name = authenticatedUser.name;
99+
} else if (authenticatedUser !== null) {
100+
name = authenticatedUser.username;
101+
}
102+
91103
const props = {
92104
logo: config.LOGO_URL,
93105
logoAltText: config.SITE_NAME,
94-
logoDestination: `${config.LMS_BASE_URL}/dashboard`,
106+
logoDestination: config.DASHBOARD_URL ? config.DASHBOARD_URL : `${config.LMS_BASE_URL}/dashboard`,
95107
loggedIn: authenticatedUser !== null,
96-
username: authenticatedUser !== null ? authenticatedUser.username : null,
108+
username: name,
97109
avatar: authenticatedUser !== null ? authenticatedUser.avatar : null,
98110
mainMenu: getConfig().AUTHN_MINIMAL_HEADER ? [] : mainMenu,
99111
userMenu: getConfig().AUTHN_MINIMAL_HEADER ? [] : userMenu,

src/Header.messages.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ const messages = defineMessages({
3131
defaultMessage: 'Profile',
3232
description: 'Link to the user profile',
3333
},
34-
'header.user.menu.account.settings': {
35-
id: 'header.user.menu.account.settings',
34+
'header.user.menu.account': {
35+
id: 'header.user.menu.account',
3636
defaultMessage: 'Account',
3737
description: 'Link to account settings',
3838
},
39+
'header.user.menu.settings': {
40+
id: 'header.user.menu.settings',
41+
defaultMessage: 'Settings',
42+
description: 'Link to account settings',
43+
},
3944
'header.user.menu.order.history': {
4045
id: 'header.user.menu.order.history',
4146
defaultMessage: 'Order History',

src/learning-header/AuthenticatedUserDropdown.jsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import { Dropdown } from '@openedx/paragon';
99

1010
import messages from './messages';
1111

12-
const AuthenticatedUserDropdown = ({ intl, username }) => {
12+
const AuthenticatedUserDropdown = ({ intl, username, name }) => {
1313
const dashboardMenuItem = (
14-
<Dropdown.Item href={`${getConfig().LMS_BASE_URL}/dashboard`}>
14+
<Dropdown.Item href={getConfig().DASHBOARD_URL ? getConfig().DASHBOARD_URL : `${getConfig().LMS_BASE_URL}/dashboard`}>
1515
{intl.formatMessage(messages.dashboard)}
1616
</Dropdown.Item>
1717
);
@@ -23,16 +23,16 @@ const AuthenticatedUserDropdown = ({ intl, username }) => {
2323
<Dropdown.Toggle variant="outline-primary">
2424
<FontAwesomeIcon icon={faUserCircle} className="d-md-none" size="lg" />
2525
<span data-hj-suppress className="d-none d-md-inline">
26-
{username}
26+
{getConfig().SHOW_FULLNAME === 'true' ? name : username}
2727
</span>
2828
</Dropdown.Toggle>
2929
<Dropdown.Menu className="dropdown-menu-right">
3030
{dashboardMenuItem}
31-
<Dropdown.Item href={`${getConfig().ACCOUNT_PROFILE_URL}/u/${username}`}>
31+
<Dropdown.Item href={getConfig().EXTERNAL_ACCOUNT_PROFILE_URL ? getConfig().EXTERNAL_ACCOUNT_PROFILE_URL : `${getConfig().ACCOUNT_PROFILE_URL}/u/${username}`}>
3232
{intl.formatMessage(messages.profile)}
3333
</Dropdown.Item>
3434
<Dropdown.Item href={getConfig().ACCOUNT_SETTINGS_URL}>
35-
{intl.formatMessage(messages.account)}
35+
{getConfig().SHOW_SETTINGS_LABEL === 'true' ? intl.formatMessage(messages.settings) : intl.formatMessage(messages.account)}
3636
</Dropdown.Item>
3737
{ getConfig().ORDER_HISTORY_URL && (
3838
<Dropdown.Item href={getConfig().ORDER_HISTORY_URL}>
@@ -51,6 +51,7 @@ const AuthenticatedUserDropdown = ({ intl, username }) => {
5151
AuthenticatedUserDropdown.propTypes = {
5252
intl: intlShape.isRequired,
5353
username: PropTypes.string.isRequired,
54+
name: PropTypes.string.isRequired,
5455
};
5556

5657
export default injectIntl(AuthenticatedUserDropdown);

src/learning-header/LearningHeader.jsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const LearningHeader = ({
3333
const headerLogo = (
3434
<LinkedLogo
3535
className="logo"
36-
href={`${getConfig().LMS_BASE_URL}/dashboard`}
36+
href={getConfig().DASHBOARD_URL ? getConfig().DASHBOARD_URL : `${getConfig().LMS_BASE_URL}/dashboard`}
3737
src={getConfig().LOGO_URL}
3838
alt={getConfig().SITE_NAME}
3939
/>
@@ -49,9 +49,10 @@ const LearningHeader = ({
4949
<span className="d-block m-0 font-weight-bold course-title">{courseTitle}</span>
5050
</div>
5151
{showUserDropdown && authenticatedUser && (
52-
<AuthenticatedUserDropdown
53-
username={authenticatedUser.username}
54-
/>
52+
<AuthenticatedUserDropdown
53+
username={authenticatedUser.username}
54+
name={authenticatedUser.name}
55+
/>
5556
)}
5657
{showUserDropdown && !authenticatedUser && (
5758
<AnonymousUserMenu />

src/learning-header/messages.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ const messages = defineMessages({
2121
defaultMessage: 'Account',
2222
description: 'The text for the user menu Account navigation link.',
2323
},
24+
settings: {
25+
id: 'header.menu.settings.label',
26+
defaultMessage: 'Settings',
27+
description: 'The text for the user menu Settings navigation link.',
28+
},
2429
orderHistory: {
2530
id: 'header.menu.orderHistory.label',
2631
defaultMessage: 'Order History',

src/setupTest.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ process.env.MARKETING_SITE_BASE_URL = 'http://localhost:18000';
3232
process.env.ORDER_HISTORY_URL = 'localhost:1996/orders';
3333
process.env.REFRESH_ACCESS_TOKEN_ENDPOINT = 'http://localhost:18000/login_refresh';
3434
process.env.SEGMENT_KEY = 'segment_whoa';
35+
process.env.SHOW_FULLNAME = false;
3536
process.env.SITE_NAME = 'edX';
3637
process.env.USER_INFO_COOKIE_NAME = 'edx-user-info';
3738
process.env.LOGO_URL = 'https://edx-cdn.org/v3/default/logo.svg';
@@ -48,6 +49,7 @@ class MockLoggingService {
4849
export const authenticatedUser = {
4950
userId: 'abc123',
5051
username: 'Mock User',
52+
name: 'Mock User Name',
5153
roles: [],
5254
administrator: false,
5355
};
@@ -66,10 +68,12 @@ export function initializeMockApp() {
6668
CSRF_TOKEN_API_PATH: process.env.CSRF_TOKEN_API_PATH || null,
6769
LOGO_URL: process.env.LOGO_URL || null,
6870
SITE_NAME: process.env.SITE_NAME || null,
71+
SHOW_FULLNAME: process.env.SHOW_FULLNAME || null,
6972

7073
authenticatedUser: {
7174
userId: 'abc123',
7275
username: 'Mock User',
76+
name: 'Mock User Name',
7377
roles: [],
7478
administrator: false,
7579
},

0 commit comments

Comments
 (0)