Skip to content

Commit

Permalink
Merge branch 'master' of github.com:openedx/frontend-app-discussions …
Browse files Browse the repository at this point in the history
…into Ali-Abbas/react-router-upgrade
  • Loading branch information
Syed-Ali-Abbas-Zaidi committed Dec 7, 2023
2 parents 994b3cd + b36c026 commit 69e3830
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 13 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"react-router": "6.18.0",
"react-router-dom": "6.18.0",
"redux": "4.1.2",
"regenerator-runtime": "0.13.9",
"regenerator-runtime": "0.14.0",
"timeago.js": "4.0.2",
"tinymce": "5.10.7",
"yup": "0.31.1"
Expand Down
5 changes: 4 additions & 1 deletion src/data/constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { getConfig } from '@edx/frontend-platform';

export const getApiBaseUrl = () => getConfig().LMS_BASE_URL;
export const getFullUrl = (path) => (
new URL(`${getConfig().PUBLIC_PATH.replace(/\/$/, '')}/${path}`, window.location.origin).href
);

/**
* Enum for thread types.
Expand Down Expand Up @@ -137,7 +140,7 @@ export const DiscussionProvider = {
OPEN_EDX: 'openedx',
};

const BASE_PATH = `${getConfig().PUBLIC_PATH}:courseId`;
const BASE_PATH = '/:courseId';

export const Routes = {
DISCUSSIONS: {
Expand Down
14 changes: 14 additions & 0 deletions src/discussions/post-comments/PostCommentsView.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,20 @@ describe('ThreadView', () => {
assertLastUpdateData({ pinned: false });
});

it('should allow copying a link to the post', async () => {
await waitFor(() => renderComponent(discussionPostId));
const post = await screen.findByTestId('post-thread-1');
const hoverCard = within(post).getByTestId('hover-card-thread-1');
Object.assign(navigator, { clipboard: { writeText: jest.fn() } });
await act(async () => {
fireEvent.click(within(hoverCard).getByRole('button', { name: /actions menu/i }));
});
await act(async () => {
fireEvent.click(within(hoverCard).getByRole('button', { name: /copy link/i }));
});
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(`http://localhost/${courseId}/posts/${discussionPostId}`);
});

it('should allow reporting the post', async () => {
await waitFor(() => renderComponent(discussionPostId));
const post = await screen.findByTestId('post-thread-1');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Factory.define('thread')
'type',
'voted',
'pinned',
'copy_link',
],
author: 'test_user',
author_label: 'Staff',
Expand Down
7 changes: 3 additions & 4 deletions src/discussions/posts/post/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useIntl } from '@edx/frontend-platform/i18n';
import { Hyperlink, useToggle } from '@edx/paragon';

import HTMLLoader from '../../../components/HTMLLoader';
import { ContentActions } from '../../../data/constants';
import { ContentActions, getFullUrl } from '../../../data/constants';
import { selectorForUnitSubsection, selectTopicContext } from '../../../data/selectors';
import { AlertBanner, Confirmation } from '../../common';
import { DiscussionContext } from '../../common/context';
Expand All @@ -38,7 +38,7 @@ const Post = ({ handleAddResponseButton }) => {
const location = useLocation();
const navigate = useNavigate();
const dispatch = useDispatch();
const courseId = useSelector((state) => state.config.id);
const { courseId } = useContext(DiscussionContext);
const topic = useSelector(selectTopic(topicId));
const getTopicSubsection = useSelector(selectorForUnitSubsection);
const topicContext = useSelector(selectTopicContext(topicId));
Expand Down Expand Up @@ -78,8 +78,7 @@ const Post = ({ handleAddResponseButton }) => {
}, [closed, postId, showClosePostModal]);

const handlePostCopyLink = useCallback(() => {
const postURL = new URL(`${getConfig().PUBLIC_PATH}${courseId}/posts/${postId}`, window.location.origin);
navigator.clipboard.writeText(postURL.href);
navigator.clipboard.writeText(getFullUrl(`${courseId}/posts/${postId}`));
}, [window.location.origin, postId, courseId]);

const handlePostPin = useCallback(() => dispatch(
Expand Down

0 comments on commit 69e3830

Please sign in to comment.