Skip to content

Commit

Permalink
feat: remove username
Browse files Browse the repository at this point in the history
remove username from header

VAN-1804
  • Loading branch information
mubbsharanwar committed Feb 2, 2024
1 parent 3b2a2bf commit ccc6023
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Environment Variables
* ``ACCOUNT_PROFILE_URL`` - The URL of the account profile page.
* ``ACCOUNT_SETTINGS_URL`` - The URL of the account settings page.
* ``AUTHN_MINIMAL_HEADER`` - A boolean flag which hides the main menu, user menu, and logged-out
* ``ENABLE_HEADER_WITHOUT_USERNAME`` - A boolean flag which hides the username from the header
menu items when truthy. This is intended to be used in micro-frontends like
frontend-app-authentication in which these menus are considered distractions from the user's task.

Expand Down
1 change: 1 addition & 0 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ subscribe(APP_READY, () => {
authenticatedUser: {
userId: '123abc',
username: 'testuser',
name: 'test user',
roles: [],
administrator: false,
},
Expand Down
33 changes: 33 additions & 0 deletions src/DesktopHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ class DesktopHeader extends React.Component {
}

renderUserMenu() {
return (getConfig().ENABLE_HEADER_WITHOUT_USERNAME ? this.userMenuWithoutUsername() : this.userMenuWithUsername());
}

Check failure on line 78 in src/DesktopHeader.jsx

View workflow job for this annotation

GitHub Actions / tests

Trailing spaces not allowed
userMenuWithUsername() {
const {
userMenu,
avatar,
Expand All @@ -99,6 +103,33 @@ class DesktopHeader extends React.Component {
);
}

userMenuWithoutUsername() {
const {
userMenu,
avatar,
name,
intl,
} = this.props;

return (
<Menu transitionClassName="menu-dropdown" transitionTimeout={250}>
<MenuTrigger
tag="button"
aria-label={intl.formatMessage(messages['header.label.account.menu.for'], { name })}
className="btn btn-outline-primary d-inline-flex align-items-center pl-2 pr-3"
>
<Avatar size="1.5em" src={avatar} alt="" className="mr-2" />
<CaretIcon role="img" aria-hidden focusable="false" />
</MenuTrigger>
<MenuContent className="mb-0 dropdown-menu show dropdown-menu-right pin-right shadow py-2">
{userMenu.map(({ type, href, content }) => (
<a className={`dropdown-${type}`} key={`${type}-${content}`} href={href}>{content}</a>
))}
</MenuContent>
</Menu>
);
}

renderLoggedOutItems() {
const { loggedOutItems } = this.props;

Expand Down Expand Up @@ -178,6 +209,7 @@ DesktopHeader.propTypes = {
logoDestination: PropTypes.string,
avatar: PropTypes.string,
username: PropTypes.string,
name: PropTypes.string,
loggedIn: PropTypes.bool,

// i18n
Expand Down Expand Up @@ -207,6 +239,7 @@ DesktopHeader.defaultProps = {
logoDestination: null,
avatar: null,
username: null,
name: null,
loggedIn: false,
appMenu: null,
};
Expand Down
2 changes: 2 additions & 0 deletions src/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ensureConfig([
subscribe(APP_CONFIG_INITIALIZED, () => {
mergeConfig({
AUTHN_MINIMAL_HEADER: !!process.env.AUTHN_MINIMAL_HEADER,
ENABLE_HEADER_WITHOUT_USERNAME: !!process.env.ENABLE_HEADER_WITHOUT_USERNAME,
}, 'Header additional config');
});

Expand Down Expand Up @@ -94,6 +95,7 @@ const Header = ({ intl }) => {
logoDestination: `${config.LMS_BASE_URL}/dashboard`,
loggedIn: authenticatedUser !== null,
username: authenticatedUser !== null ? authenticatedUser.username : null,
name: authenticatedUser !== null ? authenticatedUser.name : null,
avatar: authenticatedUser !== null ? authenticatedUser.avatar : null,
mainMenu: getConfig().AUTHN_MINIMAL_HEADER ? [] : mainMenu,
userMenu: getConfig().AUTHN_MINIMAL_HEADER ? [] : userMenu,
Expand Down
2 changes: 2 additions & 0 deletions src/Header.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('<Header />', () => {
authenticatedUser: {
userId: 'abc123',
username: 'edX',
name: 'edX',
roles: [],
administrator: false,
},
Expand Down Expand Up @@ -84,6 +85,7 @@ describe('<Header />', () => {
authenticatedUser: {
userId: 'abc123',
username: 'edX',
name: 'edX',
roles: [],
administrator: false,
},
Expand Down
2 changes: 1 addition & 1 deletion src/__snapshots__/Header.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ exports[`<Header /> renders correctly for authenticated desktop 1`] = `
<button
aria-expanded={false}
aria-haspopup="menu"
aria-label="Account menu for edX"
aria-label="Account menu for {username}"
className="menu-trigger btn btn-outline-primary d-inline-flex align-items-center pl-2 pr-3"
onClick={[Function]}
>
Expand Down
21 changes: 14 additions & 7 deletions src/learning-header/AuthenticatedUserDropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,35 @@ 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 { Avatar } from '@openedx/paragon';

Check failure on line 7 in src/learning-header/AuthenticatedUserDropdown.jsx

View workflow job for this annotation

GitHub Actions / tests

'/home/runner/work/frontend-component-header/frontend-component-header/node_modules/@openedx/paragon/dist/index.js' imported multiple times
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { Dropdown } from '@openedx/paragon';

Check failure on line 9 in src/learning-header/AuthenticatedUserDropdown.jsx

View workflow job for this annotation

GitHub Actions / tests

'/home/runner/work/frontend-component-header/frontend-component-header/node_modules/@openedx/paragon/dist/index.js' imported multiple times

import messages from './messages';

const AuthenticatedUserDropdown = ({ intl, username }) => {
const AuthenticatedUserDropdown = ({ intl, username, avatar }) => {

Check failure on line 13 in src/learning-header/AuthenticatedUserDropdown.jsx

View workflow job for this annotation

GitHub Actions / tests

'avatar' is missing in props validation
const dashboardMenuItem = (
<Dropdown.Item href={`${getConfig().LMS_BASE_URL}/dashboard`}>
{intl.formatMessage(messages.dashboard)}
</Dropdown.Item>
);

const showDropdownToggle = (
<Dropdown.Toggle variant="outline-primary">
<FontAwesomeIcon icon={faUserCircle} className="d-md-none" size="lg" />

Check failure on line 22 in src/learning-header/AuthenticatedUserDropdown.jsx

View workflow job for this annotation

GitHub Actions / tests

Expected indentation of 6 space characters but found 8
{!getConfig().ENABLE_HEADER_WITHOUT_USERNAME ? (

Check failure on line 23 in src/learning-header/AuthenticatedUserDropdown.jsx

View workflow job for this annotation

GitHub Actions / tests

Expected indentation of 6 space characters but found 8
<span data-hj-suppress className="d-none d-md-inline">
{username}
</span>
) : <Avatar size="sm" src={avatar} alt="" className="mr-2" />}
</Dropdown.Toggle>
);

return (
<>
<a className="text-gray-700" href={`${getConfig().SUPPORT_URL}`}>{intl.formatMessage(messages.help)}</a>
<Dropdown className="user-dropdown ml-3">
<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>
{showDropdownToggle}
<Dropdown.Menu className="dropdown-menu-right">
{dashboardMenuItem}
<Dropdown.Item href={`${getConfig().ACCOUNT_PROFILE_URL}/u/${username}`}>
Expand Down
4 changes: 3 additions & 1 deletion src/studio-header/UserMenu.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { getConfig } from '@edx/frontend-platform';
import {
Avatar,
} from '@openedx/paragon';
Expand Down Expand Up @@ -32,7 +33,8 @@ const UserMenu = ({
data-testid="avatar-icon"
/>
);
const title = isMobile ? avatar : <>{avatar}{username}</>;
const showUsername = !getConfig().ENABLE_HEADER_WITHOUT_USERNAME;
const title = isMobile ? avatar : <>{avatar}{showUsername && username}</>;

return (
<NavDropdownMenu
Expand Down

0 comments on commit ccc6023

Please sign in to comment.