Compare commits
1 Commits
master
...
saad/INF-7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f3226c729b |
@@ -28,6 +28,7 @@ const discussionPostId = 'thread-1';
|
|||||||
const questionPostId = 'thread-2';
|
const questionPostId = 'thread-2';
|
||||||
const courseId = 'course-v1:edX+TestX+Test_Course';
|
const courseId = 'course-v1:edX+TestX+Test_Course';
|
||||||
const reverseOrder = false;
|
const reverseOrder = false;
|
||||||
|
const enableInContextSidebar = false;
|
||||||
let store;
|
let store;
|
||||||
let axiosMock;
|
let axiosMock;
|
||||||
let container;
|
let container;
|
||||||
@@ -45,6 +46,7 @@ function mockAxiosReturnPagedComments() {
|
|||||||
requested_fields: 'profile_image',
|
requested_fields: 'profile_image',
|
||||||
endorsed,
|
endorsed,
|
||||||
reverse_order: reverseOrder,
|
reverse_order: reverseOrder,
|
||||||
|
enable_in_context_sidebar: enableInContextSidebar,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.reply(200, Factory.build('commentsResult', { can_delete: true }, {
|
.reply(200, Factory.build('commentsResult', { can_delete: true }, {
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ const closedPostId = 'thread-2';
|
|||||||
const courseId = 'course-v1:edX+TestX+Test_Course';
|
const courseId = 'course-v1:edX+TestX+Test_Course';
|
||||||
const topicsApiUrl = `${getApiBaseUrl()}/api/discussion/v1/course_topics/${courseId}`;
|
const topicsApiUrl = `${getApiBaseUrl()}/api/discussion/v1/course_topics/${courseId}`;
|
||||||
const reverseOrder = false;
|
const reverseOrder = false;
|
||||||
|
const enableInContextSidebar = false;
|
||||||
let store;
|
let store;
|
||||||
let axiosMock;
|
let axiosMock;
|
||||||
let testLocation;
|
let testLocation;
|
||||||
@@ -52,6 +53,7 @@ function mockAxiosReturnPagedComments() {
|
|||||||
requested_fields: 'profile_image',
|
requested_fields: 'profile_image',
|
||||||
endorsed,
|
endorsed,
|
||||||
reverse_order: reverseOrder,
|
reverse_order: reverseOrder,
|
||||||
|
enable_in_context_sidebar: enableInContextSidebar,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.reply(200, Factory.build('commentsResult', { can_delete: true }, {
|
.reply(200, Factory.build('commentsResult', { can_delete: true }, {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { TinyMCEEditor } from '../../../../components';
|
|||||||
import FormikErrorFeedback from '../../../../components/FormikErrorFeedback';
|
import FormikErrorFeedback from '../../../../components/FormikErrorFeedback';
|
||||||
import PostPreviewPane from '../../../../components/PostPreviewPane';
|
import PostPreviewPane from '../../../../components/PostPreviewPane';
|
||||||
import { useDispatchWithState } from '../../../../data/hooks';
|
import { useDispatchWithState } from '../../../../data/hooks';
|
||||||
|
import { DiscussionContext } from '../../../common/context';
|
||||||
import {
|
import {
|
||||||
selectModerationSettings,
|
selectModerationSettings,
|
||||||
selectUserHasModerationPrivileges,
|
selectUserHasModerationPrivileges,
|
||||||
@@ -32,6 +33,7 @@ function CommentEditor({
|
|||||||
}) {
|
}) {
|
||||||
const editorRef = useRef(null);
|
const editorRef = useRef(null);
|
||||||
const { authenticatedUser } = useContext(AppContext);
|
const { authenticatedUser } = useContext(AppContext);
|
||||||
|
const { enableInContextSidebar } = useContext(DiscussionContext);
|
||||||
const userHasModerationPrivileges = useSelector(selectUserHasModerationPrivileges);
|
const userHasModerationPrivileges = useSelector(selectUserHasModerationPrivileges);
|
||||||
const userIsGroupTa = useSelector(selectUserIsGroupTa);
|
const userIsGroupTa = useSelector(selectUserIsGroupTa);
|
||||||
const userIsStaff = useSelector(selectUserIsStaff);
|
const userIsStaff = useSelector(selectUserIsStaff);
|
||||||
@@ -71,7 +73,7 @@ function CommentEditor({
|
|||||||
};
|
};
|
||||||
await dispatch(editComment(comment.id, payload));
|
await dispatch(editComment(comment.id, payload));
|
||||||
} else {
|
} else {
|
||||||
await dispatch(addComment(values.comment, comment.threadId, comment.parentId));
|
await dispatch(addComment(values.comment, comment.threadId, comment.parentId, enableInContextSidebar));
|
||||||
}
|
}
|
||||||
/* istanbul ignore if: TinyMCE is mocked so this cannot be easily tested */
|
/* istanbul ignore if: TinyMCE is mocked so this cannot be easily tested */
|
||||||
if (editorRef.current) {
|
if (editorRef.current) {
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ export const getCommentsApiUrl = () => `${getConfig().LMS_BASE_URL}/api/discussi
|
|||||||
* @param {EndorsementStatus} endorsed
|
* @param {EndorsementStatus} endorsed
|
||||||
* @param {number=} page
|
* @param {number=} page
|
||||||
* @param {number=} pageSize
|
* @param {number=} pageSize
|
||||||
|
* @param reverseOrder
|
||||||
|
* @param enableInContextSidebar
|
||||||
* @returns {Promise<{}>}
|
* @returns {Promise<{}>}
|
||||||
*/
|
*/
|
||||||
export async function getThreadComments(
|
export async function getThreadComments(
|
||||||
@@ -24,6 +26,7 @@ export async function getThreadComments(
|
|||||||
page,
|
page,
|
||||||
pageSize,
|
pageSize,
|
||||||
reverseOrder,
|
reverseOrder,
|
||||||
|
enableInContextSidebar = false,
|
||||||
} = {},
|
} = {},
|
||||||
) {
|
) {
|
||||||
const params = snakeCaseObject({
|
const params = snakeCaseObject({
|
||||||
@@ -33,6 +36,7 @@ export async function getThreadComments(
|
|||||||
pageSize,
|
pageSize,
|
||||||
reverseOrder,
|
reverseOrder,
|
||||||
requestedFields: 'profile_image',
|
requestedFields: 'profile_image',
|
||||||
|
enableInContextSidebar,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { data } = await getAuthenticatedHttpClient()
|
const { data } = await getAuthenticatedHttpClient()
|
||||||
@@ -69,11 +73,14 @@ export async function getCommentResponses(
|
|||||||
* @param {string} comment Raw comment data to post.
|
* @param {string} comment Raw comment data to post.
|
||||||
* @param {string} threadId Thread ID for thread in which to post comment.
|
* @param {string} threadId Thread ID for thread in which to post comment.
|
||||||
* @param {string=} parentId ID for a comments parent.
|
* @param {string=} parentId ID for a comments parent.
|
||||||
|
* @param {boolean} enableInContextSidebar
|
||||||
* @returns {Promise<{}>}
|
* @returns {Promise<{}>}
|
||||||
*/
|
*/
|
||||||
export async function postComment(comment, threadId, parentId = null) {
|
export async function postComment(comment, threadId, parentId = null, enableInContextSidebar = false) {
|
||||||
const { data } = await getAuthenticatedHttpClient()
|
const { data } = await getAuthenticatedHttpClient()
|
||||||
.post(getCommentsApiUrl(), snakeCaseObject({ threadId, raw_body: comment, parentId }));
|
.post(getCommentsApiUrl(), snakeCaseObject({
|
||||||
|
threadId, raw_body: comment, parentId, enableInContextSidebar,
|
||||||
|
}));
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect } from 'react';
|
import { useContext, useEffect } from 'react';
|
||||||
|
|
||||||
import { useDispatch, useSelector } from 'react-redux';
|
import { useDispatch, useSelector } from 'react-redux';
|
||||||
|
|
||||||
@@ -6,6 +6,7 @@ import { sendTrackEvent } from '@edx/frontend-platform/analytics';
|
|||||||
|
|
||||||
import { EndorsementStatus } from '../../../data/constants';
|
import { EndorsementStatus } from '../../../data/constants';
|
||||||
import { useDispatchWithState } from '../../../data/hooks';
|
import { useDispatchWithState } from '../../../data/hooks';
|
||||||
|
import { DiscussionContext } from '../../common/context';
|
||||||
import { selectThread } from '../../posts/data/selectors';
|
import { selectThread } from '../../posts/data/selectors';
|
||||||
import { markThreadAsRead } from '../../posts/data/thunks';
|
import { markThreadAsRead } from '../../posts/data/thunks';
|
||||||
import {
|
import {
|
||||||
@@ -42,6 +43,7 @@ export function usePostComments(postId, endorsed = null) {
|
|||||||
const reverseOrder = useSelector(selectCommentSortOrder);
|
const reverseOrder = useSelector(selectCommentSortOrder);
|
||||||
const hasMorePages = useSelector(selectThreadHasMorePages(postId, endorsed));
|
const hasMorePages = useSelector(selectThreadHasMorePages(postId, endorsed));
|
||||||
const currentPage = useSelector(selectThreadCurrentPage(postId, endorsed));
|
const currentPage = useSelector(selectThreadCurrentPage(postId, endorsed));
|
||||||
|
const { enableInContextSidebar } = useContext(DiscussionContext);
|
||||||
|
|
||||||
const handleLoadMoreResponses = async () => {
|
const handleLoadMoreResponses = async () => {
|
||||||
const params = {
|
const params = {
|
||||||
@@ -58,6 +60,7 @@ export function usePostComments(postId, endorsed = null) {
|
|||||||
endorsed,
|
endorsed,
|
||||||
page: 1,
|
page: 1,
|
||||||
reverseOrder,
|
reverseOrder,
|
||||||
|
enableInContextSidebar,
|
||||||
}));
|
}));
|
||||||
}, [postId, reverseOrder]);
|
}, [postId, reverseOrder]);
|
||||||
|
|
||||||
|
|||||||
@@ -80,12 +80,15 @@ export function fetchThreadComments(
|
|||||||
page = 1,
|
page = 1,
|
||||||
reverseOrder,
|
reverseOrder,
|
||||||
endorsed = EndorsementStatus.DISCUSSION,
|
endorsed = EndorsementStatus.DISCUSSION,
|
||||||
|
enableInContextSidebar,
|
||||||
} = {},
|
} = {},
|
||||||
) {
|
) {
|
||||||
return async (dispatch) => {
|
return async (dispatch) => {
|
||||||
try {
|
try {
|
||||||
dispatch(fetchCommentsRequest());
|
dispatch(fetchCommentsRequest());
|
||||||
const data = await getThreadComments(threadId, { page, reverseOrder, endorsed });
|
const data = await getThreadComments(threadId, {
|
||||||
|
page, reverseOrder, endorsed, enableInContextSidebar,
|
||||||
|
});
|
||||||
dispatch(fetchCommentsSuccess({
|
dispatch(fetchCommentsSuccess({
|
||||||
...normaliseComments(camelCaseObject(data)),
|
...normaliseComments(camelCaseObject(data)),
|
||||||
endorsed,
|
endorsed,
|
||||||
@@ -144,7 +147,7 @@ export function editComment(commentId, comment, action = null) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addComment(comment, threadId, parentId = null) {
|
export function addComment(comment, threadId, parentId = null, enableInContextSidebar = false) {
|
||||||
return async (dispatch) => {
|
return async (dispatch) => {
|
||||||
try {
|
try {
|
||||||
dispatch(postCommentRequest({
|
dispatch(postCommentRequest({
|
||||||
@@ -152,7 +155,7 @@ export function addComment(comment, threadId, parentId = null) {
|
|||||||
threadId,
|
threadId,
|
||||||
parentId,
|
parentId,
|
||||||
}));
|
}));
|
||||||
const data = await postComment(comment, threadId, parentId);
|
const data = await postComment(comment, threadId, parentId, enableInContextSidebar);
|
||||||
dispatch(postCommentSuccess(camelCaseObject(data)));
|
dispatch(postCommentSuccess(camelCaseObject(data)));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (getHttpErrorStatus(error) === 403) {
|
if (getHttpErrorStatus(error) === 403) {
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ export async function getThread(threadId, courseId) {
|
|||||||
* @param {boolean} following Follow the thread after creating
|
* @param {boolean} following Follow the thread after creating
|
||||||
* @param {boolean} anonymous Should the thread be anonymous to all users
|
* @param {boolean} anonymous Should the thread be anonymous to all users
|
||||||
* @param {boolean} anonymousToPeers Should the thread be anonymous to peers
|
* @param {boolean} anonymousToPeers Should the thread be anonymous to peers
|
||||||
|
* @param {boolean} enableInContextSidebar
|
||||||
* @returns {Promise<{}>}
|
* @returns {Promise<{}>}
|
||||||
*/
|
*/
|
||||||
export async function postThread(
|
export async function postThread(
|
||||||
@@ -101,6 +102,7 @@ export async function postThread(
|
|||||||
anonymous,
|
anonymous,
|
||||||
anonymousToPeers,
|
anonymousToPeers,
|
||||||
} = {},
|
} = {},
|
||||||
|
enableInContextSidebar = false,
|
||||||
) {
|
) {
|
||||||
const postData = snakeCaseObject({
|
const postData = snakeCaseObject({
|
||||||
courseId,
|
courseId,
|
||||||
@@ -112,8 +114,8 @@ export async function postThread(
|
|||||||
anonymous,
|
anonymous,
|
||||||
anonymousToPeers,
|
anonymousToPeers,
|
||||||
groupId: cohort,
|
groupId: cohort,
|
||||||
|
enableInContextSidebar,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { data } = await getAuthenticatedHttpClient()
|
const { data } = await getAuthenticatedHttpClient()
|
||||||
.post(getThreadsApiUrl(), postData);
|
.post(getThreadsApiUrl(), postData);
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
@@ -204,6 +204,7 @@ export function createNewThread({
|
|||||||
anonymous,
|
anonymous,
|
||||||
anonymousToPeers,
|
anonymousToPeers,
|
||||||
cohort,
|
cohort,
|
||||||
|
enableInContextSidebar,
|
||||||
}) {
|
}) {
|
||||||
return async (dispatch) => {
|
return async (dispatch) => {
|
||||||
try {
|
try {
|
||||||
@@ -223,7 +224,7 @@ export function createNewThread({
|
|||||||
following,
|
following,
|
||||||
anonymous,
|
anonymous,
|
||||||
anonymousToPeers,
|
anonymousToPeers,
|
||||||
});
|
}, enableInContextSidebar);
|
||||||
dispatch(postThreadSuccess(camelCaseObject(data)));
|
dispatch(postThreadSuccess(camelCaseObject(data)));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (getHttpErrorStatus(error) === 403) {
|
if (getHttpErrorStatus(error) === 403) {
|
||||||
|
|||||||
@@ -187,6 +187,7 @@ function PostEditor({
|
|||||||
anonymous: allowAnonymous ? values.anonymous : undefined,
|
anonymous: allowAnonymous ? values.anonymous : undefined,
|
||||||
anonymousToPeers: allowAnonymousToPeers ? values.anonymousToPeers : undefined,
|
anonymousToPeers: allowAnonymousToPeers ? values.anonymousToPeers : undefined,
|
||||||
cohort,
|
cohort,
|
||||||
|
enableInContextSidebar,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
/* istanbul ignore if: TinyMCE is mocked so this cannot be easily tested */
|
/* istanbul ignore if: TinyMCE is mocked so this cannot be easily tested */
|
||||||
|
|||||||
Reference in New Issue
Block a user