From db8a513f615404fab543d1dad9b530fd748c74ba Mon Sep 17 00:00:00 2001 From: sohailfatima <23100065@lums.edu.pk> Date: Wed, 24 Jan 2024 22:39:01 +0500 Subject: [PATCH 1/3] fix: redirection to learners tab in inContext view --- src/discussions/common/AuthorLabel.jsx | 15 ++++++++++++--- src/discussions/learners/learner/LearnerCard.jsx | 8 +++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/discussions/common/AuthorLabel.jsx b/src/discussions/common/AuthorLabel.jsx index 87f1a6212..92b410a36 100644 --- a/src/discussions/common/AuthorLabel.jsx +++ b/src/discussions/common/AuthorLabel.jsx @@ -2,7 +2,7 @@ import React, { useContext, useMemo } from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; -import { generatePath, Link } from 'react-router-dom'; +import { Link, useLocation } from 'react-router-dom'; import * as timeago from 'timeago.js'; import { useIntl } from '@edx/frontend-platform/i18n'; @@ -11,6 +11,7 @@ import { Institution, School } from '@edx/paragon/icons'; import { Routes } from '../../data/constants'; import messages from '../messages'; +import { discussionsPath } from '../utils'; import { DiscussionContext } from './context'; import timeLocale from './time-locale'; @@ -26,7 +27,7 @@ const AuthorLabel = ({ }) => { timeago.register('time-locale', timeLocale); const intl = useIntl(); - const { courseId } = useContext(DiscussionContext); + const { courseId, enableInContextSidebar } = useContext(DiscussionContext); let icon = null; let authorLabelMessage = null; @@ -109,13 +110,21 @@ const AuthorLabel = ({ ), [author, authorLabelMessage, authorToolTip, icon, isRetiredUser, postCreatedAt, showTextPrimary, alert]); + const { pathname } = discussionsPath(Routes.LEARNERS.POSTS, { + 0: enableInContextSidebar ? 'in-context' : undefined, + learnerUsername: author, + courseId, + })(); + + const { search } = useLocation(); + return showUserNameAsLink ? (
diff --git a/src/discussions/learners/learner/LearnerCard.jsx b/src/discussions/learners/learner/LearnerCard.jsx index 8304cd6c4..7d81c72b1 100644 --- a/src/discussions/learners/learner/LearnerCard.jsx +++ b/src/discussions/learners/learner/LearnerCard.jsx @@ -1,6 +1,6 @@ import React, { useContext } from 'react'; -import { Link } from 'react-router-dom'; +import { Link, useLocation } from 'react-router-dom'; import { Routes } from '../../../data/constants'; import { DiscussionContext } from '../../common/context'; @@ -14,16 +14,18 @@ const LearnerCard = ({ learner }) => { username, threads, inactiveFlags, activeFlags, responses, replies, } = learner; const { enableInContextSidebar, learnerUsername, courseId } = useContext(DiscussionContext); - const linkUrl = discussionsPath(Routes.LEARNERS.POSTS, { + const { pathname } = discussionsPath(Routes.LEARNERS.POSTS, { 0: enableInContextSidebar ? 'in-context' : undefined, learnerUsername: learner.username, courseId, })(); + const { search } = useLocation(); + return (
Date: Thu, 25 Jan 2024 23:29:20 +0500 Subject: [PATCH 2/3] fix: changed username to simple text for incontext view --- src/discussions/common/AuthorLabel.jsx | 16 ++++------------ src/discussions/learners/learner/LearnerCard.jsx | 8 +++----- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/discussions/common/AuthorLabel.jsx b/src/discussions/common/AuthorLabel.jsx index 92b410a36..b145b9735 100644 --- a/src/discussions/common/AuthorLabel.jsx +++ b/src/discussions/common/AuthorLabel.jsx @@ -2,7 +2,7 @@ import React, { useContext, useMemo } from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; -import { Link, useLocation } from 'react-router-dom'; +import { generatePath, Link } from 'react-router-dom'; import * as timeago from 'timeago.js'; import { useIntl } from '@edx/frontend-platform/i18n'; @@ -11,7 +11,6 @@ import { Institution, School } from '@edx/paragon/icons'; import { Routes } from '../../data/constants'; import messages from '../messages'; -import { discussionsPath } from '../utils'; import { DiscussionContext } from './context'; import timeLocale from './time-locale'; @@ -45,7 +44,8 @@ const AuthorLabel = ({ const showTextPrimary = !authorLabelMessage && !isRetiredUser && !alert; const className = classNames('d-flex align-items-center', { 'mb-0.5': !postOrComment }, labelColor); - const showUserNameAsLink = linkToProfile && author && author !== intl.formatMessage(messages.anonymous); + const showUserNameAsLink = linkToProfile && author && author !== intl.formatMessage(messages.anonymous) + && !enableInContextSidebar; const authorName = useMemo(() => ( ), [author, authorLabelMessage, authorToolTip, icon, isRetiredUser, postCreatedAt, showTextPrimary, alert]); - const { pathname } = discussionsPath(Routes.LEARNERS.POSTS, { - 0: enableInContextSidebar ? 'in-context' : undefined, - learnerUsername: author, - courseId, - })(); - - const { search } = useLocation(); - return showUserNameAsLink ? (
diff --git a/src/discussions/learners/learner/LearnerCard.jsx b/src/discussions/learners/learner/LearnerCard.jsx index 7d81c72b1..8304cd6c4 100644 --- a/src/discussions/learners/learner/LearnerCard.jsx +++ b/src/discussions/learners/learner/LearnerCard.jsx @@ -1,6 +1,6 @@ import React, { useContext } from 'react'; -import { Link, useLocation } from 'react-router-dom'; +import { Link } from 'react-router-dom'; import { Routes } from '../../../data/constants'; import { DiscussionContext } from '../../common/context'; @@ -14,18 +14,16 @@ const LearnerCard = ({ learner }) => { username, threads, inactiveFlags, activeFlags, responses, replies, } = learner; const { enableInContextSidebar, learnerUsername, courseId } = useContext(DiscussionContext); - const { pathname } = discussionsPath(Routes.LEARNERS.POSTS, { + const linkUrl = discussionsPath(Routes.LEARNERS.POSTS, { 0: enableInContextSidebar ? 'in-context' : undefined, learnerUsername: learner.username, courseId, })(); - const { search } = useLocation(); - return (
Date: Wed, 31 Jan 2024 14:36:12 +0500 Subject: [PATCH 3/3] test: username is not clickable in incontext view --- src/discussions/common/AuthorLabel.test.jsx | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/discussions/common/AuthorLabel.test.jsx b/src/discussions/common/AuthorLabel.test.jsx index b2136c59e..38762621a 100644 --- a/src/discussions/common/AuthorLabel.test.jsx +++ b/src/discussions/common/AuthorLabel.test.jsx @@ -21,11 +21,11 @@ let store; let axiosMock; let container; -function renderComponent(author, authorLabel, linkToProfile, labelColor) { +function renderComponent(author, authorLabel, linkToProfile, labelColor, enableInContextSidebar) { const wrapper = render( - + { ); it( - `it is "${!linkToProfile && 'not'}" clickable when linkToProfile is ${!!linkToProfile}`, + `it is "${(!linkToProfile) && 'not'}" clickable when linkToProfile is ${!!linkToProfile} and enableInContextSidebar is false`, async () => { - renderComponent(author, authorLabel, linkToProfile, labelColor); + renderComponent(author, authorLabel, linkToProfile, labelColor, false); if (linkToProfile) { expect(screen.queryByTestId('learner-posts-link')).toBeInTheDocument(); @@ -90,6 +90,15 @@ describe('Author label', () => { }, ); + it( + 'it is not clickable when enableInContextSidebar is true', + async () => { + renderComponent(author, authorLabel, linkToProfile, labelColor, true); + + expect(screen.queryByTestId('learner-posts-link')).not.toBeInTheDocument(); + }, + ); + it( `it has "${!linkToProfile && 'not'}" label text and label color when linkToProfile is ${!!linkToProfile}`, async () => {