diff --git a/src/data/constants.js b/src/data/constants.js index a20783ed6..b91732076 100644 --- a/src/data/constants.js +++ b/src/data/constants.js @@ -144,7 +144,7 @@ export const Routes = { PATH: BASE_PATH, }, LEARNERS: { - PATH: `${BASE_PATH}/learners`, + PATH: `${BASE_PATH}/learners/:learnerUsername?`, POSTS: `${BASE_PATH}/learners/:learnerUsername/posts/:postId?`, POSTS_EDIT: `${BASE_PATH}/learners/:learnerUsername/posts/:postId/edit`, }, @@ -165,19 +165,19 @@ export const Routes = { }, COMMENTS: { PATH: [ - `${BASE_PATH}/category/:category/posts/:postId`, - `${BASE_PATH}/topics/:topicId/posts/:postId`, + `${BASE_PATH}/category/:category/posts/:postId?`, + `${BASE_PATH}/topics/:topicId/posts/:postId?`, `${BASE_PATH}/posts/:postId`, `${BASE_PATH}/my-posts/:postId`, - `${BASE_PATH}/learners/:learnerUsername/posts/:postId`, + `${BASE_PATH}/learners/:learnerUsername/posts/:postId?`, ], PAGE: `${BASE_PATH}/:page/*`, PAGES: { - category: `${BASE_PATH}/category/:category/posts/:postId`, - topics: `${BASE_PATH}/topics/:topicId/posts/:postId`, + category: `${BASE_PATH}/category/:category/posts/:postId?`, + topics: `${BASE_PATH}/topics/:topicId/posts/:postId?`, posts: `${BASE_PATH}/posts/:postId`, 'my-posts': `${BASE_PATH}/my-posts/:postId`, - learners: `${BASE_PATH}/learners/:learnerUsername/posts/:postId`, + learners: `${BASE_PATH}/learners/:learnerUsername/posts/:postId?`, }, }, TOPICS: { @@ -188,10 +188,10 @@ export const Routes = { ], ALL: `${BASE_PATH}/topics`, CATEGORY: `${BASE_PATH}/category/:category`, - CATEGORY_POST: `${BASE_PATH}/category/:category/posts/:postId`, + CATEGORY_POST: `${BASE_PATH}/category/:category/posts/:postId?`, CATEGORY_POST_EDIT: `${BASE_PATH}/category/:category/posts/:postId/edit`, TOPIC: `${BASE_PATH}/topics/:topicId`, - TOPIC_POST: `${BASE_PATH}/topics/:topicId/posts/:postId`, + TOPIC_POST: `${BASE_PATH}/topics/:topicId/posts/:postId?`, TOPIC_POST_EDIT: `${BASE_PATH}/topics/:topicId/posts/:postId/edit`, }, }; diff --git a/src/discussions/discussions-home/DiscussionSidebar.jsx b/src/discussions/discussions-home/DiscussionSidebar.jsx index 2ca687eca..f1ef4182a 100644 --- a/src/discussions/discussions-home/DiscussionSidebar.jsx +++ b/src/discussions/discussions-home/DiscussionSidebar.jsx @@ -90,6 +90,9 @@ const DiscussionSidebar = ({ displaySidebar, postActionBarRef }) => { ROUTES.TOPICS.CATEGORY, ROUTES.TOPICS.CATEGORY_POST, ROUTES.TOPICS.CATEGORY_POST_EDIT, + ROUTES.TOPICS.TOPIC, + ROUTES.TOPICS.TOPIC_POST, + ROUTES.TOPICS.TOPIC_POST_EDIT, ].map((route) => ( { element={} /> ))} - {[ROUTES.TOPICS.TOPIC, ROUTES.TOPICS.TOPIC_POST, ROUTES.TOPICS.TOPIC_POST_EDIT].map((route) => ( - } - /> - ))} {ROUTES.TOPICS.PATH.map(path => ( } /> ))} @@ -116,7 +112,7 @@ const DiscussionSidebar = ({ displaySidebar, postActionBarRef }) => { } /> )} {configStatus === RequestStatus.SUCCESSFUL && ( - } /> + } /> )} diff --git a/src/discussions/in-context-topics/TopicPostsView.test.jsx b/src/discussions/in-context-topics/TopicPostsView.test.jsx index c3f57316e..0679808a8 100644 --- a/src/discussions/in-context-topics/TopicPostsView.test.jsx +++ b/src/discussions/in-context-topics/TopicPostsView.test.jsx @@ -61,24 +61,23 @@ async function renderComponent({ topicId, category } = { }) { > - - - - - )} - /> - - - - - )} - /> + { + [ + ROUTES.POSTS.PATH, + ROUTES.TOPICS.CATEGORY, + ].map((route) => ( + + + + + )} + /> + )) + } { const intl = useIntl(); const { courseId } = useParams(); - const location = useLocation(); const dispatch = useDispatch(); const orderBy = useSelector(selectLearnerSorting()); const nextPage = useSelector(selectLearnerNextPage()); @@ -84,11 +80,6 @@ const LearnersView = () => { /> )}
- {courseConfigLoadingStatus === RequestStatus.SUCCESSFUL && !learnersTabEnabled && ( - - )} {renderLearnersList} {loadingStatus === RequestStatus.IN_PROGRESS ? (
diff --git a/src/discussions/navigation/breadcrumb-menu/LegacyBreadcrumbMenu.test.jsx b/src/discussions/navigation/breadcrumb-menu/LegacyBreadcrumbMenu.test.jsx index 6b282254a..e0eda57d7 100644 --- a/src/discussions/navigation/breadcrumb-menu/LegacyBreadcrumbMenu.test.jsx +++ b/src/discussions/navigation/breadcrumb-menu/LegacyBreadcrumbMenu.test.jsx @@ -31,14 +31,18 @@ function renderComponent(path) { - } - /> - } - /> + { + [ + ROUTES.POSTS.PATH, + ROUTES.TOPICS.CATEGORY, + ].map((route) => ( + } + /> + )) + } diff --git a/src/discussions/post-comments/PostCommentsView.jsx b/src/discussions/post-comments/PostCommentsView.jsx index c155bd82e..4407b5711 100644 --- a/src/discussions/post-comments/PostCommentsView.jsx +++ b/src/discussions/post-comments/PostCommentsView.jsx @@ -10,7 +10,7 @@ import { ArrowBack } from '@edx/paragon/icons'; import Spinner from '../../components/Spinner'; import { - EndorsementStatus, PAGES, PostsPages, ThreadType, + EndorsementStatus, PostsPages, ThreadType, } from '../../data/constants'; import { useDispatchWithState } from '../../data/hooks'; import { DiscussionContext } from '../common/context'; @@ -18,7 +18,7 @@ import { useIsOnDesktop } from '../data/hooks'; import { EmptyPage } from '../empty-posts'; import { Post } from '../posts'; import { fetchThread } from '../posts/data/thunks'; -import { discussionsPath, truncatePath } from '../utils'; +import { discussionsPath } from '../utils'; import { ResponseEditor } from './comments/comment'; import { useCommentsCount, usePost } from './data/hooks'; import messages from './messages'; @@ -43,10 +43,6 @@ const PostCommentsView = () => { courseId, learnerUsername, category, topicId, })(location); - if (page === PAGES.TOPICS || page === PAGES.CATEGORY) { - redirectUrl.pathname = truncatePath(redirectUrl.pathname); - } - useEffect(() => { if (!threadId) { submitDispatch(fetchThread(postId, courseId, true)); diff --git a/src/discussions/posts/PostsView.test.jsx b/src/discussions/posts/PostsView.test.jsx index a4262c5d0..d420270c7 100644 --- a/src/discussions/posts/PostsView.test.jsx +++ b/src/discussions/posts/PostsView.test.jsx @@ -68,19 +68,16 @@ async function renderComponent({ }} > - } /> - } - /> - } - /> - } - /> + { + [ + ROUTES.POSTS.PATH, + ROUTES.POSTS.MY_POSTS, + ROUTES.POSTS.ALL_POSTS, + ROUTES.TOPICS.CATEGORY, + ].map((route) => ( + } /> + )) + } diff --git a/src/discussions/posts/post/Post.jsx b/src/discussions/posts/post/Post.jsx index dbf2d2fba..f2ff55c25 100644 --- a/src/discussions/posts/post/Post.jsx +++ b/src/discussions/posts/post/Post.jsx @@ -4,14 +4,14 @@ import PropTypes from 'prop-types'; import classNames from 'classnames'; import { toString } from 'lodash'; import { useDispatch, useSelector } from 'react-redux'; -import { matchPath, useLocation, useNavigate } from 'react-router-dom'; +import { useLocation, useNavigate } from 'react-router-dom'; import { getConfig } from '@edx/frontend-platform'; import { useIntl } from '@edx/frontend-platform/i18n'; import { Hyperlink, useToggle } from '@edx/paragon'; import HTMLLoader from '../../../components/HTMLLoader'; -import { ContentActions, Routes } from '../../../data/constants'; +import { ContentActions } from '../../../data/constants'; import { selectorForUnitSubsection, selectTopicContext } from '../../../data/selectors'; import { AlertBanner, Confirmation } from '../../common'; import { DiscussionContext } from '../../common/context'; @@ -50,13 +50,7 @@ const Post = ({ handleAddResponseButton }) => { const displayPostFooter = following || voteCount || closed || (groupId && userHasModerationPrivileges); const handleDeleteConfirmation = useCallback(async () => { - const isTopicCategoryPostsPage = Boolean( - matchPath({ path: Routes.TOPICS.CATEGORY_POST }, location.pathname) - || matchPath({ path: Routes.TOPICS.TOPIC_POST }, location.pathname), - ); - - let basePath = truncatePath(location.pathname); - if (isTopicCategoryPostsPage) { basePath = truncatePath(basePath); } + const basePath = truncatePath(location.pathname); await dispatch(removeThread(postId)); navigate({