Skip to content
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: add functionality to remove username from header #375

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ USER_INFO_COOKIE_NAME=null
PUBLISHER_BASE_URL=''
APP_ID=''
MFE_CONFIG_API_URL=''
HIDE_USERNAME_FROM_HEADER=''
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ USER_INFO_COOKIE_NAME='edx-user-info'
PUBLISHER_BASE_URL='http://localhost:18400'
APP_ID='support-tools'
MFE_CONFIG_API_URL='http://localhost:18000/api/mfe_config/v1'
HIDE_USERNAME_FROM_HEADER=''
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ SUBSIDY_BASE_URL='http://localhost:18280'
USER_INFO_COOKIE_NAME='edx-user-info'
APP_ID=''
MFE_CONFIG_API_URL=''
HIDE_USERNAME_FROM_HEADER=''
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = createConfig('jest', {
coveragePathIgnorePatterns: [
'/node_modules/',
'src/setupTest.js',
'src/index.jsx',
'src/i18n',
'src/users/v2/UserPage.jsx',
'src/supportHeader/ToggleVersion.jsx',
Expand Down
1 change: 1 addition & 0 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ initialize({
FEATURE_CONFIGURATION_ENTERPRISE_PROVISION: process.env.FEATURE_CONFIGURATION_ENTERPRISE_PROVISION || hasFeatureFlagEnabled('FEATURE_CONFIGURATION_ENTERPRISE_PROVISION') || null,
FEATURE_CONFIGURATION_EDIT_ENTERPRISE_PROVISION: process.env.FEATURE_CONFIGURATION_EDIT_ENTERPRISE_PROVISION || hasFeatureFlagEnabled('FEATURE_CONFIGURATION_EDIT_ENTERPRISE_PROVISION') || null,
SUBSIDY_BASE_URL: process.env.SUBSIDY_BASE_URL || null,
HIDE_USERNAME_FROM_HEADER: process.env.HIDE_USERNAME_FROM_HEADER || false,
});
},
},
Expand Down
18 changes: 15 additions & 3 deletions src/supportHeader/DesktopHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,22 @@ export default class DesktopHeader extends React.Component {
const {
loggedIn,
avatar,
name,
username,
hideUsername,
} = this.props;

return (
<Dropdown>
<Dropdown.Toggle id="desktop-header-dropdown-toggle" as={AvatarButton} src={avatar}>
{username}
</Dropdown.Toggle>
{hideUsername ? (
<Dropdown.Toggle id="desktop-header-dropdown-toggle" showLabel={false} as={AvatarButton} src={avatar}>
{name}
</Dropdown.Toggle>
) : (
<Dropdown.Toggle id="desktop-header-dropdown-toggle" as={AvatarButton} src={avatar}>
{username}
</Dropdown.Toggle>
)}

<Dropdown.Menu alignRight>
{loggedIn ? this.renderUserMenuItems() : this.renderLoggedOutItems()}
Expand Down Expand Up @@ -131,7 +139,9 @@ DesktopHeader.propTypes = {
logoDestination: PropTypes.string,
avatar: PropTypes.string,
username: PropTypes.string,
name: PropTypes.string,
loggedIn: PropTypes.bool,
hideUsername: PropTypes.bool,
};

DesktopHeader.defaultProps = {
Expand All @@ -143,5 +153,7 @@ DesktopHeader.defaultProps = {
logoDestination: null,
avatar: null,
username: null,
name: null,
loggedIn: false,
hideUsername: false,
};
2 changes: 2 additions & 0 deletions src/supportHeader/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ export default function Header() {
logoDestination: getConfig().MINIMAL_HEADER ? null : `${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().MINIMAL_HEADER ? [] : mainMenu,
hideUsername: !!getConfig().HIDE_USERNAME_FROM_HEADER,
userMenu,
loggedOutItems,
};
Expand Down
75 changes: 75 additions & 0 deletions src/supportHeader/Header.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import React from 'react';
import { mergeConfig } from '@edx/frontend-platform';
import { IntlProvider } from '@edx/frontend-platform/i18n';
import { render } from '@testing-library/react';
import { Context as ResponsiveContext } from 'react-responsive';
import { AppContext } from '@edx/frontend-platform/react';

import Header from './Header';

describe('<Header />', () => {
const appContextValue = {
authenticatedUser: {
userId: '123',
username: 'abc',
name: 'full name',
},
config: {
LMS_BASE_URL: process.env.LMS_BASE_URL,
LOGO_URL: 'logo_url.jpg',
},
};

it('renders correctly for authenticated desktop', () => {
const component = (
<ResponsiveContext.Provider value={{ width: 1200 }}>
<IntlProvider locale="en">
<AppContext.Provider value={appContextValue}>
<Header />
</AppContext.Provider>
</IntlProvider>
</ResponsiveContext.Provider>
);

const { container: wrapper } = render(component);
expect(wrapper).toMatchSnapshot();
});

it('renders correctly for authenticated desktop when HIDE_USERNAME_FROM_HEADER is set to true', () => {
mergeConfig({
HIDE_USERNAME_FROM_HEADER: true,
});

const component = (
<ResponsiveContext.Provider value={{ width: 1200 }}>
<IntlProvider locale="en">
<AppContext.Provider value={appContextValue}>
<Header />
</AppContext.Provider>
</IntlProvider>
</ResponsiveContext.Provider>
);

const { container: wrapper } = render(component);
expect(wrapper).toMatchSnapshot();

mergeConfig({
HIDE_USERNAME_FROM_HEADER: '',
});
});

it('renders correctly for authenticated mobile', () => {
const component = (
<ResponsiveContext.Provider value={{ width: 500 }}>
<IntlProvider locale="en">
<AppContext.Provider value={appContextValue}>
<Header />
</AppContext.Provider>
</IntlProvider>
</ResponsiveContext.Provider>
);

const { container: wrapper } = render(component);
expect(wrapper).toMatchSnapshot();
});
});
11 changes: 8 additions & 3 deletions src/supportHeader/MobileHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ export default class MobileHeader extends React.Component {
const {
loggedIn,
avatar,
name,
username,
hideUsername,
} = this.props;

return (
<Dropdown>
<Dropdown.Toggle showLabel={false} size="md" as={AvatarButton} src={avatar}>
{username}
<Dropdown.Toggle id="mobile-header-dropdown-toggle" showLabel={false} size="md" as={AvatarButton} src={avatar}>
{hideUsername ? name : username}
</Dropdown.Toggle>

<Dropdown.Menu alignRight>
Expand Down Expand Up @@ -151,8 +153,10 @@ MobileHeader.propTypes = {
logoDestination: PropTypes.string,
avatar: PropTypes.string,
username: PropTypes.string,
name: PropTypes.string,
loggedIn: PropTypes.bool,
stickyOnMobile: PropTypes.bool,
hideUsername: PropTypes.bool,
};

MobileHeader.defaultProps = {
Expand All @@ -164,7 +168,8 @@ MobileHeader.defaultProps = {
logoDestination: null,
avatar: null,
username: null,
name: null,
loggedIn: false,
stickyOnMobile: true,

hideUsername: false,
};
Loading
Loading