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 8 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. 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,
              },
            }""",
            ),
        ]
    )
  3. Run tutor images build mfe --no-cache
  4. 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
  5. 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
  6. Run tutor images build openedx --no-cache
  7. Run tutor local start
  8. 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"
        ]
    }
  9. 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 (65a004a).
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
const extendedProfileValues = useSelector((state) => state.profilePage.account.extendedProfile);

const pluginProps = {
refreshUserProfile: (username) => dispatch(fetchProfile(username)),

Choose a reason for hiding this comment

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

The refreshUserProfile function is redefined every render. You could use useCallback to avoid unnecessary renderings in plugins that rely on this function.

Suggested change
refreshUserProfile: (username) => dispatch(fetchProfile(username)),
refreshUserProfile: useCallback((username) => dispatch(fetchProfile(username)), [dispatch]),

keepDefault: false,
plugins: [
{
// Insert a custom ExtendedProfileFields component

Choose a reason for hiding this comment

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

I think this comment is unnecessary.

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

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: No status
Status: Ready for Review
Development

Successfully merging this pull request may close these issues.

3 participants