Skip to content

Commit

Permalink
feat: wrap existing sidebars in frontend-plugin-framework `PluginSl…
Browse files Browse the repository at this point in the history
…ot`s
  • Loading branch information
brian-smith-tcril committed Dec 3, 2024
1 parent 642031b commit 810b811
Show file tree
Hide file tree
Showing 20 changed files with 321 additions and 15 deletions.
9 changes: 4 additions & 5 deletions src/courseware/course/Course.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ import { breakpoints, useWindowSize } from '@openedx/paragon';
import { AlertList } from '@src/generic/user-messages';
import { useModel } from '@src/generic/model-store';
import { getCoursewareOutlineSidebarSettings } from '../data/selectors';
import { Trigger as CourseOutlineTrigger } from './sidebar/sidebars/course-outline';
import Chat from './chat/Chat';
import SidebarProvider from './sidebar/SidebarContextProvider';
import SidebarTriggers from './sidebar/SidebarTriggers';
import NewSidebarProvider from './new-sidebar/SidebarContextProvider';
import NewSidebarTriggers from './new-sidebar/SidebarTriggers';
import { NotificationsDiscussionsSidebarTriggerSlot } from '../../plugin-slots/NotificationsDiscussionsSidebarTriggerSlot';
import { CelebrationModal, shouldCelebrateOnSectionLoad, WeeklyGoalCelebrationModal } from './celebration';
import CourseBreadcrumbs from './CourseBreadcrumbs';
import ContentTools from './content-tools';
import Sequence from './sequence';
import CourseOutlineMobileSidebarTriggerSlot from '../../plugin-slots/CourseOutlineMobileSidebarTriggerSlot';

const Course = ({
courseId,
Expand Down Expand Up @@ -109,8 +108,8 @@ const Course = ({
</>
)}
<div className="w-100 d-flex align-items-center">
<CourseOutlineTrigger isMobileView />
{isNewDiscussionSidebarViewEnabled ? <NewSidebarTriggers /> : <SidebarTriggers /> }
<CourseOutlineMobileSidebarTriggerSlot />
<NotificationsDiscussionsSidebarTriggerSlot courseId={courseId} />
</div>
</div>

Expand Down
16 changes: 6 additions & 10 deletions src/courseware/course/sequence/Sequence.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@ import SequenceContainerSlot from '../../../plugin-slots/SequenceContainerSlot';

import { getCoursewareOutlineSidebarSettings } from '../../data/selectors';
import CourseLicense from '../course-license';
import Sidebar from '../sidebar/Sidebar';
import NewSidebar from '../new-sidebar/Sidebar';
import {
Trigger as CourseOutlineTrigger,
Sidebar as CourseOutlineTray,
} from '../sidebar/sidebars/course-outline';
import NotificationsDiscussionsSidebarSlot from '../../../plugin-slots/NotificationsDiscussionsSidebarSlot';
import messages from './messages';
import HiddenAfterDue from './hidden-after-due';
import { SequenceNavigation, UnitNavigation } from './sequence-navigation';
import SequenceContent from './SequenceContent';
import CourseOutlineSidebarSlot from '../../../plugin-slots/CourseOutlineSidebarSlot';
import CourseOutlineSidebarTriggerSlot from '../../../plugin-slots/CourseOutlineSidebarTriggerSlot';

const Sequence = ({
unitId,
Expand All @@ -46,7 +43,6 @@ const Sequence = ({
const {
isStaff,
originalUserIsStaff,
isNewDiscussionSidebarViewEnabled,
} = useModel('courseHomeMeta', courseId);
const sequence = useModel('sequences', sequenceId);
const unit = useModel('units', unitId);
Expand Down Expand Up @@ -166,8 +162,8 @@ const Sequence = ({
const defaultContent = (
<>
<div className="sequence-container d-inline-flex flex-row w-100">
<CourseOutlineTrigger />
<CourseOutlineTray />
<CourseOutlineSidebarTriggerSlot />
<CourseOutlineSidebarSlot />
<div className="sequence w-100">
{!isEnabledOutlineSidebar && (
<div className="sequence-navigation-container">
Expand Down Expand Up @@ -209,7 +205,7 @@ const Sequence = ({
{unitHasLoaded && renderUnitNavigation(false)}
</div>
</div>
{isNewDiscussionSidebarViewEnabled ? <NewSidebar /> : <Sidebar />}
<NotificationsDiscussionsSidebarSlot courseId={courseId} />
</div>
<SequenceContainerSlot courseId={courseId} unitId={unitId} />
</>
Expand Down
39 changes: 39 additions & 0 deletions src/plugin-slots/CourseOutlineMobileSidebarTriggerSlot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Course Outline Sidebar Trigger Slot

### Slot ID: `course_outline_mobile_sidebar_trigger_slot`

## Description

This slot is used to replace/modify/hide the course outline sidebar mobile trigger.

## Example

![📌 in trigger slot](./screenshot.png)

The following `env.config.jsx` will replace the course outline sidebar mobile trigger entirely.

```js
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';

const config = {
pluginSlots: {
course_outline_mobile_sidebar_trigger_slot: {
keepDefault: false,
plugins: [
{
op: PLUGIN_OPERATIONS.Insert,
widget: {
id: 'custom_sidebar_trigger_component',
type: DIRECT_PLUGIN,
RenderWidget: () => (
<h1 className="d-xl-none">📌</h1>
),
},
},
]
}
},
}

export default config;
```
16 changes: 16 additions & 0 deletions src/plugin-slots/CourseOutlineMobileSidebarTriggerSlot/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { PluginSlot } from '@openedx/frontend-plugin-framework';

import CourseOutlineTrigger from '../../courseware/course/sidebar/sidebars/course-outline/CourseOutlineTrigger';

const CourseOutlineMobileSidebarTriggerSlot = () => (
<PluginSlot
id="course_outline_mobile_sidebar_trigger_slot"
slotOptions={{
mergeProps: true,
}}
>
<CourseOutlineTrigger isMobileView />
</PluginSlot>
);

export default CourseOutlineMobileSidebarTriggerSlot;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions src/plugin-slots/CourseOutlineSidebarSlot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Course Outline Sidebar Slot

### Slot ID: `course_outline_sidebar_slot`

## Description

This slot is used to replace/modify/hide the course outline sidebar.

## Example

![📊 in sidebar slot](./screenshot.png)

The following `env.config.jsx` will replace the course outline sidebar entirely.

```js
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';

const config = {
pluginSlots: {
course_outline_sidebar_slot: {
keepDefault: false,
plugins: [
{
op: PLUGIN_OPERATIONS.Insert,
widget: {
id: 'custom_sidebar_component',
type: DIRECT_PLUGIN,
RenderWidget: () => (
<h1>📊</h1>
),
},
},
]
}
},
}

export default config;
```
16 changes: 16 additions & 0 deletions src/plugin-slots/CourseOutlineSidebarSlot/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { PluginSlot } from '@openedx/frontend-plugin-framework';

import CourseOutlineTray from '../../courseware/course/sidebar/sidebars/course-outline/CourseOutlineTray';

const CourseOutlineSidebarSlot = () => (
<PluginSlot
id="course_outline_sidebar_slot"
slotOptions={{
mergeProps: true,
}}
>
<CourseOutlineTray />
</PluginSlot>
);

export default CourseOutlineSidebarSlot;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions src/plugin-slots/CourseOutlineSidebarTriggerSlot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Course Outline Sidebar Trigger Slot

### Slot ID: `course_outline_sidebar_trigger_slot`

## Description

This slot is used to replace/modify/hide the course outline sidebar trigger.

## Example

![📌 in trigger slot with sidebar closed](./screenshot_1.png)
![📌 in trigger slot with sidebar open](./screenshot_2.png)

The following `env.config.jsx` will replace the course outline sidebar trigger entirely.

```js
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';

const config = {
pluginSlots: {
course_outline_sidebar_trigger_slot: {
keepDefault: false,
plugins: [
{
op: PLUGIN_OPERATIONS.Insert,
widget: {
id: 'custom_sidebar_trigger_component',
type: DIRECT_PLUGIN,
RenderWidget: () => (
<h1 className="d-none d-xl-block">📌</h1>
),
},
},
]
}
},
}

export default config;
```
16 changes: 16 additions & 0 deletions src/plugin-slots/CourseOutlineSidebarTriggerSlot/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { PluginSlot } from '@openedx/frontend-plugin-framework';

import CourseOutlineTrigger from '../../courseware/course/sidebar/sidebars/course-outline/CourseOutlineTrigger';

const CourseOutlineSidebarTriggerSlot = () => (
<PluginSlot
id="course_outline_sidebar_trigger_slot"
slotOptions={{
mergeProps: true,
}}
>
<CourseOutlineTrigger />
</PluginSlot>
);

export default CourseOutlineSidebarTriggerSlot;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions src/plugin-slots/NotificationsDiscussionsSidebarSlot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Notifications Discussions Sidebar Slot

### Slot ID: `notifications_discussions_sidebar_slot`

## Description

This slot is used to replace/modify/hide the notifications discussions sidebar.

## Example

![📊 in sidebar slot](./screenshot.png)

The following `env.config.jsx` will replace the notifications discussions sidebar.

```js
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';

const config = {
pluginSlots: {
notifications_discussions_sidebar_slot: {
keepDefault: false,
plugins: [
{
op: PLUGIN_OPERATIONS.Insert,
widget: {
id: 'custom_sidebar_component',
type: DIRECT_PLUGIN,
RenderWidget: () => (
<h1>📊</h1>
),
},
},
]
}
},
}

export default config;
```
30 changes: 30 additions & 0 deletions src/plugin-slots/NotificationsDiscussionsSidebarSlot/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import PropTypes from 'prop-types';

import { PluginSlot } from '@openedx/frontend-plugin-framework';
import { useModel } from '@src/generic/model-store';

import Sidebar from '../../courseware/course/sidebar/Sidebar';
import NewSidebar from '../../courseware/course/new-sidebar/Sidebar';

const NotificationsDiscussionsSidebarSlot = ({ courseId }) => {
const {
isNewDiscussionSidebarViewEnabled,
} = useModel('courseHomeMeta', courseId);

return (
<PluginSlot
id="notifications_discussions_sidebar_slot"
slotOptions={{
mergeProps: true,
}}
>
{isNewDiscussionSidebarViewEnabled ? <NewSidebar /> : <Sidebar />}
</PluginSlot>
);
};

NotificationsDiscussionsSidebarSlot.propTypes = {
courseId: PropTypes.string.isRequired,
};

export default NotificationsDiscussionsSidebarSlot;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Notifications Discussions Sidebar Trigger Slot

### Slot ID: `notifications_discussions_sidebar_trigger_slot`

## Description

This slot is used to replace/modify/hide the notifications discussions sidebar trigger.

## Example

### Default content
![Trigger slot with default content](./screenshot_default.png)

### Replaced with custom component
![📬 in trigger slot](./screenshot_custom.png)

The following `env.config.jsx` will replace the notifications discussions sidebar trigger.

```js
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';

const config = {
pluginSlots: {
notifications_discussions_sidebar_trigger_slot: {
keepDefault: false,
plugins: [
{
op: PLUGIN_OPERATIONS.Insert,
widget: {
id: 'custom_sidebar_trigger_component',
type: DIRECT_PLUGIN,
RenderWidget: () => (
<h1 className='ml-auto'>📬</h1>
),
},
},
]
}
},
}

export default config;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';

import { PluginSlot } from '@openedx/frontend-plugin-framework';
import { useModel } from '@src/generic/model-store';

import SidebarTriggers from '../../courseware/course/sidebar/SidebarTriggers';
import NewSidebarTriggers from '../../courseware/course/new-sidebar/SidebarTriggers';

interface Props {
courseId: string;
}

export const NotificationsDiscussionsSidebarTriggerSlot : React.FC<Props> = ({ courseId }) => {
const {
isNewDiscussionSidebarViewEnabled,
} = useModel('courseHomeMeta', courseId);

return (
<PluginSlot
id="notifications_discussions_sidebar_trigger_slot"
slotOptions={{
mergeProps: true,
}}
>
{isNewDiscussionSidebarViewEnabled ? <NewSidebarTriggers /> : <SidebarTriggers /> }
</PluginSlot>
);
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 810b811

Please sign in to comment.