Skip to content

Commit 3391e96

Browse files
feat: added help section for post documentation (#733)
* feat: added help section for post documentation * refactor: refactor code
1 parent 4297a96 commit 3391e96

File tree

5 files changed

+150
-3
lines changed

5 files changed

+150
-3
lines changed

src/components/PostHelpPanel.jsx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import React, { useState } from 'react';
2+
3+
import {
4+
Hyperlink, Icon, IconButton, IconButtonWithTooltip,
5+
} from '@openedx/paragon';
6+
import { Close, HelpOutline } from '@openedx/paragon/icons';
7+
8+
import { useIntl } from '@edx/frontend-platform/i18n';
9+
10+
import messages from '../discussions/posts/post-editor/messages';
11+
12+
const PostHelpPanel = () => {
13+
const intl = useIntl();
14+
const [showHelpPane, setShowHelpPane] = useState(false);
15+
16+
return (
17+
<>
18+
<div className="d-flex justify-content-end">
19+
<IconButtonWithTooltip
20+
onClick={() => setShowHelpPane(true)}
21+
alt={intl.formatMessage(messages.showHelpIcon)}
22+
tooltipContent={<div>{intl.formatMessage(messages.discussionHelpTooltip)}</div>}
23+
src={HelpOutline}
24+
iconAs={Icon}
25+
size="inline"
26+
className="float-right p-3 help-icon"
27+
iconClassNames="help-icon-size"
28+
data-testid="help-button"
29+
invertColors
30+
isActive
31+
/>
32+
</div>
33+
{showHelpPane && (
34+
<div
35+
className="w-100 p-2 bg-light-200 rounded box-shadow-down-1 post-preview overflow-auto my-3"
36+
style={{ minHeight: '200px', wordBreak: 'break-word' }}
37+
>
38+
<IconButton
39+
onClick={() => setShowHelpPane(false)}
40+
alt={intl.formatMessage(messages.actionsAlt)}
41+
src={Close}
42+
iconAs={Icon}
43+
size="inline"
44+
className="float-right p-3"
45+
iconClassNames="icon-size"
46+
data-testid="hide-help-button"
47+
/>
48+
<div className="pt-2 px-3">
49+
<h4 className="font-weight-bold">{intl.formatMessage(messages.discussionHelpHeader)}</h4>
50+
<p className="pt-2">{intl.formatMessage(messages.discussionHelpDescription)}</p>
51+
<Hyperlink
52+
target="_blank"
53+
className="w-100"
54+
destination="https://support.edx.org/hc/en-us/sections/115004169687-Participating-in-Course-Discussions"
55+
showLaunchIcon={false}
56+
>
57+
{intl.formatMessage(messages.discussionHelpCourseParticipation)}
58+
</Hyperlink>
59+
<Hyperlink
60+
target="_blank"
61+
className="w-100"
62+
destination="https://support.edx.org/hc/en-us/articles/360000035267-Entering-math-expressions-in-course-discussions"
63+
showLaunchIcon={false}
64+
>
65+
{intl.formatMessage(messages.discussionHelpMathExpressions)}
66+
</Hyperlink>
67+
</div>
68+
</div>
69+
)}
70+
</>
71+
);
72+
};
73+
74+
export default React.memo(PostHelpPanel);

src/discussions/posts/post-editor/PostEditor.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { AppContext } from '@edx/frontend-platform/react';
1818

1919
import { TinyMCEEditor } from '../../../components';
2020
import FormikErrorFeedback from '../../../components/FormikErrorFeedback';
21+
import PostHelpPanel from '../../../components/PostHelpPanel';
2122
import PostPreviewPanel from '../../../components/PostPreviewPanel';
2223
import useDispatchWithState from '../../../data/hooks';
2324
import selectCourseCohorts from '../../cohorts/data/selectors';
@@ -409,6 +410,7 @@ const PostEditor = ({
409410
onEditorChange={formikCompatibleHandler(handleChange, 'comment')}
410411
onBlur={formikCompatibleHandler(handleBlur, 'comment')}
411412
/>
413+
<PostHelpPanel />
412414
<FormikErrorFeedback name="comment" />
413415
</div>
414416
<PostPreviewPanel htmlNode={values.comment} isPost editExisting={editExisting} />

src/discussions/posts/post-editor/PostEditor.test.jsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,5 +368,34 @@ describe('PostEditor', () => {
368368
expect(container.querySelector('[data-testid="hide-preview-button"]')).not.toBeInTheDocument();
369369
});
370370
});
371+
372+
it('should show Help Panel', async () => {
373+
await renderComponent(true, `/${courseId}/posts/${threadId}/edit`);
374+
375+
await act(async () => {
376+
fireEvent.click(container.querySelector('[data-testid="help-button"]'));
377+
});
378+
379+
await waitFor(() => {
380+
expect(container.querySelector('[data-testid="hide-help-button"]')).toBeInTheDocument();
381+
});
382+
});
383+
384+
it('should hide Help Panel', async () => {
385+
await renderComponent(true, `/${courseId}/posts/${threadId}/edit`);
386+
387+
await act(async () => {
388+
fireEvent.click(container.querySelector('[data-testid="help-button"]'));
389+
});
390+
391+
await act(async () => {
392+
fireEvent.click(container.querySelector('[data-testid="hide-help-button"]'));
393+
});
394+
395+
await waitFor(() => {
396+
expect(container.querySelector('[data-testid="help-button"]')).toBeInTheDocument();
397+
expect(container.querySelector('[data-testid="hide-help-button"]')).not.toBeInTheDocument();
398+
});
399+
});
371400
});
372401
});

src/discussions/posts/post-editor/messages.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,36 @@ const messages = defineMessages({
116116
defaultMessage: 'Show preview',
117117
description: 'show preview button text to allow user to see their post content.',
118118
},
119+
showHelpIcon: {
120+
id: 'discussions.editor.posts.showHelp.icon',
121+
defaultMessage: 'Show Help',
122+
description: 'show help icon to allow user to see important documentation.',
123+
},
124+
discussionHelpHeader: {
125+
id: 'discussions.editor.posts.discussionHelpHeader',
126+
defaultMessage: 'Discussions help',
127+
description: 'header text for post help section.',
128+
},
129+
discussionHelpDescription: {
130+
id: 'discussions.editor.posts.discussionHelpDescription',
131+
defaultMessage: 'Course discussions give you the opportunity to start conversations, ask questions, and interact with other learners. See the links below to learn more:',
132+
description: 'description message for post help section.',
133+
},
134+
discussionHelpCourseParticipation: {
135+
id: 'discussions.editor.posts.discussionHelpCourseParticipation',
136+
defaultMessage: 'Participating in course discussions',
137+
description: 'Documentation link title for participating in course discussions.',
138+
},
139+
discussionHelpMathExpressions: {
140+
id: 'discussions.editor.posts.discussionHelpMathExpressions',
141+
defaultMessage: 'Entering math expressions in course discussions',
142+
description: 'Documentation link title for entering math expressions in course discussions.',
143+
},
144+
discussionHelpTooltip: {
145+
id: 'discussions.editor.posts.discussionHelpTooltip',
146+
defaultMessage: 'Learn more about MathJax & LaTeX',
147+
description: 'Tooltip help message for documentation help.',
148+
},
119149
actionsAlt: {
120150
id: 'discussions.actions.label',
121151
defaultMessage: 'Actions menu',

src/index.scss

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,15 @@ th, td {
593593
white-space: nowrap;
594594
}
595595

596+
.help-icon {
597+
margin: -47px -3px 0px 0px;
598+
}
599+
600+
.help-icon-size {
601+
height: 16px !important;
602+
width: 16px !important;
603+
}
604+
596605
@media only screen and (max-width: 367px) {
597606

598607
.discussion-comments h5,
@@ -603,7 +612,8 @@ th, td {
603612
.pgn__modal,
604613
.pgn__form-label,
605614
.dropdown-menu,
606-
.tox-tbtn {
615+
.tox-tbtn,
616+
.tooltip {
607617
font-size: 10px !important;
608618
}
609619

@@ -640,7 +650,8 @@ th, td {
640650
.pgn__form-label,
641651
.pgn__modal,
642652
.dropdown-menu,
643-
.tox-tbtn {
653+
.tox-tbtn,
654+
.tooltip {
644655
font-size: 12px !important;
645656
}
646657

@@ -659,7 +670,8 @@ th, td {
659670
@media only screen and (min-width: 769px) {
660671

661672
body,
662-
#main {
673+
#main,
674+
.tooltip {
663675
font-size: 14px;
664676
}
665677
}

0 commit comments

Comments
 (0)