Skip to content

Commit f0a4586

Browse files
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 <[email protected]>
1 parent 9eaed2b commit f0a4586

File tree

5 files changed

+36
-22
lines changed

5 files changed

+36
-22
lines changed

src/data/constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export const RequestStatus = {
8080
*/
8181
export const AvatarOutlineAndLabelColors = {
8282
Staff: 'staff-color',
83+
Moderator: 'TA-color',
8384
'Community TA': 'TA-color',
8485
};
8586

src/discussions/common/AuthorLabel.jsx

+6-19
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import * as timeago from 'timeago.js';
77

88
import { useIntl } from '@edx/frontend-platform/i18n';
99
import { Icon, OverlayTrigger, Tooltip } from '@edx/paragon';
10-
import { Institution, School } from '@edx/paragon/icons';
1110

1211
import { Routes } from '../../data/constants';
1312
import messages from '../messages';
13+
import { getAuthorLabel } from '../utils';
1414
import DiscussionContext from './context';
1515
import timeLocale from './time-locale';
1616

@@ -27,18 +27,7 @@ const AuthorLabel = ({
2727
timeago.register('time-locale', timeLocale);
2828
const intl = useIntl();
2929
const { courseId, enableInContextSidebar } = useContext(DiscussionContext);
30-
let icon = null;
31-
let authorLabelMessage = null;
32-
33-
if (authorLabel === 'Staff') {
34-
icon = Institution;
35-
authorLabelMessage = intl.formatMessage(messages.authorLabelStaff);
36-
}
37-
38-
if (authorLabel === 'Community TA') {
39-
icon = School;
40-
authorLabelMessage = intl.formatMessage(messages.authorLabelTA);
41-
}
30+
const { icon, authorLabelMessage } = useMemo(() => getAuthorLabel(intl, authorLabel), [authorLabel]);
4231

4332
const isRetiredUser = author ? author.startsWith('retired__user') : false;
4433
const showTextPrimary = !authorLabelMessage && !isRetiredUser && !alert;
@@ -63,17 +52,15 @@ const AuthorLabel = ({
6352
const labelContents = useMemo(() => (
6453
<>
6554
<OverlayTrigger
55+
placement={authorToolTip ? 'top' : 'right'}
6656
overlay={(
67-
<Tooltip id={`endorsed-by-${author}-tooltip`}>
68-
{author}
57+
<Tooltip id={authorToolTip ? `endorsed-by-${author}-tooltip` : `${authorLabel}-label-tooltip`}>
58+
{authorToolTip ? author : authorLabel}
6959
</Tooltip>
7060
)}
7161
trigger={['hover', 'focus']}
7262
>
73-
<div className={classNames('d-flex flex-row align-items-center', {
74-
'disable-div': !authorToolTip,
75-
})}
76-
>
63+
<div className={classNames('d-flex flex-row align-items-center')}>
7764
<Icon
7865
style={{
7966
width: '1rem',

src/discussions/common/AuthorLabel.test.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ describe('Author label', () => {
6262
describe.each([
6363
['anonymous', null, false, ''],
6464
['ta_user', 'Community TA', true, 'text-TA-color'],
65+
['moderator_user', 'Moderator', true, 'text-TA-color'],
6566
['retired__user', null, false, ''],
6667
['staff_user', 'Staff', true, 'text-staff-color'],
6768
['learner_user', null, false, ''],
@@ -106,7 +107,7 @@ describe('Author label', () => {
106107
const authorElement = container.querySelector('[role=heading]');
107108
const labelParentNode = authorElement.parentNode.parentNode;
108109
const labelElement = labelParentNode.lastChild.lastChild;
109-
const label = ['TA', 'Staff'].includes(labelElement.textContent) && labelElement.textContent;
110+
const label = ['CTA', 'TA', 'Staff'].includes(labelElement.textContent) && labelElement.textContent;
110111

111112
if (linkToProfile) {
112113
expect(labelParentNode).toHaveClass(labelColor);

src/discussions/messages.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,14 @@ const messages = defineMessages({
153153
defaultMessage: 'Staff',
154154
description: 'A label for staff users displayed next to their username.',
155155
},
156+
authorLabelModerator: {
157+
id: 'discussions.authors.label.moderator',
158+
defaultMessage: 'TA',
159+
description: 'A label for moderators displayed next to their username.',
160+
},
156161
authorLabelTA: {
157162
id: 'discussions.authors.label.ta',
158-
defaultMessage: 'TA',
163+
defaultMessage: 'CTA',
159164
description: 'A label for community TAs displayed next to their username.',
160165
},
161166
loadMorePosts: {

src/discussions/utils.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
import { getConfig } from '@edx/frontend-platform';
1111
import {
1212
CheckCircle, CheckCircleOutline, Delete, Edit, InsertLink,
13-
Lock, LockOpen, Pin, Report, Verified, VerifiedOutline,
13+
Institution, Lock, LockOpen, Pin, Report, School,
14+
Verified, VerifiedOutline,
1415
} from '@edx/paragon/icons';
1516

1617
import {
@@ -293,3 +294,22 @@ export function isLastElementOfList(list, element) {
293294
export function truncatePath(path) {
294295
return path.substring(0, path.lastIndexOf('/'));
295296
}
297+
298+
export function getAuthorLabel(intl, authorLabel) {
299+
const authorLabelMappings = {
300+
Staff: {
301+
icon: Institution,
302+
authorLabelMessage: intl.formatMessage(messages.authorLabelStaff),
303+
},
304+
Moderator: {
305+
icon: School,
306+
authorLabelMessage: intl.formatMessage(messages.authorLabelModerator),
307+
},
308+
'Community TA': {
309+
icon: School,
310+
authorLabelMessage: intl.formatMessage(messages.authorLabelTA),
311+
},
312+
};
313+
314+
return authorLabelMappings[authorLabel] || {};
315+
}

0 commit comments

Comments
 (0)