Skip to content

Commit ccc6023

Browse files
committed
feat: remove username
remove username from header VAN-1804
1 parent 3b2a2bf commit ccc6023

File tree

8 files changed

+57
-9
lines changed

8 files changed

+57
-9
lines changed

README.rst

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Environment Variables
4949
* ``ACCOUNT_PROFILE_URL`` - The URL of the account profile page.
5050
* ``ACCOUNT_SETTINGS_URL`` - The URL of the account settings page.
5151
* ``AUTHN_MINIMAL_HEADER`` - A boolean flag which hides the main menu, user menu, and logged-out
52+
* ``ENABLE_HEADER_WITHOUT_USERNAME`` - A boolean flag which hides the username from the header
5253
menu items when truthy. This is intended to be used in micro-frontends like
5354
frontend-app-authentication in which these menus are considered distractions from the user's task.
5455

example/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ subscribe(APP_READY, () => {
2626
authenticatedUser: {
2727
userId: '123abc',
2828
username: 'testuser',
29+
name: 'test user',
2930
roles: [],
3031
administrator: false,
3132
},

src/DesktopHeader.jsx

+33
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ class DesktopHeader extends React.Component {
7373
}
7474

7575
renderUserMenu() {
76+
return (getConfig().ENABLE_HEADER_WITHOUT_USERNAME ? this.userMenuWithoutUsername() : this.userMenuWithUsername());
77+
}
78+
79+
userMenuWithUsername() {
7680
const {
7781
userMenu,
7882
avatar,
@@ -99,6 +103,33 @@ class DesktopHeader extends React.Component {
99103
);
100104
}
101105

106+
userMenuWithoutUsername() {
107+
const {
108+
userMenu,
109+
avatar,
110+
name,
111+
intl,
112+
} = this.props;
113+
114+
return (
115+
<Menu transitionClassName="menu-dropdown" transitionTimeout={250}>
116+
<MenuTrigger
117+
tag="button"
118+
aria-label={intl.formatMessage(messages['header.label.account.menu.for'], { name })}
119+
className="btn btn-outline-primary d-inline-flex align-items-center pl-2 pr-3"
120+
>
121+
<Avatar size="1.5em" src={avatar} alt="" className="mr-2" />
122+
<CaretIcon role="img" aria-hidden focusable="false" />
123+
</MenuTrigger>
124+
<MenuContent className="mb-0 dropdown-menu show dropdown-menu-right pin-right shadow py-2">
125+
{userMenu.map(({ type, href, content }) => (
126+
<a className={`dropdown-${type}`} key={`${type}-${content}`} href={href}>{content}</a>
127+
))}
128+
</MenuContent>
129+
</Menu>
130+
);
131+
}
132+
102133
renderLoggedOutItems() {
103134
const { loggedOutItems } = this.props;
104135

@@ -178,6 +209,7 @@ DesktopHeader.propTypes = {
178209
logoDestination: PropTypes.string,
179210
avatar: PropTypes.string,
180211
username: PropTypes.string,
212+
name: PropTypes.string,
181213
loggedIn: PropTypes.bool,
182214

183215
// i18n
@@ -207,6 +239,7 @@ DesktopHeader.defaultProps = {
207239
logoDestination: null,
208240
avatar: null,
209241
username: null,
242+
name: null,
210243
loggedIn: false,
211244
appMenu: null,
212245
};

src/Header.jsx

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ ensureConfig([
2727
subscribe(APP_CONFIG_INITIALIZED, () => {
2828
mergeConfig({
2929
AUTHN_MINIMAL_HEADER: !!process.env.AUTHN_MINIMAL_HEADER,
30+
ENABLE_HEADER_WITHOUT_USERNAME: !!process.env.ENABLE_HEADER_WITHOUT_USERNAME,
3031
}, 'Header additional config');
3132
});
3233

@@ -94,6 +95,7 @@ const Header = ({ intl }) => {
9495
logoDestination: `${config.LMS_BASE_URL}/dashboard`,
9596
loggedIn: authenticatedUser !== null,
9697
username: authenticatedUser !== null ? authenticatedUser.username : null,
98+
name: authenticatedUser !== null ? authenticatedUser.name : null,
9799
avatar: authenticatedUser !== null ? authenticatedUser.avatar : null,
98100
mainMenu: getConfig().AUTHN_MINIMAL_HEADER ? [] : mainMenu,
99101
userMenu: getConfig().AUTHN_MINIMAL_HEADER ? [] : userMenu,

src/Header.test.jsx

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ describe('<Header />', () => {
4343
authenticatedUser: {
4444
userId: 'abc123',
4545
username: 'edX',
46+
name: 'edX',
4647
roles: [],
4748
administrator: false,
4849
},
@@ -84,6 +85,7 @@ describe('<Header />', () => {
8485
authenticatedUser: {
8586
userId: 'abc123',
8687
username: 'edX',
88+
name: 'edX',
8789
roles: [],
8890
administrator: false,
8991
},

src/__snapshots__/Header.test.jsx.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ exports[`<Header /> renders correctly for authenticated desktop 1`] = `
246246
<button
247247
aria-expanded={false}
248248
aria-haspopup="menu"
249-
aria-label="Account menu for edX"
249+
aria-label="Account menu for {username}"
250250
className="menu-trigger btn btn-outline-primary d-inline-flex align-items-center pl-2 pr-3"
251251
onClick={[Function]}
252252
>

src/learning-header/AuthenticatedUserDropdown.jsx

+14-7
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,35 @@ import PropTypes from 'prop-types';
44
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
55
import { faUserCircle } from '@fortawesome/free-solid-svg-icons';
66
import { getConfig } from '@edx/frontend-platform';
7+
import { Avatar } from '@openedx/paragon';
78
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
89
import { Dropdown } from '@openedx/paragon';
910

1011
import messages from './messages';
1112

12-
const AuthenticatedUserDropdown = ({ intl, username }) => {
13+
const AuthenticatedUserDropdown = ({ intl, username, avatar }) => {
1314
const dashboardMenuItem = (
1415
<Dropdown.Item href={`${getConfig().LMS_BASE_URL}/dashboard`}>
1516
{intl.formatMessage(messages.dashboard)}
1617
</Dropdown.Item>
1718
);
1819

20+
const showDropdownToggle = (
21+
<Dropdown.Toggle variant="outline-primary">
22+
<FontAwesomeIcon icon={faUserCircle} className="d-md-none" size="lg" />
23+
{!getConfig().ENABLE_HEADER_WITHOUT_USERNAME ? (
24+
<span data-hj-suppress className="d-none d-md-inline">
25+
{username}
26+
</span>
27+
) : <Avatar size="sm" src={avatar} alt="" className="mr-2" />}
28+
</Dropdown.Toggle>
29+
);
30+
1931
return (
2032
<>
2133
<a className="text-gray-700" href={`${getConfig().SUPPORT_URL}`}>{intl.formatMessage(messages.help)}</a>
2234
<Dropdown className="user-dropdown ml-3">
23-
<Dropdown.Toggle variant="outline-primary">
24-
<FontAwesomeIcon icon={faUserCircle} className="d-md-none" size="lg" />
25-
<span data-hj-suppress className="d-none d-md-inline">
26-
{username}
27-
</span>
28-
</Dropdown.Toggle>
35+
{showDropdownToggle}
2936
<Dropdown.Menu className="dropdown-menu-right">
3037
{dashboardMenuItem}
3138
<Dropdown.Item href={`${getConfig().ACCOUNT_PROFILE_URL}/u/${username}`}>

src/studio-header/UserMenu.jsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
4+
import { getConfig } from '@edx/frontend-platform';
45
import {
56
Avatar,
67
} from '@openedx/paragon';
@@ -32,7 +33,8 @@ const UserMenu = ({
3233
data-testid="avatar-icon"
3334
/>
3435
);
35-
const title = isMobile ? avatar : <>{avatar}{username}</>;
36+
const showUsername = !getConfig().ENABLE_HEADER_WITHOUT_USERNAME;
37+
const title = isMobile ? avatar : <>{avatar}{showUsername && username}</>;
3638

3739
return (
3840
<NavDropdownMenu

0 commit comments

Comments
 (0)