From f0a4586eed71a60b4e080a8690080357a2c3070e Mon Sep 17 00:00:00 2001 From: ayesha waris <73840786+ayesha-waris@users.noreply.github.com> Date: Thu, 15 Feb 2024 18:12:20 +0500 Subject: [PATCH] feat: modified TA icon according to role (#665) * feat: modified TA icon according to role * fix: fixed icon and tooltip position * fix: fixed failing testcase * refactor: removed duplication * test: added testcases to check for updated user labels * refactor: updated variables names for clarity * refactor: moved authorLabel selection logic to utils --------- Co-authored-by: sohailfatima <23100065@lums.edu.pk> --- src/data/constants.js | 1 + src/discussions/common/AuthorLabel.jsx | 25 +++++---------------- src/discussions/common/AuthorLabel.test.jsx | 3 ++- src/discussions/messages.js | 7 +++++- src/discussions/utils.js | 22 +++++++++++++++++- 5 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/data/constants.js b/src/data/constants.js index 3fa9496e6..50b2078c0 100644 --- a/src/data/constants.js +++ b/src/data/constants.js @@ -80,6 +80,7 @@ export const RequestStatus = { */ export const AvatarOutlineAndLabelColors = { Staff: 'staff-color', + Moderator: 'TA-color', 'Community TA': 'TA-color', }; diff --git a/src/discussions/common/AuthorLabel.jsx b/src/discussions/common/AuthorLabel.jsx index e50bcf168..5314cb408 100644 --- a/src/discussions/common/AuthorLabel.jsx +++ b/src/discussions/common/AuthorLabel.jsx @@ -7,10 +7,10 @@ import * as timeago from 'timeago.js'; import { useIntl } from '@edx/frontend-platform/i18n'; import { Icon, OverlayTrigger, Tooltip } from '@edx/paragon'; -import { Institution, School } from '@edx/paragon/icons'; import { Routes } from '../../data/constants'; import messages from '../messages'; +import { getAuthorLabel } from '../utils'; import DiscussionContext from './context'; import timeLocale from './time-locale'; @@ -27,18 +27,7 @@ const AuthorLabel = ({ timeago.register('time-locale', timeLocale); const intl = useIntl(); const { courseId, enableInContextSidebar } = useContext(DiscussionContext); - let icon = null; - let authorLabelMessage = null; - - if (authorLabel === 'Staff') { - icon = Institution; - authorLabelMessage = intl.formatMessage(messages.authorLabelStaff); - } - - if (authorLabel === 'Community TA') { - icon = School; - authorLabelMessage = intl.formatMessage(messages.authorLabelTA); - } + const { icon, authorLabelMessage } = useMemo(() => getAuthorLabel(intl, authorLabel), [authorLabel]); const isRetiredUser = author ? author.startsWith('retired__user') : false; const showTextPrimary = !authorLabelMessage && !isRetiredUser && !alert; @@ -63,17 +52,15 @@ const AuthorLabel = ({ const labelContents = useMemo(() => ( <> - {author} + + {authorToolTip ? author : authorLabel} )} trigger={['hover', 'focus']} > -
+
{ describe.each([ ['anonymous', null, false, ''], ['ta_user', 'Community TA', true, 'text-TA-color'], + ['moderator_user', 'Moderator', true, 'text-TA-color'], ['retired__user', null, false, ''], ['staff_user', 'Staff', true, 'text-staff-color'], ['learner_user', null, false, ''], @@ -106,7 +107,7 @@ describe('Author label', () => { const authorElement = container.querySelector('[role=heading]'); const labelParentNode = authorElement.parentNode.parentNode; const labelElement = labelParentNode.lastChild.lastChild; - const label = ['TA', 'Staff'].includes(labelElement.textContent) && labelElement.textContent; + const label = ['CTA', 'TA', 'Staff'].includes(labelElement.textContent) && labelElement.textContent; if (linkToProfile) { expect(labelParentNode).toHaveClass(labelColor); diff --git a/src/discussions/messages.js b/src/discussions/messages.js index 555f9df71..b9a3b7471 100644 --- a/src/discussions/messages.js +++ b/src/discussions/messages.js @@ -153,9 +153,14 @@ const messages = defineMessages({ defaultMessage: 'Staff', description: 'A label for staff users displayed next to their username.', }, + authorLabelModerator: { + id: 'discussions.authors.label.moderator', + defaultMessage: 'TA', + description: 'A label for moderators displayed next to their username.', + }, authorLabelTA: { id: 'discussions.authors.label.ta', - defaultMessage: 'TA', + defaultMessage: 'CTA', description: 'A label for community TAs displayed next to their username.', }, loadMorePosts: { diff --git a/src/discussions/utils.js b/src/discussions/utils.js index 77fcd6b47..0bcf34c53 100644 --- a/src/discussions/utils.js +++ b/src/discussions/utils.js @@ -10,7 +10,8 @@ import { import { getConfig } from '@edx/frontend-platform'; import { CheckCircle, CheckCircleOutline, Delete, Edit, InsertLink, - Lock, LockOpen, Pin, Report, Verified, VerifiedOutline, + Institution, Lock, LockOpen, Pin, Report, School, + Verified, VerifiedOutline, } from '@edx/paragon/icons'; import { @@ -293,3 +294,22 @@ export function isLastElementOfList(list, element) { export function truncatePath(path) { return path.substring(0, path.lastIndexOf('/')); } + +export function getAuthorLabel(intl, authorLabel) { + const authorLabelMappings = { + Staff: { + icon: Institution, + authorLabelMessage: intl.formatMessage(messages.authorLabelStaff), + }, + Moderator: { + icon: School, + authorLabelMessage: intl.formatMessage(messages.authorLabelModerator), + }, + 'Community TA': { + icon: School, + authorLabelMessage: intl.formatMessage(messages.authorLabelTA), + }, + }; + + return authorLabelMappings[authorLabel] || {}; +}