Skip to content

Commit

Permalink
feat: added help section for post documentation (#733)
Browse files Browse the repository at this point in the history
* feat: added help section for post documentation

* refactor: refactor code
  • Loading branch information
sundasnoreen12 authored Aug 8, 2024
1 parent 4297a96 commit 3391e96
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 3 deletions.
74 changes: 74 additions & 0 deletions src/components/PostHelpPanel.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React, { useState } from 'react';

import {
Hyperlink, Icon, IconButton, IconButtonWithTooltip,
} from '@openedx/paragon';
import { Close, HelpOutline } from '@openedx/paragon/icons';

import { useIntl } from '@edx/frontend-platform/i18n';

import messages from '../discussions/posts/post-editor/messages';

const PostHelpPanel = () => {
const intl = useIntl();
const [showHelpPane, setShowHelpPane] = useState(false);

return (
<>
<div className="d-flex justify-content-end">
<IconButtonWithTooltip
onClick={() => setShowHelpPane(true)}
alt={intl.formatMessage(messages.showHelpIcon)}
tooltipContent={<div>{intl.formatMessage(messages.discussionHelpTooltip)}</div>}
src={HelpOutline}
iconAs={Icon}
size="inline"
className="float-right p-3 help-icon"
iconClassNames="help-icon-size"
data-testid="help-button"
invertColors
isActive
/>
</div>
{showHelpPane && (
<div
className="w-100 p-2 bg-light-200 rounded box-shadow-down-1 post-preview overflow-auto my-3"
style={{ minHeight: '200px', wordBreak: 'break-word' }}
>
<IconButton
onClick={() => setShowHelpPane(false)}
alt={intl.formatMessage(messages.actionsAlt)}
src={Close}
iconAs={Icon}
size="inline"
className="float-right p-3"
iconClassNames="icon-size"
data-testid="hide-help-button"
/>
<div className="pt-2 px-3">
<h4 className="font-weight-bold">{intl.formatMessage(messages.discussionHelpHeader)}</h4>
<p className="pt-2">{intl.formatMessage(messages.discussionHelpDescription)}</p>
<Hyperlink
target="_blank"
className="w-100"
destination="https://support.edx.org/hc/en-us/sections/115004169687-Participating-in-Course-Discussions"
showLaunchIcon={false}
>
{intl.formatMessage(messages.discussionHelpCourseParticipation)}
</Hyperlink>
<Hyperlink
target="_blank"
className="w-100"
destination="https://support.edx.org/hc/en-us/articles/360000035267-Entering-math-expressions-in-course-discussions"
showLaunchIcon={false}
>
{intl.formatMessage(messages.discussionHelpMathExpressions)}
</Hyperlink>
</div>
</div>
)}
</>
);
};

export default React.memo(PostHelpPanel);
2 changes: 2 additions & 0 deletions src/discussions/posts/post-editor/PostEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { AppContext } from '@edx/frontend-platform/react';

import { TinyMCEEditor } from '../../../components';
import FormikErrorFeedback from '../../../components/FormikErrorFeedback';
import PostHelpPanel from '../../../components/PostHelpPanel';
import PostPreviewPanel from '../../../components/PostPreviewPanel';
import useDispatchWithState from '../../../data/hooks';
import selectCourseCohorts from '../../cohorts/data/selectors';
Expand Down Expand Up @@ -409,6 +410,7 @@ const PostEditor = ({
onEditorChange={formikCompatibleHandler(handleChange, 'comment')}
onBlur={formikCompatibleHandler(handleBlur, 'comment')}
/>
<PostHelpPanel />
<FormikErrorFeedback name="comment" />
</div>
<PostPreviewPanel htmlNode={values.comment} isPost editExisting={editExisting} />
Expand Down
29 changes: 29 additions & 0 deletions src/discussions/posts/post-editor/PostEditor.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -368,5 +368,34 @@ describe('PostEditor', () => {
expect(container.querySelector('[data-testid="hide-preview-button"]')).not.toBeInTheDocument();
});
});

it('should show Help Panel', async () => {
await renderComponent(true, `/${courseId}/posts/${threadId}/edit`);

await act(async () => {
fireEvent.click(container.querySelector('[data-testid="help-button"]'));
});

await waitFor(() => {
expect(container.querySelector('[data-testid="hide-help-button"]')).toBeInTheDocument();
});
});

it('should hide Help Panel', async () => {
await renderComponent(true, `/${courseId}/posts/${threadId}/edit`);

await act(async () => {
fireEvent.click(container.querySelector('[data-testid="help-button"]'));
});

await act(async () => {
fireEvent.click(container.querySelector('[data-testid="hide-help-button"]'));
});

await waitFor(() => {
expect(container.querySelector('[data-testid="help-button"]')).toBeInTheDocument();
expect(container.querySelector('[data-testid="hide-help-button"]')).not.toBeInTheDocument();
});
});
});
});
30 changes: 30 additions & 0 deletions src/discussions/posts/post-editor/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,36 @@ const messages = defineMessages({
defaultMessage: 'Show preview',
description: 'show preview button text to allow user to see their post content.',
},
showHelpIcon: {
id: 'discussions.editor.posts.showHelp.icon',
defaultMessage: 'Show Help',
description: 'show help icon to allow user to see important documentation.',
},
discussionHelpHeader: {
id: 'discussions.editor.posts.discussionHelpHeader',
defaultMessage: 'Discussions help',
description: 'header text for post help section.',
},
discussionHelpDescription: {
id: 'discussions.editor.posts.discussionHelpDescription',
defaultMessage: 'Course discussions give you the opportunity to start conversations, ask questions, and interact with other learners. See the links below to learn more:',
description: 'description message for post help section.',
},
discussionHelpCourseParticipation: {
id: 'discussions.editor.posts.discussionHelpCourseParticipation',
defaultMessage: 'Participating in course discussions',
description: 'Documentation link title for participating in course discussions.',
},
discussionHelpMathExpressions: {
id: 'discussions.editor.posts.discussionHelpMathExpressions',
defaultMessage: 'Entering math expressions in course discussions',
description: 'Documentation link title for entering math expressions in course discussions.',
},
discussionHelpTooltip: {
id: 'discussions.editor.posts.discussionHelpTooltip',
defaultMessage: 'Learn more about MathJax & LaTeX',
description: 'Tooltip help message for documentation help.',
},
actionsAlt: {
id: 'discussions.actions.label',
defaultMessage: 'Actions menu',
Expand Down
18 changes: 15 additions & 3 deletions src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,15 @@ th, td {
white-space: nowrap;
}

.help-icon {
margin: -47px -3px 0px 0px;
}

.help-icon-size {
height: 16px !important;
width: 16px !important;
}

@media only screen and (max-width: 367px) {

.discussion-comments h5,
Expand All @@ -603,7 +612,8 @@ th, td {
.pgn__modal,
.pgn__form-label,
.dropdown-menu,
.tox-tbtn {
.tox-tbtn,
.tooltip {
font-size: 10px !important;
}

Expand Down Expand Up @@ -640,7 +650,8 @@ th, td {
.pgn__form-label,
.pgn__modal,
.dropdown-menu,
.tox-tbtn {
.tox-tbtn,
.tooltip {
font-size: 12px !important;
}

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

body,
#main {
#main,
.tooltip {
font-size: 14px;
}
}
Expand Down

0 comments on commit 3391e96

Please sign in to comment.