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 12 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
12,242 changes: 5,284 additions & 6,958 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 @@ -55,7 +55,7 @@
"universal-cookie": "4.0.4"
},
"devDependencies": {
"@edx/frontend-build": "11.0.2",
"@edx/frontend-build": "^12.0.3",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let's keep the version pinned like our other dependencies are.

"@testing-library/jest-dom": "5.11.9",
"@testing-library/react": "11.2.7",
"@testing-library/react-hooks": "3.7.0",
Expand Down
4 changes: 2 additions & 2 deletions src/components/NotFoundPage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Helmet } from 'react-helmet';
import { AppContext } from '@edx/frontend-platform/react';
import { Container } from '@edx/paragon';

const NotFoundPage = ({ pageTitle, errorHeading, errorMessage }) => {
function NotFoundPage({ pageTitle, errorHeading, errorMessage }) {
const { enterpriseConfig } = useContext(AppContext);

let PAGE_TITLE = pageTitle;
Expand All @@ -22,7 +22,7 @@ const NotFoundPage = ({ pageTitle, errorHeading, errorMessage }) => {
</div>
</Container>
);
};
}

NotFoundPage.defaultProps = {
pageTitle: 'Page not found',
Expand Down
11 changes: 5 additions & 6 deletions src/components/TagCloud/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import PropTypes from 'prop-types';

import './styles/TagCloud.scss';

const TagCloud = ({ tags, onRemove }) => (
<>
function TagCloud({ tags, onRemove }) {
return (
<div className="skills-tag">
<ul className="item">
{
Expand All @@ -19,16 +19,15 @@ const TagCloud = ({ tags, onRemove }) => (
}
</ul>
</div>

</>
);
);
}

TagCloud.propTypes = {
onRemove: PropTypes.func.isRequired,
tags: PropTypes.arrayOf(
PropTypes.shape({
title: PropTypes.string.isRequired,
metadata: PropTypes.object.isRequired,
metadata: PropTypes.shape({}).isRequired,
}),
).isRequired,
};
Expand Down
17 changes: 11 additions & 6 deletions src/components/Toasts/ToastsProvider.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React, { createContext, useState } from 'react';
import React, {
createContext, useCallback, useState, useMemo,
} from 'react';
import PropTypes from 'prop-types';

export const ToastsContext = createContext();

const ToastsProvider = ({ children }) => {
function ToastsProvider({ children }) {
const [toasts, setToasts] = useState([]);

const addToast = (message) => {
Expand All @@ -16,21 +18,24 @@ 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]);

return (
<ToastsContext.Provider value={{ toasts, addToast, removeToast }}>
<ToastsContext.Provider value={
useMemo(() => ({ toasts, addToast, removeToast }), [removeToast, toasts])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useMemo shouldn't be called inline like this. Let's move it up above and store its output as a new variable contextValue instead.

}
>
{children}
</ToastsContext.Provider>
);
};
}

ToastsProvider.propTypes = {
children: PropTypes.node.isRequired,
Expand Down
1 change: 1 addition & 0 deletions src/components/app/LoginRefresh.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Container } from '@edx/paragon';
import { LoadingSpinner } from '../loading-spinner';
import { loginRefresh } from '../../utils/common';

// eslint-disable-next-line react/prop-types
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[curious] Why are we disabling this ESLint rule here versus defining the prop type for children?

export default function LoginRefresh({ children }) {
const { authenticatedUser } = useContext(AppContext);
const { roles } = authenticatedUser;
Expand Down
32 changes: 18 additions & 14 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,23 @@ import * as utils from '../../utils/common';
jest.mock('../../utils/common');

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call useMemo above the return statement within the component to create a new variable contextValue instead.

authenticatedUser: {
userId: 1,
roles,
},
}), [roles])
}
>
<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
6 changes: 3 additions & 3 deletions src/components/contact-admin-mailto/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { AppContext } from '@edx/frontend-platform/react';
import { MailtoLink } from '@edx/paragon';
import PropTypes from 'prop-types';

const ContactAdminMailto = ({
function ContactAdminMailto({
children,
}) => {
}) {
const { enterpriseConfig: { adminUsers } } = useContext(AppContext);
const adminEmails = adminUsers.map(user => user.email);

Expand All @@ -21,7 +21,7 @@ const ContactAdminMailto = ({
}

return children;
};
}

ContactAdminMailto.propTypes = {
children: PropTypes.node,
Expand Down
6 changes: 4 additions & 2 deletions src/components/course/CourseAssociatedPrograms.jsx
Original file line number Diff line number Diff line change
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 Down
18 changes: 10 additions & 8 deletions src/components/course/CourseEnrollmentFailedAlert.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const createUpgradeFailureMessages = (contactHelpText, enrollmentSource) => ({
* reasons. The contents of the alert are determined by a ``failureReason`` which is passed
* from the Data Sharing Consent (DSC) page as a query parameter.
*/
const CourseEnrollmentFailedAlert = ({ className, enrollmentSource }) => {
function CourseEnrollmentFailedAlert({ className, enrollmentSource }) {
const { search } = useLocation();
const { enterpriseConfig } = useContext(AppContext);
const renderContactHelpText = useRenderContactHelpText(enterpriseConfig);
Expand All @@ -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 All @@ -110,7 +112,7 @@ const CourseEnrollmentFailedAlert = ({ className, enrollmentSource }) => {
</Alert>
</Container>
);
};
}

CourseEnrollmentFailedAlert.defaultProps = {
className: 'mt-3',
Expand Down
4 changes: 2 additions & 2 deletions src/components/course/CourseRecommendationCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getPrimaryPartnerLogo, isDefinedAndNotNull } from '../../utils/common';
export const COURSE_REC_EVENT_NAME = 'edx.ui.enterprise.learner_portal.recommended.course.clicked';
export const SAME_PART_EVENT_NAME = 'edx.ui.enterprise.learner_portal.same.partner.recommended.course.clicked';

const CourseRecommendationCard = ({ course, isPartnerRecommendation }) => {
function CourseRecommendationCard({ course, isPartnerRecommendation }) {
const { enterpriseConfig: { slug, uuid } } = useContext(AppContext);
const eventName = isPartnerRecommendation ? SAME_PART_EVENT_NAME : COURSE_REC_EVENT_NAME;
const history = useHistory();
Expand Down Expand Up @@ -87,7 +87,7 @@ const CourseRecommendationCard = ({ course, isPartnerRecommendation }) => {
</Card.Footer>
</Card>
);
};
}

CourseRecommendationCard.propTypes = {
course: PropTypes.shape({
Expand Down
4 changes: 2 additions & 2 deletions src/components/course/CourseRecommendations.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CardGrid } from '@edx/paragon';
import { CourseContext } from './CourseContextProvider';
import CourseRecommendationCard from './CourseRecommendationCard';

const CourseRecommendations = () => {
function CourseRecommendations() {
const { state } = useContext(CourseContext);
const { course, courseRecommendations } = state;
const { allRecommendations, samePartnerRecommendations } = courseRecommendations;
Expand Down Expand Up @@ -36,6 +36,6 @@ const CourseRecommendations = () => {
)}
</div>
);
};
}

export default CourseRecommendations;
6 changes: 3 additions & 3 deletions src/components/course/CourseRunCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ import { SubsidyRequestsContext } from '../enterprise-subsidy-requests/SubsidyRe
const DATE_FORMAT = 'MMM D';
const DEFAULT_BUTTON_LABEL = 'Enroll';

const CourseRunCard = ({
function CourseRunCard({
userEntitlements,
courseRun,
userEnrollments,
courseKey,
subsidyRequestCatalogsApplicableToCourse,
}) => {
}) {
const {
availability,
pacingType,
Expand Down Expand Up @@ -224,7 +224,7 @@ const CourseRunCard = ({
</Card.Section>
</Card>
);
};
}

CourseRunCard.propTypes = {
courseKey: PropTypes.string.isRequired,
Expand Down
4 changes: 2 additions & 2 deletions src/components/course/CourseRunCards.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import { CourseContext } from './CourseContextProvider';
import CourseRunCard from './CourseRunCard';

const CourseRunCards = () => {
function CourseRunCards() {
const {
state: courseData,
subsidyRequestCatalogsApplicableToCourse,
Expand Down Expand Up @@ -35,6 +35,6 @@ const CourseRunCards = () => {
))}
</CardGrid>
);
};
}

export default CourseRunCards;
4 changes: 2 additions & 2 deletions src/components/course/CourseSidebarPrice.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const FREE_WHEN_APPROVED_MESSAGE = 'Free to me\n(when approved)';
export const COVERED_BY_ENTERPRISE_OFFER_MESSAGE = 'This course can be purchased with your organization\'s learner credit';
export const INSUFFICIENT_ENTERPRISE_OFFER_BALANCE = 'Your organization doesn\'t have enough learner credit remaining.';

const CourseSidebarPrice = () => {
function CourseSidebarPrice() {
const { enterpriseConfig } = useContext(AppContext);
const { state: courseData } = useContext(CourseContext);
const { activeCourseRun, userSubsidyApplicableToCourse } = courseData;
Expand Down Expand Up @@ -117,6 +117,6 @@ const CourseSidebarPrice = () => {
<small>{discountedPriceMessage}</small>
</>
);
};
}

export default CourseSidebarPrice;
7 changes: 4 additions & 3 deletions src/components/course/EnrollModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ export const MODAL_TEXTS = {
},
};

const EnrollModal = ({
function EnrollModal({
isModalOpen,
setIsModalOpen,
enrollmentUrl,
courseRunPrice,
userSubsidyApplicableToCourse,
couponCodesCount,
onEnroll,
}) => {
}) {
const [isLoading, setIsLoading] = useState(false);

const getModalTexts = () => {
Expand Down Expand Up @@ -93,6 +93,7 @@ const EnrollModal = ({
href={enrollmentUrl}
onClick={handleEnroll}
>
{ /* eslint-disable-next-line react/jsx-no-useless-fragment */ }
<>
{isLoading && <FontAwesomeIcon icon={faSpinner} alt="loading" className="fa-spin mr-2" />}
{buttonText}
Expand All @@ -102,7 +103,7 @@ const EnrollModal = ({
onClose={() => setIsModalOpen(false)}
/>
);
};
}

EnrollModal.propTypes = {
isModalOpen: PropTypes.bool.isRequired,
Expand Down
4 changes: 2 additions & 2 deletions src/components/course/LicenseRequestedAlert.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { UserSubsidyContext } from '../enterprise-user-subsidy/UserSubsidy';
* A component to render an alert when a learner has a license request that is pending review.
* Once dismissed, the learner will not see this alert again until the cookies are cleared.
*/
const LicenseRequestedAlert = ({ catalogList }) => {
function LicenseRequestedAlert({ catalogList }) {
const cookies = new Cookies();
const previouslyDismissed = cookies.get(LICENSE_REQUESTED_ALERT_DISMISSED_COOKIE_NAME);
const [isAlertOpen, setIsAlertOpen] = useState(!previouslyDismissed);
Expand Down Expand Up @@ -56,7 +56,7 @@ const LicenseRequestedAlert = ({ catalogList }) => {
</Alert>
</Container>
);
};
}

LicenseRequestedAlert.propTypes = {
catalogList: PropTypes.arrayOf(PropTypes.string).isRequired,
Expand Down
Loading