feat: add CORE_PLUGINS hook and bundle the notifications tray#292
feat: add CORE_PLUGINS hook and bundle the notifications tray#292arbrandes merged 1 commit intooverhangio:mainfrom
Conversation
Introduces a CORE_PLUGINS filter for bundled frontend plugin packages, enabled by default and disableable symmetrically to MFE_APPS. Ports tutor-contrib-platform-notifications into tutor-mfe as the first core plugin. Co-Authored-By: Claude <noreply@anthropic.com>
| {%- if is_core_plugin_enabled("notifications") %} | ||
| const { NotificationsTray } = await import('@edx/frontend-plugin-notifications'); | ||
| {%- endif %} |
There was a problem hiding this comment.
can we add this to mfe-env-config-runtime-definitions patch again like it was in tutor-contrib-platform-notifications instead of filling in env.config.jsx?
There was a problem hiding this comment.
We could, but not cleanly: the patches tutor-mfe defines (such as mfe-env-config-runtime-definitions) are meant for other plugins to consume. That's what the templates are for: we put the stuff we own in there, and patches are for external use.
| {%- if is_core_plugin_enabled("notifications") %} | ||
| {%- for slot_name in [ | ||
| "org.openedx.frontend.layout.header_desktop_secondary_menu.v1", | ||
| "org.openedx.frontend.layout.header_learning_help.v1", | ||
| "org.openedx.frontend.layout.studio_header_search_button_slot.v1", | ||
| ] %} | ||
| addPlugins(config, '{{ slot_name }}', [ | ||
| { | ||
| op: PLUGIN_OPERATIONS.Insert, | ||
| widget: { | ||
| id: 'notification-drawer-widget', | ||
| priority: 10, | ||
| type: DIRECT_PLUGIN, | ||
| RenderWidget: NotificationsTray, | ||
| }, | ||
| }, | ||
| ]); | ||
| {%- endfor %} | ||
| {%- endif %} |
There was a problem hiding this comment.
can we also move this to plugin.py file under notifications section? As I was thinking we might end up adding plugin slots directly to env.config.jsx in future? Although its also fine if we don't do it.
There was a problem hiding this comment.
I actually tried, but it doesn't work well: we're consuming the hook (PLUGIN_SLOTS) we're defining ourselves, so there are timing/race conditions that result in the core plugin not being picked up here.
I know it looks funny, but defining this directly in the template is the right place.
There was a problem hiding this comment.
there are timing/race conditions that result in the core plugin not being picked up here.
I know it looks funny, but defining this directly in the template is the right place.
makes sense,
|
@arbrandes Do we need this PR? as most of these changes also exists in frontend-base PR e.g. |
|
@Faraz32123, we do need this PR. It looks similar to frontend-base, but frontend-plugin-notifications and frontend-app-notifications are two separate things: the first is for legacy MFEs (which this PR takes care of), the second for frontend-base apps. Once this PR merges, I'll have to rebase the frontend-base one so the two conditions are checked (is_core_plugin_enabled("notifications") and is_frontend_app_enabled("notifications"), for the backend stuff. (Yes, this looks pretty redundant, but until all MFEs are converted to apps, we're going to have to live with some duplication.) |
Description
Ports
tutor-contrib-platform-notificationsinto tutor-mfe so that enabling the plugin gives operators the notifications tray out of the box, with no extra plugin to install.To support this cleanly, it introduces a
CORE_PLUGINSfilter intutormfe.hooks: a registry of bundled frontend plugin packages that ship enabled by default. Operators can disable any core plugin by popping its entry from the filter, symmetrically to howMFE_APPSworks today. Notifications is the first (and currently only) core plugin.Testing
With this branch installed and tutor-mfe enabled, run
tutor config saveand inspect the rendered environment. In$(tutor config printroot)/env/plugins/mfe/build/mfe/Dockerfileeach MFE stage should contain aRUN ... npm install ... @edx/frontend-plugin-notifications@^2.0.3line just before themfe-dockerfile-post-npm-installpatch call. In$(tutor config printroot)/env/plugins/mfe/build/mfe/env.config.jsxthere should be aconst { NotificationsTray } = await import('@edx/frontend-plugin-notifications');line inside thetry {}block. In$(tutor config printroot)/env/apps/openedx/settings/lms/production.py, bothMFE_CONFIG["SHOW_EMAIL_CHANNEL"]andMFE_CONFIG["SHOW_PUSH_CHANNEL"]should be set, andNOTIFICATIONS_DEFAULT_FROM_EMAILshould be defined viaENV_TOKENS.To verify the disable path, create a file at
$(tutor plugins printroot)/disable_notifications.pycontaining:Then run
tutor plugins enable disable_notifications && tutor config save. The rendered Dockerfile,env.config.jsx, LMS production settings, andlms-envshould no longer referencefrontend-plugin-notifications,NotificationsTray,SHOW_EMAIL_CHANNEL, orNOTIFICATIONS_DEFAULT_FROM_EMAIL. Runningtutor plugins disable disable_notifications && tutor config savebrings them all back.LLM usage notice
Built with assistance from Claude.