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

Upgraded frontend-build version #593

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c8e76ba
refactor: updated frontend-build version
BilalQamar95 Aug 4, 2022
86e15db
refactor: resolved eslint issues
BilalQamar95 Aug 4, 2022
9f917d8
refactor: resolved eslint issues
BilalQamar95 Aug 4, 2022
d5dd932
refactor: resolved eslint issues
BilalQamar95 Aug 4, 2022
698d52f
Merge branch 'master' of https://github.com/openedx/frontend-app-lear…
BilalQamar95 Aug 16, 2022
1914ac9
refactor: updated package-lock & resolved eslint after master branch …
BilalQamar95 Aug 16, 2022
67bc7d6
refactor: updated files to ignore jsx-no-useless-fragment rule
BilalQamar95 Aug 22, 2022
fbe59f5
Merge branch 'master' of https://github.com/openedx/frontend-app-lear…
BilalQamar95 Aug 22, 2022
656ef07
refactor: resolved eslint issues post master branch merge
BilalQamar95 Aug 22, 2022
e478a32
refactor: resolved merge conflicts with master
BilalQamar95 Sep 1, 2022
d31f1e3
refactor: resolved eslint issues after master branch merge
BilalQamar95 Sep 1, 2022
b0a3664
refactor: resolved failing test cases
BilalQamar95 Sep 1, 2022
b9f3e23
refactor: implemented suggested changes
BilalQamar95 Sep 5, 2022
8c1b8b4
refactor: updated tests to accommodate jsx-no-constructed-context-val…
BilalQamar95 Sep 16, 2022
8f6bcfe
Merge branch 'master' of https://github.com/openedx/frontend-app-lear…
BilalQamar95 Oct 27, 2022
9e4a052
refactor: updated frontend-build & resolved eslint issues
BilalQamar95 Oct 28, 2022
5dee7ad
Merge branch 'master' of https://github.com/openedx/frontend-app-lear…
BilalQamar95 Nov 17, 2022
3063711
refactor: resolved eslint issues
BilalQamar95 Nov 17, 2022
3f4a0ad
Merge branch 'master' of https://github.com/openedx/frontend-app-lear…
BilalQamar95 Dec 29, 2022
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
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// eslint-disable-next-line import/no-extraneous-dependencies
const { getBaseConfig } = require('@edx/frontend-build');

const config = getBaseConfig('eslint');

// Ignore linting on module.config.js
Expand All @@ -8,7 +10,7 @@ config.ignorePatterns = ['module.config.js'];
// since they are causing eslint to fail for no apparent reason since
// upgrading @edx/frontend-build from v3 to v5:
// - TypeError: Cannot read property 'range' of null
config.rules['indent'] = ['error', 2, { 'ignoredNodes': ['TemplateLiteral', 'SwitchCase'] }];
config.rules.indent = ['error', 2, { ignoredNodes: ['TemplateLiteral', 'SwitchCase'] }];
config.rules['template-curly-spacing'] = 'off';
config.rules['import/prefer-default-export'] = 'off';

Expand Down
13,224 changes: 5,694 additions & 7,530 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
},
"devDependencies": {
"@edx/browserslist-config": "1.1.1",
"@edx/frontend-build": "11.0.2",
"@edx/frontend-build": "12.3.0",
"@testing-library/jest-dom": "5.11.9",
"@testing-library/react": "11.2.7",
"@testing-library/react-hooks": "3.7.0",
Expand Down
2 changes: 1 addition & 1 deletion src/components/TagCloud/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ TagCloud.propTypes = {
tags: PropTypes.arrayOf(
PropTypes.shape({
title: PropTypes.string.isRequired,
metadata: PropTypes.object.isRequired,
metadata: PropTypes.shape({}).isRequired,
}),
).isRequired,
};
Expand Down
12 changes: 8 additions & 4 deletions src/components/Toasts/ToastsProvider.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React, { createContext, useState } from 'react';
import React, {
createContext, useCallback, useState, useMemo,
} from 'react';
import PropTypes from 'prop-types';

export const ToastsContext = createContext();
Expand All @@ -16,17 +18,19 @@ const ToastsProvider = ({ children }) => {
]);
};

const removeToast = (id) => {
const removeToast = useCallback((id) => {
const index = toasts.findIndex(toast => toast.id === id);
setToasts((prevToasts) => {
const newToasts = [...prevToasts];
newToasts.splice(index, 1);
return newToasts;
});
};
}, [toasts]);

const contextValue = useMemo(() => ({ toasts, addToast, removeToast }), [removeToast, toasts]);

return (
<ToastsContext.Provider value={{ toasts, addToast, removeToast }}>
<ToastsContext.Provider value={contextValue}>
{children}
</ToastsContext.Provider>
);
Expand Down
8 changes: 5 additions & 3 deletions src/components/app/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { initializeHotjar } from '@edx/frontend-enterprise-hotjar';
import AuthenticatedPage from './AuthenticatedPage';
import EnterpriseAppPageRoutes from './EnterpriseAppPageRoutes';
import NotFoundPage from '../NotFoundPage';
import NoticesProvider from '../notices-provider';
import { NoticesProvider } from '../notices-provider';
import {
EnterpriseCustomerRedirect,
EnterprisePageRedirect,
Expand All @@ -16,7 +16,7 @@ import { EnterpriseInvitePage } from '../enterprise-invite';
import { ExecutiveEducation2UPage } from '../executive-education-2u';
import { ToastsProvider, Toasts } from '../Toasts';

export default function App() {
const App = () => {
useEffect(() => {
if (process.env.HOTJAR_APP_ID) {
try {
Expand Down Expand Up @@ -56,4 +56,6 @@ export default function App() {
</NoticesProvider>
</AppProvider>
);
}
};

export default App;
6 changes: 4 additions & 2 deletions src/components/app/AuthenticatedPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Layout } from '../layout';
import LoginRefresh from './LoginRefresh';
import { ErrorPage } from '../error-page';

export default function AuthenticatedPage({ children, useEnterpriseConfigCache }) {
const AuthenticatedPage = ({ children, useEnterpriseConfigCache }) => {
const location = useLocation();
const params = new URLSearchParams(location.search);
const { enterpriseSlug } = useParams();
Expand Down Expand Up @@ -55,7 +55,7 @@ export default function AuthenticatedPage({ children, useEnterpriseConfigCache }
</LoginRefresh>
</LoginRedirect>
);
}
};

AuthenticatedPage.propTypes = {
children: PropTypes.node.isRequired,
Expand All @@ -65,3 +65,5 @@ AuthenticatedPage.propTypes = {
AuthenticatedPage.defaultProps = {
useEnterpriseConfigCache: true,
};

export default AuthenticatedPage;
24 changes: 12 additions & 12 deletions src/components/app/AuthenticatedUserSubsidyPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import {
} from '../enterprise-user-subsidy';
import { SubsidyRequestsContextProvider } from '../enterprise-subsidy-requests';

export default function AuthenticatedUserSubsidyPage({ children }) {
return (
<AuthenticatedPage>
<UserSubsidy>
<SubsidyRequestsContextProvider>
<AutoActivateLicense />
{children}
</SubsidyRequestsContextProvider>
</UserSubsidy>
</AuthenticatedPage>
);
}
const AuthenticatedUserSubsidyPage = ({ children }) => (
<AuthenticatedPage>
<UserSubsidy>
<SubsidyRequestsContextProvider>
<AutoActivateLicense />
{children}
</SubsidyRequestsContextProvider>
</UserSubsidy>
</AuthenticatedPage>
);

AuthenticatedUserSubsidyPage.propTypes = {
children: PropTypes.node.isRequired,
};

export default AuthenticatedUserSubsidyPage;
50 changes: 24 additions & 26 deletions src/components/app/EnterpriseAppPageRoutes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,29 @@ import { features } from '../../config';
import { LicenseActivationPage } from '../license-activation';
import { PathwayProgressPage } from '../pathway-progress';

function EnterpriseAppPageRoutes() {
return (
<AuthenticatedUserSubsidyPage>
<PageRoute exact path="/:enterpriseSlug" component={DashboardPage} />
<PageRoute
exact
path={['/:enterpriseSlug/search', '/:enterpriseSlug/search/:pathwayUUID']}
component={SearchPage}
/>
<PageRoute exact path="/:enterpriseSlug/course/:courseKey" component={CoursePage} />
{features.ENABLE_PROGRAMS && (
<PageRoute exact path="/:enterpriseSlug/program/:programUuid" component={ProgramPage} />
)}
{
// Deprecated URL, will be removed in the future.
<PageRoute exact path="/:enterpriseSlug/program-progress/:programUUID" component={ProgramProgressRedirect} />
}
<PageRoute exact path="/:enterpriseSlug/program/:programUUID/progress" component={ProgramProgressPage} />
<PageRoute exact path="/:enterpriseSlug/skills-quiz" component={SkillsQuizPage} />
<PageRoute exact path="/:enterpriseSlug/licenses/:activationKey/activate" component={LicenseActivationPage} />
{features.FEATURE_ENABLE_PATHWAY_PROGRESS && (
<PageRoute exact path="/:enterpriseSlug/pathway/:pathwayUUID/progress" component={PathwayProgressPage} />
)}
</AuthenticatedUserSubsidyPage>
);
}
const EnterpriseAppPageRoutes = () => (
<AuthenticatedUserSubsidyPage>
<PageRoute exact path="/:enterpriseSlug" component={DashboardPage} />
<PageRoute
exact
path={['/:enterpriseSlug/search', '/:enterpriseSlug/search/:pathwayUUID']}
component={SearchPage}
/>
<PageRoute exact path="/:enterpriseSlug/course/:courseKey" component={CoursePage} />
{features.ENABLE_PROGRAMS && (
<PageRoute exact path="/:enterpriseSlug/program/:programUuid" component={ProgramPage} />
)}
{
// Deprecated URL, will be removed in the future.
<PageRoute exact path="/:enterpriseSlug/program-progress/:programUUID" component={ProgramProgressRedirect} />
}
<PageRoute exact path="/:enterpriseSlug/program/:programUUID/progress" component={ProgramProgressPage} />
<PageRoute exact path="/:enterpriseSlug/skills-quiz" component={SkillsQuizPage} />
<PageRoute exact path="/:enterpriseSlug/licenses/:activationKey/activate" component={LicenseActivationPage} />
{features.FEATURE_ENABLE_PATHWAY_PROGRESS && (
<PageRoute exact path="/:enterpriseSlug/pathway/:pathwayUUID/progress" component={PathwayProgressPage} />
)}
</AuthenticatedUserSubsidyPage>
);

export default EnterpriseAppPageRoutes;
11 changes: 9 additions & 2 deletions src/components/app/LoginRefresh.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { useContext, useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import { AppContext } from '@edx/frontend-platform/react';
import { Container } from '@edx/paragon';

import { LoadingSpinner } from '../loading-spinner';
import { loginRefresh } from '../../utils/common';

export default function LoginRefresh({ children }) {
const LoginRefresh = ({ children }) => {
const { authenticatedUser } = useContext(AppContext);
const { roles } = authenticatedUser;

Expand All @@ -32,4 +33,10 @@ export default function LoginRefresh({ children }) {
);
}
return children;
}
};

LoginRefresh.propTypes = {
children: PropTypes.node.isRequired,
};

export default LoginRefresh;
22 changes: 12 additions & 10 deletions src/components/app/LoginRefresh.test.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useMemo } from 'react';
import '@testing-library/jest-dom/extend-expect';
import { render, act } from '@testing-library/react';
import { AppContext } from '@edx/frontend-platform/react';
Expand All @@ -9,19 +9,21 @@ import * as utils from '../../utils/common';
jest.mock('../../utils/common');

// eslint-disable-next-line react/prop-types
const LoginRefreshWithContext = ({ roles = [] }) => (
<AppContext.Provider value={{
const LoginRefreshWithContext = ({ roles = [] }) => {
const contextValue = useMemo(() => ({
authenticatedUser: {
userId: 1,
roles,
},
}}
>
<LoginRefresh>
<div>Hello!</div>
</LoginRefresh>
</AppContext.Provider>
); /* eslint-enable react/prop-types */
}), [roles]);
return (
<AppContext.Provider value={contextValue}>
<LoginRefresh>
<div>Hello!</div>
</LoginRefresh>
</AppContext.Provider>
);
}; /* eslint-enable react/prop-types */

describe('<LoginRefresh />', () => {
it('should call loginRefresh if the user has no roles', async () => {
Expand Down
12 changes: 8 additions & 4 deletions src/components/course/CourseAssociatedPrograms.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { CourseContext } from './CourseContextProvider';
import { getProgramIcon, formatProgramType } from './data/utils';
import { features } from '../../config';

export default function CourseAssociatedPrograms() {
const CourseAssociatedPrograms = () => {
const { state } = useContext(CourseContext);
const { course } = state;
const { enterpriseConfig } = useContext(AppContext);
Expand Down Expand Up @@ -37,12 +37,14 @@ export default function CourseAssociatedPrograms() {
: program.marketingUrl}
target="_blank"
onClick={() => {
sendEnterpriseTrackEvent(enterpriseConfig.uuid,
sendEnterpriseTrackEvent(
enterpriseConfig.uuid,
'edx.ui.enterprise.learner_portal.course.sidebar.program.clicked',
{
program_title: program.title,
program_type: program.type,
});
},
);
}}
>
{program.title}
Expand All @@ -53,4 +55,6 @@ export default function CourseAssociatedPrograms() {
</ul>
</div>
);
}
};

export default CourseAssociatedPrograms;
4 changes: 2 additions & 2 deletions src/components/course/CourseContextProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const reducer = (state, action) => {
}
};

export function CourseContextProvider({ children, initialState }) {
export const CourseContextProvider = ({ children, initialState }) => {
const { catalogsForSubsidyRequests } = useContext(SubsidyRequestsContext);
const [state, dispatch] = useReducer(reducer, initialState);
const { catalog } = state;
Expand All @@ -42,7 +42,7 @@ export function CourseContextProvider({ children, initialState }) {
{children}
</CourseContext.Provider>
);
}
};

CourseContextProvider.propTypes = {
children: PropTypes.node.isRequired,
Expand Down
14 changes: 8 additions & 6 deletions src/components/course/CourseEnrollmentFailedAlert.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ const CourseEnrollmentFailedAlert = ({ className, enrollmentSource }) => {
[courseEnrollmentsByStatus, courseRunKey],
);

const failureReasonMessages = useMemo(() => {
const contactHelpText = renderContactHelpText(Alert.Link);
return isUpgradeAttempt ? createUpgradeFailureMessages(contactHelpText, enrollmentSource)
: createEnrollmentFailureMessages(contactHelpText);
},
[enrollmentSource, isUpgradeAttempt, renderContactHelpText]);
const failureReasonMessages = useMemo(
() => {
const contactHelpText = renderContactHelpText(Alert.Link);
return isUpgradeAttempt ? createUpgradeFailureMessages(contactHelpText, enrollmentSource)
: createEnrollmentFailureMessages(contactHelpText);
},
[enrollmentSource, isUpgradeAttempt, renderContactHelpText],
);

if (!hasEnrollmentFailed) {
return null;
Expand Down
6 changes: 4 additions & 2 deletions src/components/course/CourseHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
import LicenseRequestedAlert from './LicenseRequestedAlert';
import SubsidyRequestButton from './SubsidyRequestButton';

export default function CourseHeader() {
const CourseHeader = () => {
const { enterpriseConfig } = useContext(AppContext);
const { state } = useContext(CourseContext);
const { course, catalog } = state;
Expand Down Expand Up @@ -111,4 +111,6 @@ export default function CourseHeader() {
</Container>
</div>
);
}
};

export default CourseHeader;
6 changes: 4 additions & 2 deletions src/components/course/CourseMainContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function formatSponsorTextList(sponsors) {
return sponsorTextList;
}

export default function CourseMainContent() {
const CourseMainContent = () => {
const { config } = useContext(AppContext);
const { state } = useContext(CourseContext);
const { course, activeCourseRun } = state;
Expand Down Expand Up @@ -156,4 +156,6 @@ export default function CourseMainContent() {
)}
</>
);
}
};

export default CourseMainContent;
6 changes: 4 additions & 2 deletions src/components/course/CoursePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { UserSubsidyContext } from '../enterprise-user-subsidy/UserSubsidy';
import { SubsidyRequestsContext } from '../enterprise-subsidy-requests';
import { useSearchCatalogs } from '../search/data/hooks';

export default function CoursePage() {
const CoursePage = () => {
const { courseKey } = useParams();
const { enterpriseConfig } = useContext(AppContext);
const { search } = useLocation();
Expand Down Expand Up @@ -154,4 +154,6 @@ export default function CoursePage() {
</CourseEnrollmentsContextProvider>
</>
);
}
};

export default CoursePage;
Loading