Skip to content

Commit

Permalink
build: edx namespace packages upgrade & resolved respective eslint is…
Browse files Browse the repository at this point in the history
…sue (openedx#508)

* refactor: updated frontend-build, frontend-platform, header & footer packages

* fix: resolved eslint issues post frontend-build upgrade

* refactor: resolved eslint issues

* refactor: pinned frontend-build & changed suggested function definitions
  • Loading branch information
BilalQamar95 authored and snglth committed Jan 9, 2024
1 parent 566deb5 commit 0230354
Show file tree
Hide file tree
Showing 16 changed files with 544 additions and 83 deletions.
502 changes: 474 additions & 28 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/discussions/common/EndorsedAlertBanner.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function renderComponent(content, postType) {
</AppProvider>
</IntlProvider>,
);
}
};

describe.each([
{
Expand Down
1 change: 1 addition & 0 deletions src/discussions/common/HoverCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ HoverCard.propTypes = {
addResponseCommentButtonMessage: PropTypes.string.isRequired,
onLike: PropTypes.func.isRequired,
voted: PropTypes.bool.isRequired,
// eslint-disable-next-line react/forbid-prop-types
endorseIcons: PropTypes.objectOf(PropTypes.any),
onFollow: PropTypes.func,
following: PropTypes.bool,
Expand Down
6 changes: 4 additions & 2 deletions src/discussions/common/HoverCard.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ async function mockAxiosReturnPagedCommentsResponses() {
};

[1, 2].forEach(async (page) => {
axiosMock.onGet(commentsResponsesApiUrl, { params: { ...paramsTemplate, page } }).reply(200,
axiosMock.onGet(commentsResponsesApiUrl, { params: { ...paramsTemplate, page } }).reply(
200,
Factory.build('commentsResult', null, {
parentId,
page,
pageSize: 1,
count: 2,
}));
}),
);

await executeThunk(fetchCommentResponses(parentId), store.dispatch, store.getState);
});
Expand Down
14 changes: 8 additions & 6 deletions src/discussions/data/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ import { fetchCourseConfig } from './thunks';

export function useTotalTopicThreadCount() {
const topics = useSelector(selectTopics);
const count = useMemo(() => (
Object.keys(topics)?.reduce((total, topicId) => {
const topic = topics[topicId];
return total + topic.threadCounts.discussion + topic.threadCounts.question;
}, 0)),
[]);
const count = useMemo(
() => (
Object.keys(topics)?.reduce((total, topicId) => {
const topic = topics[topicId];
return total + topic.threadCounts.discussion + topic.threadCounts.question;
}, 0)),
[],
);

return count;
}
Expand Down
1 change: 1 addition & 0 deletions src/discussions/discussions-home/DiscussionsHome.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable react/jsx-no-constructed-context-values */
import React, { lazy, Suspense, useRef } from 'react';

import classNames from 'classnames';
Expand Down
1 change: 1 addition & 0 deletions src/discussions/learners/LearnersView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const LearnersView = ({ intl }) => {
courseConfigLoadingStatus === RequestStatus.SUCCESSFUL && learnersTabEnabled && learners.map((learner) => (
<LearnerCard learner={learner} key={learner.username} />
))
// eslint-disable-next-line react/jsx-no-useless-fragment
) || <></>
), [courseConfigLoadingStatus, learnersTabEnabled, learners]);

Expand Down
1 change: 1 addition & 0 deletions src/discussions/post-comments/PostCommentsView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const PostCommentsView = ({ intl }) => {
}

return (
// eslint-disable-next-line react/jsx-no-constructed-context-values
<PostCommentsContext.Provider value={{
isClosed: closed,
postType: type,
Expand Down
6 changes: 4 additions & 2 deletions src/discussions/post-comments/PostCommentsView.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,15 @@ async function mockAxiosReturnPagedCommentsResponses() {
};

[1, 2].forEach(async (page) => {
axiosMock.onGet(commentsResponsesApiUrl, { params: { ...paramsTemplate, page } }).reply(200,
axiosMock.onGet(commentsResponsesApiUrl, { params: { ...paramsTemplate, page } }).reply(
200,
Factory.build('commentsResult', null, {
parentId,
page,
pageSize: 1,
count: 2,
}));
}),
);

await executeThunk(fetchCommentResponses(parentId), store.dispatch, store.getState);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ CommentEditor.propTypes = {
comment: PropTypes.shape({
author: PropTypes.string,
id: PropTypes.string,
lastEdit: PropTypes.object,
lastEdit: PropTypes.shape({}),
parentId: PropTypes.string,
rawBody: PropTypes.string,
author: PropTypes.string,
Expand Down
18 changes: 9 additions & 9 deletions src/discussions/post-comments/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function getThreadComments(threadId, {

const { data } = await getAuthenticatedHttpClient().get(getCommentsApiUrl(), { params: { ...params, signal } });
return data;
}
};

/**
* Fetches a responses to a comment.
Expand All @@ -63,7 +63,7 @@ export async function getCommentResponses(commentId, {
const { data } = await getAuthenticatedHttpClient()
.get(url, { params });
return data;
}
};

/**
* Posts a comment.
Expand All @@ -73,13 +73,13 @@ export async function getCommentResponses(commentId, {
* @param {boolean} enableInContextSidebar
* @returns {Promise<{}>}
*/
export async function postComment(comment, threadId, parentId = null, enableInContextSidebar = false) {
export const postComment = async (comment, threadId, parentId = null, enableInContextSidebar = false) => {
const { data } = await getAuthenticatedHttpClient()
.post(getCommentsApiUrl(), snakeCaseObject({
threadId, raw_body: comment, parentId, enableInContextSidebar,
}));
return data;
}
};

/**
* Updates existing comment.
Expand All @@ -91,13 +91,13 @@ export async function postComment(comment, threadId, parentId = null, enableInCo
* @param {string=} editReasonCode The moderation reason code for editing.
* @returns {Promise<{}>}
*/
export async function updateComment(commentId, {
export const updateComment = async (commentId, {
comment,
voted,
flagged,
endorsed,
editReasonCode,
}) {
}) => {
const url = `${getCommentsApiUrl()}${commentId}/`;
const postData = snakeCaseObject({
raw_body: comment,
Expand All @@ -110,14 +110,14 @@ export async function updateComment(commentId, {
const { data } = await getAuthenticatedHttpClient()
.patch(url, postData, { headers: { 'Content-Type': 'application/merge-patch+json' } });
return data;
}
};

/**
* Deletes existing comment.
* @param {string} commentId ID of comment to delete
*/
export async function deleteComment(commentId) {
export const deleteComment = async (commentId) => {
const url = `${getCommentsApiUrl()}${commentId}/`;
await getAuthenticatedHttpClient()
.delete(url);
}
};
26 changes: 13 additions & 13 deletions src/discussions/posts/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ export async function getThreads(courseId, {
});
const { data } = await getAuthenticatedHttpClient().get(getThreadsApiUrl(), { params });
return data;
}
};

/**
* Fetches a single thread.
* @param {string} threadId
* @returns {Promise<{}>}
*/
export async function getThread(threadId, courseId) {
export const getThread = async (threadId, courseId) => {
const params = { requested_fields: 'profile_image', course_id: courseId };
const url = `${getThreadsApiUrl()}${threadId}/`;
const { data } = await getAuthenticatedHttpClient().get(url, { params });
return data;
}
};

/**
* Posts a new thread.
Expand All @@ -88,7 +88,7 @@ export async function getThread(threadId, courseId) {
* @param {boolean} enableInContextSidebar
* @returns {Promise<{}>}
*/
export async function postThread(
export const postThread = async (
courseId,
topicId,
type,
Expand All @@ -101,7 +101,7 @@ export async function postThread(
anonymousToPeers,
} = {},
enableInContextSidebar = false,
) {
) => {
const postData = snakeCaseObject({
courseId,
topicId,
Expand All @@ -117,7 +117,7 @@ export async function postThread(
const { data } = await getAuthenticatedHttpClient()
.post(getThreadsApiUrl(), postData);
return data;
}
};

/**
* Updates an existing thread.
Expand All @@ -136,7 +136,7 @@ export async function postThread(
* @param {string} closeReasonCode
* @returns {Promise<{}>}
*/
export async function updateThread(threadId, {
export const updateThread = async (threadId, {
flagged,
voted,
read,
Expand All @@ -149,7 +149,7 @@ export async function updateThread(threadId, {
pinned,
editReasonCode,
closeReasonCode,
} = {}) {
} = {}) => {
const url = `${getThreadsApiUrl()}${threadId}/`;
const patchData = snakeCaseObject({
topicId,
Expand All @@ -168,17 +168,17 @@ export async function updateThread(threadId, {
const { data } = await getAuthenticatedHttpClient()
.patch(url, patchData, { headers: { 'Content-Type': 'application/merge-patch+json' } });
return data;
}
};

/**
* Deletes a thread.
* @param {string} threadId
*/
export async function deleteThread(threadId) {
export const deleteThread = async (threadId) => {
const url = `${getThreadsApiUrl()}${threadId}/`;
await getAuthenticatedHttpClient()
.delete(url);
}
};

/**
* Upload a file.
Expand All @@ -188,7 +188,7 @@ export async function deleteThread(threadId) {
* @param {string} threadKey
* @returns {Promise<{ location: string }>}
*/
export async function uploadFile(blob, filename, courseId, threadKey) {
export const uploadFile = async (blob, filename, courseId, threadKey) => {
const uploadUrl = `${getCoursesApiUrl()}${courseId}/upload`;
const formData = new FormData();
formData.append('thread_key', threadKey);
Expand All @@ -198,4 +198,4 @@ export async function uploadFile(blob, filename, courseId, threadKey) {
throw new Error(data.developer_message);
}
return data;
}
};
32 changes: 17 additions & 15 deletions src/discussions/posts/post-editor/PostEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,11 @@ const PostEditor = ({
}, [postId, topicId, post?.author, category, editExisting, commentsPagePath, location]);

// null stands for no cohort restriction ("All learners" option)
const selectedCohort = useCallback((cohort) => (
cohort === 'default' ? null : cohort),
[]);
const selectedCohort = useCallback(
(cohort) => (
cohort === 'default' ? null : cohort),
[],
);

const submitForm = useCallback(async (values, { resetForm }) => {
if (editExisting) {
Expand Down Expand Up @@ -323,18 +325,18 @@ const PostEditor = ({
{enableInContext ? (
<>
{coursewareTopics?.map(section => (
section?.children?.map(subsection => (
<optgroup
label={handleInContextSelectLabel(section, subsection)}
key={subsection.id}
>
{subsection?.children?.map(unit => (
<option key={unit.id} value={unit.id}>
{unit.name || intl.formatMessage(messages.unnamedSubTopics)}
</option>
))}
</optgroup>
))
section?.children?.map(subsection => (
<optgroup
label={handleInContextSelectLabel(section, subsection)}
key={subsection.id}
>
{subsection?.children?.map(unit => (
<option key={unit.id} value={unit.id}>
{unit.name || intl.formatMessage(messages.unnamedSubTopics)}
</option>
))}
</optgroup>
))
))}
{(userIsStaff || userIsGroupTa || userHasModerationPrivileges) && (
<optgroup label={intl.formatMessage(messages.archivedTopics)}>
Expand Down
6 changes: 3 additions & 3 deletions src/discussions/posts/post/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ const Post = ({
`${window.location.origin}/${courseId}/posts/${postId}`,
), [window.location.origin, postId, courseId]);

const handlePostPin = useCallback(() => dispatch(updateExistingThread(
postId, { pinned: !pinned },
)), [postId, pinned]);
const handlePostPin = useCallback(() => dispatch(
updateExistingThread(postId, { pinned: !pinned }),
), [postId, pinned]);

const handlePostReport = useCallback(() => {
if (abuseFlagged) {
Expand Down
8 changes: 5 additions & 3 deletions src/discussions/posts/post/PostLink.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ const PostLink = ({
const canSeeReportedBadge = abuseFlagged || abuseFlaggedCount;
const isPostRead = read || (!read && commentCount !== unreadCommentCount);

const checkIsSelected = useMemo(() => (
window.location.pathname.includes(postId)),
[window.location.pathname]);
const checkIsSelected = useMemo(
() => (
window.location.pathname.includes(postId)),
[window.location.pathname],
);

return (
<Link
Expand Down
1 change: 1 addition & 0 deletions src/discussions/topics/topic-group/TopicGroupBase.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const TopicGroupBase = ({

const renderFilteredTopics = useMemo(() => {
if (!hasFilteredSubtopics) {
// eslint-disable-next-line react/jsx-no-useless-fragment
return <></>;
}

Expand Down

0 comments on commit 0230354

Please sign in to comment.