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

fix: post sharing URL #455

Merged
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion src/discussions/posts/post/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
import { useDispatch, useSelector } from 'react-redux';
import { useHistory, useLocation } from 'react-router-dom';

import { getConfig } from '@edx/frontend-platform';
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { Hyperlink, useToggle } from '@edx/paragon';

Expand Down Expand Up @@ -35,6 +36,9 @@ function Post({
const { reasonCodesEnabled } = useSelector(selectModerationSettings);
const [isDeleting, showDeleteConfirmation, hideDeleteConfirmation] = useToggle(false);
const [isClosing, showClosePostModal, hideClosePostModal] = useToggle(false);

const postURL = new URL(`${getConfig().PUBLIC_PATH}${courseId}/posts/${post.id}`, window.location.origin);
Copy link
Contributor

Choose a reason for hiding this comment

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

We use BASE_URL in discussions MFE. PUBLIC_PATH is not valid in configuration.

Copy link
Contributor Author

@dyudyunov dyudyunov Mar 7, 2023

Choose a reason for hiding this comment

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

I didn't get it, can you explain in detail?

The PUBLIC_PATH has a default value set to '/' (source). It is used for subdomain-based deployments.
In the case of the subdirectory-based deployments, it will be set for each MFE individually. In my case, its value is '/discussions/'.

The BASE_URL var has a form of the "{{ MFE_BASE_SCHEMA }}://{{ MFE_BASE }}" where the MFE_BASE will be
the same value ("mfe.{{ EDXAPP_LMS_BASE }}") for all MFEs in case of using subdirectory-based deployment (from the README for the MFE deployer)

Why is the PUBLIC_PATH not valid?

How can I use the BASE_URL in case of subdirectory-based deployments?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PUBLIC_PATH is actually used in the discussions MFE

Copy link
Contributor

Choose a reason for hiding this comment

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

here is the example.
BASE_URL='http://localhost:2002'
${getConfig().BASE_URL}/${courseId}/topics/${post.topicId}}`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

here is the example. BASE_URL='http://localhost:2002' ${getConfig().BASE_URL}/${courseId}/topics/${post.topicId}}`

Yes that's understandable
But the issue I'm trying to fix - is that the PUBLIC_PATH is NOT processed now. And in the case of using the URL construction like ${getConfig().BASE_URL}/${courseId}/topics/${post.topicId}} you'll get an invalid results if you're using the subdirectory-based deployment (your URL actually should be ${getConfig().BASE_URL}${getConfig().PUBLIC_PATH}${courseId}/topics/${post.topicId}})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what if I use ${getConfig().PUBLIC_PATH || '/'} instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I still don't understand why you're saying your instances are lacking the default for the PUBLIC_PATH (which is '/') defined in both configuration and frontend-build repositories

Copy link
Contributor

Choose a reason for hiding this comment

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

@asadazam93 and @muhammadadeeltajamul, any Open edX MFE must support path-based deployments, regardless of what your production deployment looks like. That's the whole point of the configuration variable: to allow users to deploy it in different ways.

With that in mind, it looks to me like @dyudyunov's fix is correct.

Copy link
Contributor

Choose a reason for hiding this comment

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

We will need to fix the deployment path before we can merge this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@asadazam93 can you test it on the sandbox instance? I think you don't need to change your env because the default value ('/') should work well for you


const actionHandlers = {
[ContentActions.EDIT_CONTENT]: () => history.push({
...location,
Expand All @@ -50,7 +54,7 @@ function Post({
dispatch(updateExistingThread(post.id, { closed: true }));
}
},
[ContentActions.COPY_LINK]: () => { navigator.clipboard.writeText(`${window.location.origin}/${courseId}/posts/${post.id}`); },
[ContentActions.COPY_LINK]: () => { navigator.clipboard.writeText(postURL.href); },
[ContentActions.PIN]: () => dispatch(updateExistingThread(post.id, { pinned: !post.pinned })),
[ContentActions.REPORT]: () => dispatch(updateExistingThread(post.id, { flagged: !post.abuseFlagged })),
};
Expand Down