Skip to content

Commit

Permalink
refactor: use comparison to compare bool var
Browse files Browse the repository at this point in the history
  • Loading branch information
asadali145 committed Apr 1, 2024
1 parent 49ec111 commit 74f17da
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ MARKETING_SITE_BASE_URL=http://localhost:18000
ORDER_HISTORY_URL=localhost:1996/orders
REFRESH_ACCESS_TOKEN_ENDPOINT=http://localhost:18000/login_refresh
SEGMENT_KEY=null
SHOW_FULLNAME=false
SHOW_SETTINGS_LABEL=false
SHOW_FULLNAME='false'
SHOW_SETTINGS_LABEL='false'
SITE_NAME=Open edX
USER_INFO_COOKIE_NAME=edx-user-info
LOGO_URL=https://edx-cdn.org/v3/default/logo.svg
Expand Down
6 changes: 0 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const Header = ({ intl }) => {
{
type: 'item',
href: config.ACCOUNT_SETTINGS_URL,
content: config.SHOW_SETTINGS_LABEL ? intl.formatMessage(messages['header.user.menu.settings']) : intl.formatMessage(messages['header.user.menu.account']),
content: config.SHOW_SETTINGS_LABEL === 'true' ? intl.formatMessage(messages['header.user.menu.settings']) : intl.formatMessage(messages['header.user.menu.account']),
},
{
type: 'item',
Expand Down Expand Up @@ -94,7 +94,7 @@ const Header = ({ intl }) => {
];

let name = null

Check failure on line 96 in src/Header.jsx

View workflow job for this annotation

GitHub Actions / tests

Missing semicolon
if (authenticatedUser !== null && config.SHOW_FULLNAME) {
if (authenticatedUser !== null && config.SHOW_FULLNAME === 'true') {
name = authenticatedUser.name

Check failure on line 98 in src/Header.jsx

View workflow job for this annotation

GitHub Actions / tests

Missing semicolon
} else if (authenticatedUser !== null) {
name = authenticatedUser.username

Check failure on line 100 in src/Header.jsx

View workflow job for this annotation

GitHub Actions / tests

Missing semicolon
Expand Down
7 changes: 4 additions & 3 deletions src/learning-header/AuthenticatedUserDropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Dropdown } from '@openedx/paragon';

import messages from './messages';

const AuthenticatedUserDropdown = ({ intl, name }) => {
const AuthenticatedUserDropdown = ({ intl, username, name }) => {
const dashboardMenuItem = (
<Dropdown.Item href={`${getConfig().LMS_BASE_URL}/dashboard`}>
{intl.formatMessage(messages.dashboard)}
Expand All @@ -23,7 +23,7 @@ const AuthenticatedUserDropdown = ({ intl, name }) => {
<Dropdown.Toggle variant="outline-primary">
<FontAwesomeIcon icon={faUserCircle} className="d-md-none" size="lg" />
<span data-hj-suppress className="d-none d-md-inline">
{name}
{getConfig().SHOW_FULLNAME === 'true' ? name : username}
</span>
</Dropdown.Toggle>
<Dropdown.Menu className="dropdown-menu-right">
Expand All @@ -32,7 +32,7 @@ const AuthenticatedUserDropdown = ({ intl, name }) => {
{intl.formatMessage(messages.profile)}
</Dropdown.Item>
<Dropdown.Item href={getConfig().ACCOUNT_SETTINGS_URL}>
{getConfig().SHOW_SETTINGS_LABEL ? intl.formatMessage(messages.settings) : intl.formatMessage(messages.account)}
{getConfig().SHOW_SETTINGS_LABEL === 'true' ? intl.formatMessage(messages.settings) : intl.formatMessage(messages.account)}
</Dropdown.Item>
{ getConfig().ORDER_HISTORY_URL && (
<Dropdown.Item href={getConfig().ORDER_HISTORY_URL}>
Expand All @@ -50,6 +50,7 @@ const AuthenticatedUserDropdown = ({ intl, name }) => {

AuthenticatedUserDropdown.propTypes = {
intl: intlShape.isRequired,
username: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
};

Expand Down
3 changes: 2 additions & 1 deletion src/learning-header/LearningHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ const LearningHeader = ({
</div>
{showUserDropdown && authenticatedUser && (
<AuthenticatedUserDropdown
name={getConfig().SHOW_FULLNAME ? authenticatedUser.name : authenticatedUser.username}
username={authenticatedUser.username}
name={authenticatedUser.name}
/>
)}
{showUserDropdown && !authenticatedUser && (
Expand Down
4 changes: 4 additions & 0 deletions src/setupTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ process.env.MARKETING_SITE_BASE_URL = 'http://localhost:18000';
process.env.ORDER_HISTORY_URL = 'localhost:1996/orders';
process.env.REFRESH_ACCESS_TOKEN_ENDPOINT = 'http://localhost:18000/login_refresh';
process.env.SEGMENT_KEY = 'segment_whoa';
process.env.SHOW_FULLNAME = false;
process.env.SITE_NAME = 'edX';
process.env.USER_INFO_COOKIE_NAME = 'edx-user-info';
process.env.LOGO_URL = 'https://edx-cdn.org/v3/default/logo.svg';
Expand All @@ -48,6 +49,7 @@ class MockLoggingService {
export const authenticatedUser = {
userId: 'abc123',
username: 'Mock User',
name: 'Mock User Name',
roles: [],
administrator: false,
};
Expand All @@ -66,10 +68,12 @@ export function initializeMockApp() {
CSRF_TOKEN_API_PATH: process.env.CSRF_TOKEN_API_PATH || null,
LOGO_URL: process.env.LOGO_URL || null,
SITE_NAME: process.env.SITE_NAME || null,
SHOW_FULLNAME: process.env.SHOW_FULLNAME || null,

authenticatedUser: {
userId: 'abc123',
username: 'Mock User',
name: 'Mock User Name',
roles: [],
administrator: false,
},
Expand Down

0 comments on commit 74f17da

Please sign in to comment.