feat: Add plugin slots for sidebars (#1752)

This commit is contained in:
Kshitij Sobti
2025-04-11 16:49:13 +05:30
committed by GitHub
parent 5df7adffec
commit 341a03c50b
12 changed files with 168 additions and 50 deletions

View File

@@ -0,0 +1,42 @@
# CourseAuthoringUnitSidebarSlot
### Slot ID: `course_authoring_unit_sidebar_slot`
### Plugin Props:
* `courseId` - String.
* `blockId` - String. The usage id of the current unit being viewed / edited.
* `unitTitle` - String. The name of the current unit being viewed / edited.
## Description
The slot wraps the sidebar that is displayed on the unit editor page. It can
be used to add additional sidebar components or modify the existing sidebar.
## Example
![Screenshot of the unit sidebar surrounded by border](./images/unit_sidebar_with_border.png)
The following example configuration surrounds the sidebar in a border as shown above.
```js
import { PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
const config = {
pluginSlots: {
course_authoring_unit_sidebar_slot: {
keepDefault: true,
plugins: [
{
op: PLUGIN_OPERATIONS.Wrap,
widgetId: 'default_contents',
wrapper: ({ component }) => (
<div style={{ border: 'thick dashed red' }}>{component}</div>
),
},
],
},
}
};
export default config;
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

View File

@@ -0,0 +1,37 @@
import { getConfig } from '@edx/frontend-platform';
import { PluginSlot } from '@openedx/frontend-plugin-framework/dist';
import TagsSidebarControls from '../../content-tags-drawer/tags-sidebar-controls';
import Sidebar from '../../course-unit/sidebar';
import LocationInfo from '../../course-unit/sidebar/LocationInfo';
import PublishControls from '../../course-unit/sidebar/PublishControls';
export const CourseAuthoringUnitSidebarSlot = (
{
blockId,
courseId,
unitTitle,
}: CourseAuthoringUnitSidebarSlotProps,
) => (
<PluginSlot
id="course_authoring_unit_sidebar_slot"
pluginProps={{ blockId, courseId, unitTitle }}
>
<Sidebar data-testid="course-unit-sidebar">
<PublishControls blockId={blockId} />
</Sidebar>
{getConfig().ENABLE_TAGGING_TAXONOMY_PAGES === 'true' && (
<Sidebar className="tags-sidebar">
<TagsSidebarControls />
</Sidebar>
)}
<Sidebar data-testid="course-unit-location-sidebar">
<LocationInfo />
</Sidebar>
</PluginSlot>
);
interface CourseAuthoringUnitSidebarSlotProps {
blockId: string;
courseId: string;
unitTitle: string;
}