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: modified TA icon according to role #664

Closed
wants to merge 7 commits into from
Closed
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 src/data/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const RequestStatus = {
*/
export const AvatarOutlineAndLabelColors = {
Staff: 'staff-color',
Moderator: 'TA-color',
'Community TA': 'TA-color',
};

Expand Down
25 changes: 6 additions & 19 deletions src/discussions/common/AuthorLabel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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;
Expand All @@ -63,17 +52,15 @@ const AuthorLabel = ({
const labelContents = useMemo(() => (
<>
<OverlayTrigger
placement={authorToolTip ? 'top' : 'right'}
overlay={(
<Tooltip id={`endorsed-by-${author}-tooltip`}>
{author}
<Tooltip id={authorToolTip ? `endorsed-by-${author}-tooltip` : `${authorLabel}-label-tooltip`}>
{authorToolTip ? author : authorLabel}
</Tooltip>
)}
trigger={['hover', 'focus']}
>
<div className={classNames('d-flex flex-row align-items-center', {
'disable-div': !authorToolTip,
})}
>
<div className={classNames('d-flex flex-row align-items-center')}>
<Icon
style={{
width: '1rem',
Expand Down
3 changes: 2 additions & 1 deletion src/discussions/common/AuthorLabel.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe('Author label', () => {
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, ''],
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion src/discussions/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
22 changes: 21 additions & 1 deletion src/discussions/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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] || {};
}
Loading