-
Notifications
You must be signed in to change notification settings - Fork 243
feat: add course end dashboard plugin slots #1658
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
Open
jansenk
wants to merge
7
commits into
master
Choose a base branch
from
jkantor/course-end-plugins
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b7d3c40
refactor: move courserecommendationsslot into new folder
jansenk 082c8be
fixup! refactor: move courserecommendationsslot into new folder
jansenk b616cab
feat: add plugin slot for course exit view courses button
jansenk 4a45604
feat: add dashboard footnote plugin slot
jansenk 8a62a38
refactor: unify imports
jansenk a4a1c83
refactor: simplify footnot link
jansenk c74ab08
refactor: simplify course exit pliugin slot
jansenk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,28 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { getAuthenticatedUser } from '@edx/frontend-platform/auth'; | ||
import { | ||
FormattedMessage, injectIntl, intlShape, | ||
} from '@edx/frontend-platform/i18n'; | ||
import { Hyperlink } from '@openedx/paragon'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
import { faCalendarAlt } from '@fortawesome/free-regular-svg-icons'; | ||
import { getConfig } from '@edx/frontend-platform'; | ||
|
||
import { useModel } from '../../../generic/model-store'; | ||
|
||
import { DashboardFootnoteLinkPluginSlot } from '../../../plugin-slots/CourseExitPluginSlots'; | ||
import Footnote from './Footnote'; | ||
import messages from './messages'; | ||
import { logClick } from './utils'; | ||
|
||
const DashboardFootnote = ({ intl, variant }) => { | ||
const { courseId } = useSelector(state => state.courseware); | ||
const { org } = useModel('courseHomeMeta', courseId); | ||
const { administrator } = getAuthenticatedUser(); | ||
|
||
const dashboardLink = ( | ||
<Hyperlink | ||
style={{ textDecoration: 'underline' }} | ||
destination={`${getConfig().LMS_BASE_URL}/dashboard`} | ||
className="text-reset" | ||
onClick={() => logClick(org, courseId, administrator, 'dashboard_footnote', { variant })} | ||
> | ||
{intl.formatMessage(messages.dashboardLink)} | ||
</Hyperlink> | ||
); | ||
const DashboardFootnote = ({ variant }) => { | ||
const intl = useIntl(); | ||
const dashboardLink = (<DashboardFootnoteLinkPluginSlot variant={variant} />); | ||
|
||
return ( | ||
<Footnote | ||
icon={faCalendarAlt} | ||
text={( | ||
<FormattedMessage | ||
id="courseCelebration.dashboardInfo" // for historical reasons | ||
defaultMessage="You can access this course and its materials on your {dashboardLink}." | ||
description="Text that precedes link to learner's dashboard" | ||
values={{ dashboardLink }} | ||
/> | ||
)} | ||
text={intl.formatMessage(messages.dashboardInfo, { dashboardLink })} | ||
/> | ||
); | ||
}; | ||
|
||
DashboardFootnote.propTypes = { | ||
intl: intlShape.isRequired, | ||
content: PropTypes.shape({ | ||
dashboardFootnoteUrl: PropTypes.string, | ||
}), | ||
variant: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default injectIntl(DashboardFootnote); | ||
export default DashboardFootnote; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/plugin-slots/CourseExitPluginSlots/CourseExitViewCoursesPluginSlot/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Course Exit "View Courses" Button Plugin Slot | ||
|
||
### Slot ID: `course_exit_view_courses_slot` | ||
### Props: | ||
* `href` | ||
|
||
## Description | ||
|
||
This slot is used for modifying "View Courses" button in the course exit screen | ||
|
||
## Example | ||
|
||
The following `env.config.jsx` will make the link link to `example.com` | ||
|
||
```js | ||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework'; | ||
|
||
const config = { | ||
pluginSlots: { | ||
course_exit_view_courses_slot: { | ||
keepDefault: true, | ||
plugins: [ | ||
{ | ||
op: PLUGIN_OPERATIONS.Modify, | ||
widgetId: 'default_contents', | ||
fn: (widget) => { | ||
widget.content.href = 'http://www.example.com'; | ||
return widget; | ||
} | ||
}, | ||
] | ||
}, | ||
}, | ||
} | ||
|
||
export default config; | ||
``` |
39 changes: 39 additions & 0 deletions
39
src/plugin-slots/CourseExitPluginSlots/CourseExitViewCoursesPluginSlot/index.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Button } from '@openedx/paragon'; | ||
import PropTypes from 'prop-types'; | ||
import { getConfig } from '@edx/frontend-platform'; | ||
import { PluginSlot } from '@openedx/frontend-plugin-framework'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
import messages from '../../../courseware/course/course-exit/messages'; | ||
|
||
const ViewCoursesLink = ({ content }) => { | ||
const intl = useIntl(); | ||
return ( | ||
<div className="row w-100 mt-2 mb-4 justify-content-end"> | ||
<Button | ||
variant="outline-primary" | ||
href={content.href} | ||
> | ||
{intl.formatMessage(messages.viewCoursesButton)} | ||
</Button> | ||
</div> | ||
); | ||
}; | ||
|
||
ViewCoursesLink.propTypes = { | ||
content: PropTypes.shape({ | ||
href: PropTypes.string.isRequired, | ||
}).isRequired, | ||
}; | ||
|
||
const CourseExitViewCoursesPluginSlot = () => { | ||
const href = `${getConfig().LMS_BASE_URL}/dashboard`; | ||
return ( | ||
<PluginSlot id="course_exit_view_courses_slot"> | ||
<ViewCoursesLink content={{ href }} /> | ||
</PluginSlot> | ||
); | ||
}; | ||
|
||
CourseExitViewCoursesPluginSlot.propTypes = {}; | ||
|
||
export default CourseExitViewCoursesPluginSlot; | ||
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...slots/CourseRecommendationsSlot/index.jsx → ...Slots/CourseRecommendationsSlot/index.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
40 changes: 40 additions & 0 deletions
40
src/plugin-slots/CourseExitPluginSlots/DashboardFootnoteLinkPluginSlot/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Course Exit Dashboard Footnote Link Plugin Slot | ||
|
||
### Slot ID: `course_exit_dashboard_footnote_link_slot` | ||
### Props: | ||
* `variant` | ||
* `content: { destination }` | ||
|
||
## Description | ||
|
||
This slot is used for modifying the link to the learner dashboard in the footnote on the course exit page | ||
|
||
## Example | ||
|
||
The following `env.config.jsx` will change the link to point to `example.com` | ||
|
||
 | ||
|
||
```js | ||
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework'; | ||
|
||
const config = { | ||
pluginSlots: { | ||
course_exit_dashboard_footnote_link_slot: { | ||
keepDefault: true, | ||
plugins: [ | ||
{ | ||
op: PLUGIN_OPERATIONS.Modify, | ||
widgetId: 'default_contents', | ||
fn: (widget) => { | ||
widget.content.destination = 'http://www.example.com'; | ||
return widget; | ||
} | ||
}, | ||
] | ||
}, | ||
}, | ||
} | ||
|
||
export default config; | ||
``` |
50 changes: 50 additions & 0 deletions
50
src/plugin-slots/CourseExitPluginSlots/DashboardFootnoteLinkPluginSlot/index.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import PropTypes from 'prop-types'; | ||
import { Hyperlink } from '@openedx/paragon'; | ||
import { getConfig } from '@edx/frontend-platform'; | ||
import { PluginSlot } from '@openedx/frontend-plugin-framework'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
import { useSelector } from 'react-redux'; | ||
import { getAuthenticatedUser } from '@edx/frontend-platform/auth'; | ||
import messages from '../../../courseware/course/course-exit/messages'; | ||
import { logClick } from '../../../courseware/course/course-exit/utils'; | ||
import { useModel } from '../../../generic/model-store'; | ||
|
||
const DashboardFootnoteLink = ({ variant, content }) => { | ||
const intl = useIntl(); | ||
const { courseId } = useSelector(state => state.courseware); | ||
const { org } = useModel('courseHomeMeta', courseId); | ||
const { administrator } = getAuthenticatedUser(); | ||
const { destination } = content; | ||
return ( | ||
<Hyperlink | ||
style={{ textDecoration: 'underline' }} | ||
destination={destination} | ||
className="text-reset" | ||
onClick={() => logClick(org, courseId, administrator, 'dashboard_footnote', { variant })} | ||
> | ||
{intl.formatMessage(messages.dashboardLink)} | ||
</Hyperlink> | ||
); | ||
}; | ||
|
||
DashboardFootnoteLink.propTypes = { | ||
variant: PropTypes.string.isRequired, | ||
content: PropTypes.shape({ | ||
destination: PropTypes.string.isRequired, | ||
}).isRequired, | ||
}; | ||
|
||
const DashboardFootnoteLinkPluginSlot = ({ variant }) => { | ||
const destination = `${getConfig().LMS_BASE_URL}/dashboard`; | ||
return ( | ||
<PluginSlot id="course_exit_dashboard_footnote_link_slot"> | ||
<DashboardFootnoteLink variant={variant} content={{ destination }} /> | ||
</PluginSlot> | ||
); | ||
}; | ||
|
||
DashboardFootnoteLinkPluginSlot.propTypes = { | ||
variant: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default DashboardFootnoteLinkPluginSlot; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import DashboardFootnoteLinkPluginSlot from './DashboardFootnoteLinkPluginSlot'; | ||
import CourseRecommendationsSlot from './CourseRecommendationsSlot'; | ||
import CourseExitViewCoursesPluginSlot from './CourseExitViewCoursesPluginSlot'; | ||
|
||
export { | ||
DashboardFootnoteLinkPluginSlot, | ||
CourseRecommendationsSlot, | ||
CourseExitViewCoursesPluginSlot, | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't need to block this PR if you didn't know, but: whenever creating new files in this repo or any MFE repo, please:
.tsx
instead of.jsx
propTypes
- propTypes have been deprecated for 8 years!You also don't need to use default exports anymore, but you can if you want to.