Skip to content

feat: Add slot for whole application #1799

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
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
APP_INIT_ERROR, APP_READY, subscribe, initialize, mergeConfig, getConfig, getPath,
} from '@edx/frontend-platform';
import { AppProvider, ErrorPage } from '@edx/frontend-platform/react';
import { AuthoringAppSlot } from 'CourseAuthoring/plugin-slots/AuthoringAppSlot';
import React, { StrictMode, useEffect } from 'react';
import { createRoot } from 'react-dom/client';
import {
Expand Down Expand Up @@ -97,12 +98,14 @@ const App = () => {

return (
<AppProvider store={initializeStore()} wrapWithRouter={false}>
<ToastProvider>
<QueryClientProvider client={queryClient}>
<Head />
<RouterProvider router={router} />
</QueryClientProvider>
</ToastProvider>
<AuthoringAppSlot>
<ToastProvider>
<QueryClientProvider client={queryClient}>
<Head />
<RouterProvider router={router} />
</QueryClientProvider>
</ToastProvider>
</AuthoringAppSlot>
</AppProvider>
);
};
Expand Down
44 changes: 44 additions & 0 deletions src/plugin-slots/AuthoringAppSlot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# AuthoringAppSlot

### Slot ID: `authoring_app_slot`

### Plugin Props:

NONE

## Description

The slot wraps the entire application. It can be used to add content before or
after the application (such as cookie banners) or to wrap the entire
application in a component. One possible use case of that is to wrap the entire
application in a context manager that would allow communication between
different slots injected on the page.

## Example

![Screenshot of the entire app surrounded by border](./images/app_wrapped_in_border.png)

The following example configuration wraps the entire app in a dashed border as
shown above.

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

const config = {
pluginSlots: {
authoring_app_slot: {
keepDefault: true,
plugins: [
{
op: PLUGIN_OPERATIONS.Wrap,
widgetId: 'default_contents',
wrapper: ({ component }) => (
<div style={{ border: 'thick dashed red' }}>{component}</div>
),
},
],
},
}
};
export default config;
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions src/plugin-slots/AuthoringAppSlot/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { PluginSlot } from '@openedx/frontend-plugin-framework';

Check warning on line 1 in src/plugin-slots/AuthoringAppSlot/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugin-slots/AuthoringAppSlot/index.tsx#L1

Added line #L1 was not covered by tests

export const AuthoringAppSlot = ({ children }:AuthoringAppSlotProps) => (
<PluginSlot id="authoring_app_slot">

Check warning on line 4 in src/plugin-slots/AuthoringAppSlot/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugin-slots/AuthoringAppSlot/index.tsx#L3-L4

Added lines #L3 - L4 were not covered by tests
{children}
</PluginSlot>
);

interface AuthoringAppSlotProps {
children: React.ReactNode;
}