Skip to content

feat: add plugin slot in authn mfe#1298

Closed
hinakhadim wants to merge 1 commit intoopenedx:masterfrom
edly-io:hina/add_plugin_slot
Closed

feat: add plugin slot in authn mfe#1298
hinakhadim wants to merge 1 commit intoopenedx:masterfrom
edly-io:hina/add_plugin_slot

Conversation

@hinakhadim
Copy link
Copy Markdown
Contributor

Description

I want to include a React Component or JS file that can read cookies. But it can be done via PluginSlot which is not used in authn MFE. I have included PluginSlot in authn MFE which is wrapping <Routes>. I was unsure where to include it in authn MFE. I want to include where cookies can be read on any page/route. As all Routes Pages/Components doesn't have same layout, I have to include around `. Feel free to suggest any other way but we have to sure that if I load any page of Authn MFE, code containing "read cookies" should be executed.

How Has This Been Tested?

It was tested in dev by passing env.config.jsx. There is one problem I faced is that @openedx/frontend-plugin-framework was not installing due to deps conflict issue. So I had to install it by force. Because this package has support for react-error-boundary v4.x.x and @testing-library/react-hooks has support for error-boundary 3.x.x.

import React, { useEffect } from 'react';

import { getConfig } from '@edx/frontend-platform';
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
import Cookies from 'universal-cookie';

const AddDarkTheme = () => {
  useEffect(() => {
    const cookies = new Cookies();
    if (cookies.get(getConfig().THEME_COOKIE_NAME) === 'dark') {
      document.body.classList.add('indigo-dark-theme');
    }

    return () => cookies.removeChangeListener();
  }, []);
  return (<div />);
};

const themePluginSlot = {
  keepDefault: true,
  plugins: [
    {
      op: PLUGIN_OPERATIONS.Insert,
      widget: {
        id: 'read_theme_cookie',
        type: DIRECT_PLUGIN,
        priority: 1,
        RenderWidget: AddDarkTheme,
      },
    },
  ],
};

const config = {
  pluginSlots: {
    widget_routes_plugin_slot: themePluginSlot,
  },
};

export default config;

Merge Checklist

  • If your update includes visual changes, have they been reviewed by a designer? Send them a link to the Sandbox, if applicable.
  • Is there adequate test coverage for your changes?

Post-merge Checklist

  • Deploy the changes to prod after verifying on stage or ask @openedx/2u-vanguards to do it.
  • 🎉 🙌 Celebrate! Thanks for your contribution.

@hinakhadim hinakhadim requested a review from a team as a code owner August 12, 2024 15:24
@arbrandes arbrandes self-requested a review August 12, 2024 17:53
@arbrandes
Copy link
Copy Markdown
Contributor

@hinakhadim, we discussed this near the end of today's FWG meeting. What we'll probably do is leverage the loadExternalScripts functionality of frontend-platform to allow any MFE to inject any script they want via configuration, without the need for slots.

jignaciopm pushed a commit to eduNEXT/frontend-app-authn that referenced this pull request Jun 10, 2025
@arbrandes
Copy link
Copy Markdown
Contributor

Closing in favor of openedx/frontend-base#129

@arbrandes arbrandes closed this Jan 29, 2026
@github-project-automation github-project-automation Bot moved this from Todo to Done in Frontend Working Group Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants