Skip to content

feat: add slot to extend the profile fields #1211

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 9 commits into
base: master
Choose a base branch
from

Conversation

bra-i-am
Copy link

@bra-i-am bra-i-am commented May 19, 2025

Description

This PR creates a slot ExtendedProfileFieldsSlot and inserts it into ProfilePage.jsx. The main goal of this change is to allow the extension of the profile fields.

This use case is required by NAU and can be validated by @igobranco

Screenshots

Before After
default_fields custom_fields

How Has This Been Tested?

In case you want to test my implementation, I'll leave you a little guide down below:

  1. Have a tutor environment (I used Tutor Main)

  2. You have to mount this MFE on the branch of this PR so you can use the slot:
    a. Add this script to the following tutor plugin to override the branch of Profle MFE

    from tutormfe.hooks import MFE_APPS
    
    @MFE_APPS.add()
    def _add_my_mfe(mfes):
    mfes["profile"] = {
         "repository": "https://github.com/edunext/frontend-app-profile.git",
         "port": 1995,
         "version": "bc/add-extra-fields-slot",
     }

    b. Another way we can do this in the queue is by tutor mounts add the MFE in our Tutor local env. To do this, we must:

    • Install the @edunext/frontend-component-extended-fields@latest package in our MFE Profile.

    • Create an env.config.jsx file in the root of the MFE with the following configuration:

      import { PLUGIN_OPERATIONS, DIRECT_PLUGIN } from '@openedx/frontend-plugin-framework';
      import { ExtendedProfileFields } from '@edunext/frontend-component-extended-fields';
      
      // Load environment variables from .env file
      const config = {
        ...process.env,
        pluginSlots: {
          extended_profile_fields_slot: {
            plugins: [
              {
                op: PLUGIN_OPERATIONS.Insert,
                widget: {
                  id: 'extended_profile_fields',
                  type: DIRECT_PLUGIN,
              RenderWidget: ExtendedProfileFields,
                },
              },
            ],
          },
        },
      };
      
      export default config;
  3. Create a tutor plugin and enable it:

    from tutormfe.hooks import PLUGIN_SLOTS
    from tutor import hooks
    
    hooks.Filters.ENV_PATCHES.add_item(
        (
            "mfe-dockerfile-post-npm-install",
            """
    # npm package
    RUN npm install '@edunext/frontend-component-extended-fields@latest'
    """,
        )
    )
    
    hooks.Filters.ENV_PATCHES.add_item(
        (
            "mfe-env-config-buildtime-imports",
            """
    import { ExtendedProfileFields } from '@edunext/frontend-component-extended-fields';
    """,
        )
    )
    
    PLUGIN_SLOTS.add_items(
        [
            (
                "profile",
                "extended_profile_fields_slot",
                """
            {
              op: PLUGIN_OPERATIONS.Insert,
              widget: {
                id: 'extended_profile_fields',
    		    type: DIRECT_PLUGIN,
    		    RenderWidget: ExtendedProfileFields,
              },
            }""",
            ),
        ]
    )
  4. Run tutor images build mfe --no-cache

  5. Add this in the config.yml to add the custom form:

    OPENEDX_EXTRA_PIP_REQUIREMENTS:
    - git+https://github.com/bra-i-am/custom-form-app.git
  6. Add the following env variables

    # lms.env.yml
    ADDL_INSTALLED_APPS:
      - "custom_reg_form"
    ENABLE_COMBINED_LOGIN_REGISTRATION: true
    REGISTRATION_EXTENSION_FORM: "custom_reg_form.forms.ExtraInfoForm"
    
    # cms.env.yml
    ENABLE_COMBINED_LOGIN_REGISTRATION: true
  7. Run tutor images build openedx --no-cache

  8. Run tutor local start

  9. Add the following settings to the Site Configurations > local.openedx.io:

    {
        "ENABLE_PROFILE_MICROFRONTEND": "true",
        "ENABLE_DYNAMIC_REGISTRATION_FIELDS": "true",
        "MFE_CONFIG": {
            "ENABLE_DYNAMIC_REGISTRATION_FIELDS": "true"
        },
        "REGISTRATION_EXTRA_FIELDS": {
            "employment_situation": "required",
            "data_authorization": "required",
            "allow_newsletter": "required",
            "terms_of_service": "hidden",
            "honor_code": "hidden",
            "full_name": "required",
            "bio": "required",
            "wants_newsletter": "required",
            "favorite_language": "required",
            "password_hint": "required",
            "terms_accepted": "required"
        },
        "extended_profile_fields": [
            "data_authorization",
            "full_name",
            "bio",
            "wants_newsletter",
            "favorite_language",
            "password_hint",
            "terms_accepted"
        ]
    }
  10. Run tutor local restart to update the settings

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label May 19, 2025
@openedx-webhooks
Copy link

openedx-webhooks commented May 19, 2025

Thanks for the pull request, @bra-i-am!

This repository is currently maintained by @openedx/2u-infinity.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.


Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

Copy link

codecov bot commented May 22, 2025

Codecov Report

Attention: Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.

Project coverage is 66.93%. Comparing base (37feffc) to head (4900dd4).
Report is 5 commits behind head on master.

Files with missing lines Patch % Lines
...c/plugin-slots/ExtendedProfileFieldsSlot/index.jsx 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1211      +/-   ##
==========================================
+ Coverage   66.82%   66.93%   +0.11%     
==========================================
  Files          51       52       +1     
  Lines         856      862       +6     
  Branches      176      179       +3     
==========================================
+ Hits          572      577       +5     
- Misses        273      274       +1     
  Partials       11       11              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bra-i-am bra-i-am changed the title Bc/add extra fields slot feat: add slot to extend the profile fields May 23, 2025
Copy link

@jignaciopm jignaciopm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was testing this PluginSlot, thanks to README It was easy. I like this kind of contributions.We need to expand our range of plugin slots and it is good to have this example base

Copy link

@Asespinel Asespinel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything in the PR looks good to me overall. One suggestion: it might be better to update the plugin so that it only installs the form for the profile/account MFE. This would help keep things more scoped and prevent unnecessary installations. couldn't replicate the changes locally due to some environment configs not loading, but the logic looks solid.

I tested with this plugin and I could build the MFE images with no problems:

from tutormfe.hooks import PLUGIN_SLOTS
from tutor import hooks

hooks.Filters.ENV_PATCHES.add_item(
    (
        "mfe-dockerfile-post-npm-install-profile",
        """
# npm package
RUN npm install '@edunext/frontend-component-extended-fields@latest' --force
""",
    )
)

hooks.Filters.ENV_PATCHES.add_item(
    (
        "mfe-dockerfile-post-npm-install-account",
        """
# npm package
RUN npm install '@edunext/frontend-component-extended-fields@latest' --force
""",
    )
)

hooks.Filters.ENV_PATCHES.add_item(
    (
        "mfe-env-config-buildtime-imports-profile",
        """
import { ExtendedProfileFields } from '@edunext/frontend-component-extended-fields';
""",
    )
)

hooks.Filters.ENV_PATCHES.add_item(
    (
        "mfe-env-config-buildtime-imports-account",
        """
import { ExtendedProfileFields } from '@edunext/frontend-component-extended-fields';
""",
    )
)

PLUGIN_SLOTS.add_items(
    [
        (
            "profile",
            "extended_profile_fields_slot",
            """
        {
          op: PLUGIN_OPERATIONS.Insert,
          widget: {
            id: 'extended_profile_fields',
		    type: DIRECT_PLUGIN,
		    RenderWidget: ExtendedProfileFields,
          },
        }""",
        ),
    ]
)

@jignaciopm
Copy link

jignaciopm commented Jun 4, 2025

I want to take this opportunity to mention a few things in the steps to test this development:

There is no mention of the use of this branch in our Local Tutor

Add the next script to tutor plugin to override the branch of Profle MFE

from tutormfe.hooks import MFE_APPS

@MFE_APPS.add()
def _add_my_mfe(mfes):
    mfes["profile"] = {
        "repository": "https://github.com/edunext/frontend-app-profile.git",
        "port": 1995,
        "version": "bc/add-extra-fields-slot",
    }

Another way we can do this in the queue is by using mount in our Local Tutor. To do this, we must:

  1. Install the @edunext/frontend-component-extended-fields@latest package in our MFE Profile.
  2. Create the env.config.jsx file in the root of the MFE with the following configuration:
import { PLUGIN_OPERATIONS, DIRECT_PLUGIN } from '@openedx/frontend-plugin-framework';
import { ExtendedProfileFields } from '@edunext/frontend-component-extended-fields';

// Load environment variables from .env file
const config = {
  ...process.env,
  pluginSlots: {
    extended_profile_fields_slot: {
      plugins: [
        {
          op: PLUGIN_OPERATIONS.Insert,
          widget: {
            id: 'extended_profile_fields',
            type: DIRECT_PLUGIN,
	    RenderWidget: ExtendedProfileFields,
          },
        },
      ],
    },
  },
};

export default config;

Problem with backend to update values

I think this problem is not associate with this PR, but maybe we have to mention this in troubleshooting section
Captura de pantalla de 2025-06-04 14-32-15

Install dependency only in Profile and Account MFE

What Andres mentions is important, we don't have to install @edunext/frontend-component-extended-fields dependency in each MFE, it's too much. We must figure out another way to make this work.

Finally @bra-i-am I don't see anything about the PR of @edunext/frontend-component-extended-fields and custom-form-app. Do you need any review of this?

@bra-i-am
Copy link
Author

bra-i-am commented Jun 4, 2025

@Asespinel, thank you for your review. I'll be working on the change of the plugin you mentioned!

I hope the issue is gone, and you can test it properly. Please let me know any other comments/questions you have ✨

@bra-i-am
Copy link
Author

bra-i-am commented Jun 4, 2025

@jignaciopm, thank you again for your review 🙏✨

There is no mention of the use of this branch in our Local Tutor

You're right, I forgot to mention that really important thing... with your permission, I'll paste the steps you give in the cover letter of this PR 😅

Problem with backend to update values

I already reviewed this: it was an error with the handling I was doing in the frontend-component-extended-fields custom library. I already published a new version with the fix, so if you build the MFE image again, it should be solved

Install dependency only in Profile and Account MFE

Yees, you are right... I'll be checking this out

Finally @bra-i-am I don't see anything about the PR of @edunext/frontend-component-extended-fields and custom-form-app. Do you need any review of this?

Honestly, I didn't create any PR for those things... but the repositories are not too big, so if you take a look at them, it would be great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Status: Ready for Review
Development

Successfully merging this pull request may close these issues.

4 participants