Skip to content

Allow customization of external URLs #809

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

Merged
merged 3 commits into from
Jun 9, 2025

Conversation

wgu-taylor-payne
Copy link
Contributor

@wgu-taylor-payne wgu-taylor-payne commented May 23, 2025

Description:

This adds a getExternalLinkUrl function to the config.js module. This provides a way for external links to be customized/overridden in frontend apps. To customize links, it is required to provide a externalLinkUrlOverrides object as part of the config object defined in env.config.js. This object maps default URLs to custom URLs. Given a URL, the getExternalLinkUrl will check the config object via getConfig for a matching key, and if found, will return the value, which is a custom URL to be used in place of the default URL. If no match is found, the function will return the URL passed in (if it is a valid string).

getExternalLinkUrl can be used when no custom configuration is provided. Also, it will still work in these cases:

  1. externalLinkUrlOverrides does not exist in the config object.
  2. externalLinkUrlOverrides exists, but is empty.
  3. externalLinkUrlOverrides exists, and is not empty, but does not contain a mapping for the URL provided.

In all of these scenarios, the URL passed into the function will be returned to the function. An exception to this is the case where an invalid argument is supplied to the url parameter. In this case the function will fall back to a default value of '#'.

Closes #798

Merge checklist:

  • Consider running your code modifications in the included example app within frontend-platform. This can be done by running npm start and opening http://localhost:8080.
  • Consider testing your code modifications in another local micro-frontend using local aliases configured via the module.config.js file in frontend-build.
  • Verify your commit title/body conforms to the conventional commits format (e.g., fix, feat) and is appropriate for your code change. Consider whether your code is a breaking change, and modify your commit accordingly.

Post merge:

  • After the build finishes for the merged commit, verify the new release has been pushed to NPM.

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

Thanks for the pull request, @wgu-taylor-payne!

This repository is currently maintained by @openedx/committers-frontend.

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 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.12%. Comparing base (93bee06) to head (1dc67f9).
Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #809      +/-   ##
==========================================
+ Coverage   86.79%   87.12%   +0.33%     
==========================================
  Files          48       48              
  Lines        1401     1406       +5     
  Branches      297      300       +3     
==========================================
+ Hits         1216     1225       +9     
+ Misses        172      168       -4     
  Partials       13       13              

☔ 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.

@wgu-taylor-payne wgu-taylor-payne changed the title External url config Allow customization of external URLs May 23, 2025
@wgu-taylor-payne wgu-taylor-payne added the mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). label May 23, 2025
@wgu-taylor-payne wgu-taylor-payne self-assigned this May 23, 2025
@tonybusa tonybusa requested a review from Copilot May 27, 2025 16:10
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces the getExternalLinkUrl function to allow customization of external URLs by providing a custom mapping via the configuration object. Key changes include:

  • Adding the getExternalLinkUrl function in src/config.js with accompanying documentation.
  • Introducing thorough tests in src/getExternalLinkUrl.test.js to cover various scenarios.
  • Updating relevant documentation in README.md and example usage in ExamplePage.jsx.

Reviewed Changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/index.js Updated re-exports to include getExternalLinkUrl.
src/getExternalLinkUrl.test.js Added tests to validate getExternalLinkUrl behavior under multiple scenarios.
src/config.js Introduced getExternalLinkUrl function and updated documentation for external URL customization.
example/ExamplePage.jsx Demonstrated usage of getExternalLinkUrl in a React example page.
env.config.js Provided a sample customExternalUrls mapping in the configuration object.
README.md Updated instructions to guide users on configuring custom external links with getExternalLinkUrl.
Files not reviewed (1)
  • .env.development: Language not supported
Comments suppressed due to low confidence (1)

src/config.js:315

  • The docstring states that a warning is logged for invalid URLs, but the implementation does not log any warning. Consider updating the documentation or adding the warning logging for consistency.
 * If the input URL is invalid, a warning is logged and '#' is returned.

@sarina
Copy link
Contributor

sarina commented May 27, 2025

I'm not going to be able to provide a comprehensive review on this PR. But I do wonder why the values in .env.development have changed.

@sarina sarina removed their request for review May 27, 2025 16:39
@wgu-taylor-payne
Copy link
Contributor Author

The ports in .env.development were compatible with devstack rather than tutor. I've updated them to be compatible with a default tutor dev environment.

@mphilbrick211 mphilbrick211 moved this from Needs Triage to Ready for Review in Contributions May 27, 2025
@mphilbrick211 mphilbrick211 requested a review from a team May 27, 2025 19:02
Copy link
Contributor

@arbrandes arbrandes left a comment

Choose a reason for hiding this comment

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

I love the included documentation and tests, thank you! The code looks great, too.

I only raised a matter of function/object naming, which we should discuss before merging.

@wgu-taylor-payne wgu-taylor-payne force-pushed the external-url-config branch 2 times, most recently from 1edd96e to a41e178 Compare June 5, 2025 20:44
Copy link
Contributor

@brian-smith-tcril brian-smith-tcril left a comment

Choose a reason for hiding this comment

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

Overall this looks great! Would you be able to move the .env changes and the README changes that aren't related to URL overrides to a separate PR? I think they're valuable changes but I'd prefer to keep this PR targeted to the one task.

Create the getExternalLinkUrl function and make it available for
use in frontend apps. It checks for a `customExternalUrls` object
in the config to see if a custom URL has been provided for a given
URL.

Use getExternalLinkUrl in the example app for this package. One
link is overridden with a custom URL while the other is not.
Copy link
Contributor

@brian-smith-tcril brian-smith-tcril left a comment

Choose a reason for hiding this comment

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

Thank you so much for putting this together!

LGTM!

Copy link
Contributor

@arbrandes arbrandes left a comment

Choose a reason for hiding this comment

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

Looks great! 👍🏼

@arbrandes arbrandes merged commit 8c88998 into openedx:master Jun 9, 2025
6 checks passed
@github-project-automation github-project-automation bot moved this from Ready for Review to Done in Contributions Jun 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). open-source-contribution PR author is not from Axim or 2U
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

External link map for customizable documentation links in frontend repos
5 participants