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

feat: Profile image on user posts (redwood.master) #746

Open
wants to merge 1 commit into
base: open-release/redwood.master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ USER_INFO_COOKIE_NAME=''
SUPPORT_URL=''
LEARNER_FEEDBACK_URL=''
STAFF_FEEDBACK_URL=''
ENABLE_PROFILE_IMAGE=''
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ USER_INFO_COOKIE_NAME='edx-user-info'
SUPPORT_URL='https://support.edx.org'
LEARNER_FEEDBACK_URL=''
STAFF_FEEDBACK_URL=''
ENABLE_PROFILE_IMAGE='true'
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ USER_INFO_COOKIE_NAME='edx-user-info'
SUPPORT_URL='https://support.edx.org'
LEARNER_FEEDBACK_URL=''
STAFF_FEEDBACK_URL=''
ENABLE_PROFILE_IMAGE=''
8 changes: 1 addition & 7 deletions src/discussions/data/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,11 @@ import { ContentSelectors } from './constants';
import {
selectAreThreadsFiltered,
selectEnableInContext,
selectIsCourseAdmin,
selectIsCourseStaff,
selectIsPostingEnabled,
selectIsUserLearner,
selectPostThreadCount,
selectUserHasModerationPrivileges,
selectUserIsGroupTa,
selectUserIsStaff,
} from './selectors';
import fetchCourseConfig from './thunks';

Expand Down Expand Up @@ -220,12 +217,9 @@ export const useCurrentDiscussionTopic = () => {

export const useUserPostingEnabled = () => {
const isPostingEnabled = useSelector(selectIsPostingEnabled);
const isUserAdmin = useSelector(selectUserIsStaff);
const userHasModerationPrivileges = useSelector(selectUserHasModerationPrivileges);
const isUserGroupTA = useSelector(selectUserIsGroupTa);
const isCourseAdmin = useSelector(selectIsCourseAdmin);
const isCourseStaff = useSelector(selectIsCourseStaff);
const isPrivileged = isUserAdmin || userHasModerationPrivileges || isUserGroupTA || isCourseAdmin || isCourseStaff;
const isPrivileged = userHasModerationPrivileges || isUserGroupTA;

return (isPostingEnabled || isPrivileged);
};
Expand Down
8 changes: 4 additions & 4 deletions src/discussions/data/hooks.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ const courseConfigApiUrl = getCourseConfigApiUrl();
let store;
let axiosMock;

const generateApiResponse = (isPostingEnabled, isCourseAdmin = false) => ({
const generateApiResponse = (isPostingEnabled, hasModerationPrivileges = false) => ({
isPostingEnabled,
hasModerationPrivileges: false,
hasModerationPrivileges,
isGroupTa: false,
isCourseAdmin,
isCourseAdmin: false,
isCourseStaff: false,
isUserAdmin: false,
});
Expand Down Expand Up @@ -160,7 +160,7 @@ describe('Hooks', () => {
expect(queryByText('false')).toBeInTheDocument();
});

test('when posting is not disabled and Role is not Learner return true', async () => {
test('when posting is disabled and Role is not Learner return true', async () => {
axiosMock.onGet(`${courseConfigApiUrl}${courseId}/`)
.reply(200, generateApiResponse(false, true));
await executeThunk(fetchCourseConfig(courseId), store.dispatch, store.getState);
Expand Down
3 changes: 2 additions & 1 deletion src/discussions/post-comments/comments/comment/Comment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const Comment = ({
const {
id, parentId, childCount, abuseFlagged, endorsed, threadId, endorsedAt, endorsedBy, endorsedByLabel, renderedBody,
voted, following, voteCount, authorLabel, author, createdAt, lastEdit, rawBody, closed, closedBy, closeReason,
editByLabel, closedByLabel,
editByLabel, closedByLabel, users: postUsers,
} = comment;
const intl = useIntl();
const hasChildren = childCount > 0;
Expand Down Expand Up @@ -203,6 +203,7 @@ const Comment = ({
closed={closed}
createdAt={createdAt}
lastEdit={lastEdit}
postUsers={postUsers}
/>
{isEditing ? (
<CommentEditor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import PropTypes from 'prop-types';
import { Avatar } from '@openedx/paragon';
import classNames from 'classnames';

import { getConfig } from '@edx/frontend-platform';

import { AvatarOutlineAndLabelColors } from '../../../../data/constants';
import { AuthorLabel } from '../../../common';
import { useAlertBannerVisible } from '../../../data/hooks';
Expand All @@ -15,6 +17,7 @@ const CommentHeader = ({
closed,
createdAt,
lastEdit,
postUsers,
}) => {
const colorClass = AvatarOutlineAndLabelColors[authorLabel];
const hasAnyAlert = useAlertBannerVisible({
Expand All @@ -24,6 +27,8 @@ const CommentHeader = ({
closed,
});

const profileImage = getConfig().ENABLE_PROFILE_IMAGE === 'true' && postUsers && Object.values(postUsers)[0].profile.image;

return (
<div className={classNames('d-flex flex-row justify-content-between', {
'mt-2': hasAnyAlert,
Expand All @@ -33,6 +38,7 @@ const CommentHeader = ({
<Avatar
className={`border-0 ml-0.5 mr-2.5 ${colorClass ? `outline-${colorClass}` : 'outline-anonymous'}`}
alt={author}
src={profileImage?.hasImage ? profileImage?.imageUrlSmall : undefined}
style={{
width: '32px',
height: '32px',
Expand Down Expand Up @@ -61,6 +67,7 @@ CommentHeader.propTypes = {
editorUsername: PropTypes.string,
reason: PropTypes.string,
}),
postUsers: PropTypes.shape({}).isRequired,
};

CommentHeader.defaultProps = {
Expand Down
3 changes: 2 additions & 1 deletion src/discussions/posts/post/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const Post = ({ handleAddResponseButton }) => {
const {
topicId, abuseFlagged, closed, pinned, voted, hasEndorsed, following, closedBy, voteCount, groupId, groupName,
closeReason, authorLabel, type: postType, author, title, createdAt, renderedBody, lastEdit, editByLabel,
closedByLabel,
closedByLabel, users: postUsers,
} = useSelector(selectThread(postId));
const intl = useIntl();
const location = useLocation();
Expand Down Expand Up @@ -182,6 +182,7 @@ const Post = ({ handleAddResponseButton }) => {
lastEdit={lastEdit}
postType={postType}
title={title}
postUsers={postUsers}
/>
<div className="d-flex mt-14px text-break font-style text-primary-500">
<HTMLLoader htmlNode={renderedBody} componentId="post" cssClassName="html-loader w-100" testId={postId} />
Expand Down
11 changes: 9 additions & 2 deletions src/discussions/posts/post/PostHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Avatar, Badge, Icon } from '@openedx/paragon';
import { Question } from '@openedx/paragon/icons';
import classNames from 'classnames';

import { getConfig } from '@edx/frontend-platform';
import { useIntl } from '@edx/frontend-platform/i18n';

import { AvatarOutlineAndLabelColors, ThreadType } from '../../../data/constants';
Expand All @@ -13,7 +14,7 @@ import { useAlertBannerVisible } from '../../data/hooks';
import messages from './messages';

export const PostAvatar = React.memo(({
author, postType, authorLabel, fromPostLink, read,
author, postType, authorLabel, fromPostLink, read, postUsers,
}) => {
const outlineColor = AvatarOutlineAndLabelColors[authorLabel];

Expand All @@ -37,6 +38,8 @@ export const PostAvatar = React.memo(({
return spacing;
}, [postType]);

const profileImage = getConfig().ENABLE_PROFILE_IMAGE === 'true' && postUsers && Object.values(postUsers)[0].profile.image;

return (
<div className={avatarSpacing}>
{postType === ThreadType.QUESTION && (
Expand All @@ -59,6 +62,7 @@ export const PostAvatar = React.memo(({
height: avatarSize,
width: avatarSize,
}}
src={profileImage?.hasImage ? profileImage?.imageUrlSmall : undefined}
alt={author}
/>
</div>
Expand All @@ -71,6 +75,7 @@ PostAvatar.propTypes = {
authorLabel: PropTypes.string,
fromPostLink: PropTypes.bool,
read: PropTypes.bool,
postUsers: PropTypes.shape({}).isRequired,
};

PostAvatar.defaultProps = {
Expand All @@ -90,6 +95,7 @@ const PostHeader = ({
title,
postType,
preview,
postUsers,
}) => {
const intl = useIntl();
const showAnsweredBadge = preview && hasEndorsed && postType === ThreadType.QUESTION;
Expand All @@ -101,7 +107,7 @@ const PostHeader = ({
return (
<div className={classNames('d-flex flex-fill mw-100', { 'mt-10px': hasAnyAlert && !preview })}>
<div className="flex-shrink-0">
<PostAvatar postType={postType} author={author} authorLabel={authorLabel} />
<PostAvatar postType={postType} author={author} authorLabel={authorLabel} postUsers={postUsers} />
</div>
<div className="align-items-center d-flex flex-row">
<div className="d-flex flex-column justify-content-start mw-100">
Expand Down Expand Up @@ -151,6 +157,7 @@ PostHeader.propTypes = {
reason: PropTypes.string,
}),
closed: PropTypes.bool,
postUsers: PropTypes.shape({}).isRequired,
};

PostHeader.defaultProps = {
Expand Down
2 changes: 2 additions & 0 deletions src/discussions/posts/post/PostLink.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const PostLink = ({
const {
topicId, hasEndorsed, type, author, authorLabel, abuseFlagged, abuseFlaggedCount, read, commentCount,
unreadCommentCount, id, pinned, previewBody, title, voted, voteCount, following, groupId, groupName, createdAt,
users: postUsers,
} = useSelector(selectThread(postId));
const { pathname } = discussionsPath(Routes.COMMENTS.PAGES[page], {
0: enableInContextSidebar ? 'in-context' : undefined,
Expand Down Expand Up @@ -83,6 +84,7 @@ const PostLink = ({
authorLabel={authorLabel}
fromPostLink
read={isPostRead}
postUsers={postUsers}
/>
<div className="d-flex flex-column flex-fill" style={{ minWidth: 0 }}>
<div className="d-flex flex-column justify-content-start mw-100 flex-fill" style={{ marginBottom: '-3px' }}>
Expand Down
1 change: 1 addition & 0 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ initialize({
LEARNING_BASE_URL: process.env.LEARNING_BASE_URL,
LEARNER_FEEDBACK_URL: process.env.LEARNER_FEEDBACK_URL,
STAFF_FEEDBACK_URL: process.env.STAFF_FEEDBACK_URL,
ENABLE_PROFILE_IMAGE: process.env.ENABLE_PROFILE_IMAGE,
}, 'DiscussionsConfig');
},
},
Expand Down
Loading