Skip to content

Commit

Permalink
feat: add unit title to pluginslot (#1383)
Browse files Browse the repository at this point in the history
  • Loading branch information
hajorg authored May 21, 2024
1 parent df36123 commit e577efb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ exports[`Unit component output snapshot: not bookmarked, do not show content 1`]
<UnitTitleSlot
courseId="test-course-id"
unitId="test-props-id"
unitTitle="unit-title"
/>
</div>
<h2
Expand Down
2 changes: 1 addition & 1 deletion src/courseware/course/sequence/Unit/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const Unit = ({
<div className="unit">
<div className="mb-0">
<h3 className="h3">{unit.title}</h3>
<UnitTitleSlot courseId={courseId} unitId={id} />
<UnitTitleSlot courseId={courseId} unitId={id} unitTitle={unit.title} />
</div>
<h2 className="sr-only">{formatMessage(messages.headerPlaceholder)}</h2>
<BookmarkButton
Expand Down
6 changes: 4 additions & 2 deletions src/plugin-slots/UnitTitleSlot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
### Props:
* `courseId`
* `unitId`
* `unitTitle`

## Description

This slot is used for adding content after the Unit title.

## Example

The following `env.config.jsx` will render the `course_id` and `unit_id` of the course as `<p>` elements.
The following `env.config.jsx` will render the `course_id`, `unit_id` and `unitTitle` of the course as `<p>` elements.

![Screenshot of Content added after the Unit Title](./images/post_unit_title.png)

Expand All @@ -28,10 +29,11 @@ const config = {
widget: {
id: 'custom_unit_title_content',
type: DIRECT_PLUGIN,
RenderWidget: ({courseId, unitId}) => (
RenderWidget: ({courseId, unitId, unitTitle}) => (
<>
<p>📚: {courseId}</p>
<p>📙: {unitId}</p>
<p>📙: {unitTitle}</p>
</>
),
},
Expand Down
4 changes: 3 additions & 1 deletion src/plugin-slots/UnitTitleSlot/index.jsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import PropTypes from 'prop-types';
import { PluginSlot } from '@openedx/frontend-plugin-framework';

const UnitTitleSlot = ({ courseId, unitId }) => (
const UnitTitleSlot = ({ courseId, unitId, unitTitle }) => (
<PluginSlot
id="unit_title_slot"
pluginProps={{
courseId,
unitId,
unitTitle,
}}
/>
);

UnitTitleSlot.propTypes = {
courseId: PropTypes.string.isRequired,
unitId: PropTypes.string.isRequired,
unitTitle: PropTypes.string.isRequired,
};

export default UnitTitleSlot;

0 comments on commit e577efb

Please sign in to comment.