Skip to content

Commit 5baeb14

Browse files
committed
feat: display multiple dashboards and some style fixes
1 parent d1ed685 commit 5baeb14

8 files changed

Lines changed: 59 additions & 48 deletions

File tree

.env.development

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ FAVICON_URL=https://edx-cdn.org/v3/prod/favicon.ico
2323
NOTIFICATION_FEEDBACK_URL=''
2424
CAREERS_URL=''
2525
STUDIO_BASE_URL=''
26+
ENABLE_EDX_PERSONAL_DASHBOARD=true

.env.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ FAVICON_URL=https://edx-cdn.org/v3/prod/favicon.ico
2323
NOTIFICATION_FEEDBACK_URL=''
2424
CAREERS_URL=''
2525
STUDIO_BASE_URL=''
26+
ENABLE_EDX_PERSONAL_DASHBOARD=true

src/Header.jsx

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const Header = ({
7373
type: 'item',
7474
href: `${config.LMS_BASE_URL}/dashboard`,
7575
content: intl.formatMessage(messages['header.links.courses']),
76-
isActive: document.title.includes('Learner Home'),
76+
isActive: document.title.includes(intl.formatMessage(messages['header.pages.learner.home'])),
7777
},
7878
{
7979
type: 'item',
@@ -93,26 +93,12 @@ const Header = ({
9393
},
9494
];
9595

96-
// const dashboardMenuItem = {
97-
// type: 'item',
98-
// href: `${config.LMS_BASE_URL}/dashboard`,
99-
// content: intl.formatMessage(messages['header.user.menu.dashboard']),
100-
// };
101-
10296
const logoutMenuItem = {
10397
type: 'item',
10498
href: config.LOGOUT_URL,
10599
content: intl.formatMessage(messages['header.user.menu.logout']),
106100
};
107101

108-
// If there is an Enterprise LP link, use that instead of the B2C Dashboard
109-
// let baseUserMenuDashboardLinks = [];
110-
// if (enterpriseLearnerPortalLink) {
111-
// baseUserMenuDashboardLinks = [enterpriseLearnerPortalLink];
112-
// } else {
113-
// baseUserMenuDashboardLinks = [dashboardMenuItem];
114-
// }
115-
116102
const defaultSecondaryMenu = [
117103
...(getConfig().SUPPORT_URL ? [{
118104
type: 'item',
@@ -125,7 +111,10 @@ const Header = ({
125111
const defaultUserMenu = authenticatedUser === null ? [] : [{
126112
heading: '',
127113
items: [
128-
// ...baseUserMenuDashboardLinks,
114+
// Users should only see Career button if they do not have an available
115+
// learner portal, because an available learner portal currently means
116+
// that they access content via B2B Subscriptions, in which context "career" button
117+
// is not relevant.
129118
...(!enterpriseLearnerPortalLink ? [{
130119
type: 'item',
131120
href: 'https://careers.edx.org/',
@@ -141,13 +130,13 @@ const Header = ({
141130
type: 'item',
142131
href: `${config.ACCOUNT_PROFILE_URL}/u/${authenticatedUser.username}`,
143132
content: intl.formatMessage(messages['header.user.menu.profile']),
144-
isActive: document.title.includes('Profile'),
133+
isActive: document.title.includes(intl.formatMessage(messages['header.user.menu.profile'])),
145134
},
146135
{
147136
type: 'item',
148137
href: config.ACCOUNT_SETTINGS_URL,
149138
content: intl.formatMessage(messages['header.user.menu.account.settings']),
150-
isActive: document.title.includes('Account'),
139+
isActive: document.title.includes(intl.formatMessage(messages['header.user.menu.account.settings'])),
151140
},
152141
// Users should only see Order History if they do not have an available
153142
// learner portal and have a ORDER_HISTORY_URL define in the environment,
@@ -167,11 +156,17 @@ const Header = ({
167156
const secondaryMenu = secondaryMenuItems || defaultSecondaryMenu;
168157
let userMenu = authenticatedUser === null ? [] : userMenuItems || defaultUserMenu;
169158

159+
const minimalDashboardMenuItem = {
160+
type: 'item',
161+
href: `${config.LMS_BASE_URL}/dashboard`,
162+
content: intl.formatMessage(messages['header.user.menu.dashboard']),
163+
};
164+
170165
if (getConfig().MINIMAL_HEADER && authenticatedUser !== null) {
171166
userMenu = [{
172167
heading: '',
173168
items: [
174-
// dashboardMenuItem,
169+
minimalDashboardMenuItem,
175170
logoutMenuItem,
176171
],
177172
}];

src/Header.messages.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { defineMessages } from '@edx/frontend-platform/i18n';
22

33
const messages = defineMessages({
4+
'header.pages.learner.home': {
5+
id: 'header.pages.learner.home',
6+
defaultMessage: 'Learner Home',
7+
description: 'Title of the page in learner dashboard',
8+
},
49
'header.links.courses': {
510
id: 'header.links.courses',
611
defaultMessage: 'Courses',

src/Header.test.jsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react';
33
import { act } from 'react-dom/test-utils';
44
import { IntlProvider } from '@edx/frontend-platform/i18n';
55
import TestRenderer from 'react-test-renderer';
6-
import { useEnterpriseConfig } from '@edx/frontend-enterprise-utils';
6+
import { isEnterpriseUser, useEnterpriseConfig } from '@edx/frontend-enterprise-utils';
77
import { AppContext } from '@edx/frontend-platform/react';
88
import { getConfig } from '@edx/frontend-platform';
99
import { Context as ResponsiveContext } from 'react-responsive';
@@ -44,6 +44,10 @@ const HeaderContext = ({ width, contextValue }) => (
4444
describe('<Header />', () => {
4545
beforeEach(() => {
4646
useEnterpriseConfig.mockReturnValue({});
47+
getConfig.mockReturnValue({
48+
ENABLE_EDX_PERSONAL_DASHBOARD: true,
49+
SUPPORT_URL: 'http://localhost:18000/support'
50+
});
4751
});
4852

4953
beforeAll(async () => {
@@ -66,6 +70,10 @@ describe('<Header />', () => {
6670
});
6771
};
6872

73+
const mockIsEnterpriseUser = () => {
74+
isEnterpriseUser.mockReturnValue(true);
75+
};
76+
6977
it('renders correctly for unauthenticated users on desktop', () => {
7078
const contextValue = {
7179
authenticatedUser: null,
@@ -138,22 +146,26 @@ describe('<Header />', () => {
138146
});
139147

140148
expect(screen.getByText('Order History')).toBeInTheDocument();
149+
expect(screen.queryByText('Career')).toBeInTheDocument();
150+
expect(screen.getByText('Help')).toBeInTheDocument();
141151
expect(screen.getByText('Dashboard')).toBeInTheDocument();
142152

143153
wrapper.unmount();
144154

145-
// When learner portal links are present, Order History should not be a dropdown item
155+
// When learner portal links are present, Order History and Career should not be a dropdown item
146156
// We do this in the same test to avoid weird things about jest wanting you to use
147157
// the "correct" act() function (even though it gives the same warning regardless
148158
// of where you import it from, be it react-dom/test-utils or react-test-renderer).
159+
mockIsEnterpriseUser();
149160
mockUseEnterpriseConfig();
150161
wrapper = render(component);
151162
await act(async () => {
152163
await flushPromises();
153164
fireEvent.click(wrapper.container.querySelector('#menu-dropdown'));
154165
});
155166
expect(screen.queryByText('Order History')).not.toBeInTheDocument();
156-
expect(screen.getByText('Dashboard')).toBeInTheDocument();
167+
expect(screen.queryByText('Career')).not.toBeInTheDocument();
168+
expect(screen.getByText('Personal')).toBeInTheDocument();
157169
});
158170

159171
it('renders correctly for unauthenticated users on mobile', () => {

src/__snapshots__/Header.test.jsx.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ exports[`<Header /> renders correctly for authenticated users on desktop 1`] = `
161161
aria-label="Secondary"
162162
className="nav secondary-menu-container align-items-center ml-auto"
163163
>
164+
<a
165+
className="nav-link"
166+
href="http://localhost:18000/support"
167+
onClick={null}
168+
>
169+
Help
170+
</a>
164171
<div
165172
className="pgn__dropdown pgn__dropdown-light dropdown"
166173
data-testid="dropdown"

src/common/UserDashboardMenu/index.test.jsx

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ import {
55
screen,
66
render,
77
} from '@testing-library/react';
8-
import { useEnterpriseConfig } from '@edx/frontend-enterprise-utils';
98

109
import UserDashboardMenu from './index'; // eslint-disable-line
1110

12-
jest.mock('@edx/frontend-enterprise-utils');
1311
mergeConfig({ ENABLE_EDX_PERSONAL_DASHBOARD: true });
1412
const IntlUserDashboardMenu = injectIntl(UserDashboardMenu);
1513

@@ -21,25 +19,24 @@ describe('User Dashboard Menu', () => {
2119
</IntlProvider>
2220
);
2321

24-
it('should render dashboard menu in the user menu dropdown', () => {
25-
useEnterpriseConfig.mockReturnValue({
26-
enterpriseLearnerPortalLink: {
27-
type: 'item',
28-
href: 'http://localhost:8000',
29-
content: 'Dashboard',
30-
},
31-
enterpriseCustomerBrandingConfig: {
32-
logoAltText: 'fake-enterprise-name',
33-
logoDestination: 'http://fake.url',
34-
logo: 'http://fake-logo.url',
35-
},
36-
});
37-
38-
render(Wrapper(<IntlUserDashboardMenu />));
22+
it('should render enterprise dashboard menu in the user menu dropdown', () => {
23+
render(Wrapper(<IntlUserDashboardMenu
24+
enterpriseOrg="Fake Enterprise"
25+
enterpriseSrc="http://fake.url"
26+
hasEnterpriseAccount
27+
/>));
3928

4029
const dashboardSwitchMenu = screen.getByText('SWITCH DASHBOARD');
41-
const dashboardMenu = screen.getByText('Personal');
42-
expect(dashboardMenu).toBeTruthy();
30+
const personalDashboard = screen.getByText('Personal');
31+
const enterpriseDashboard = screen.getByText('Fake Enterprise Dashboard');
4332
expect(dashboardSwitchMenu).toBeTruthy();
33+
expect(personalDashboard).toBeTruthy();
34+
expect(enterpriseDashboard).toBeTruthy();
35+
});
36+
it('should render only one dashboard menu in the user menu dropdown when not enterprise user', () => {
37+
render(Wrapper(<IntlUserDashboardMenu />));
38+
39+
const personalDashboard = screen.getByText('Dashboard');
40+
expect(personalDashboard).toBeTruthy();
4441
});
4542
});

src/index.scss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
$spacer: 1rem;
2-
$blue: #007db8;
3-
$white: #fff;
4-
$component-active-bg: #0A3055FF !default;
5-
$component-active-color: $white !default;
6-
$rounded-pill: 50rem !default;
7-
81
@import './Menu/menu.scss';
92
@import './studio-header/StudioHeader.scss';
103

0 commit comments

Comments
 (0)