Skip to content
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

feat: query string dynamic app config #3391

Merged
merged 2 commits into from May 15, 2023
Merged

feat: query string dynamic app config #3391

merged 2 commits into from May 15, 2023

Conversation

anarnoli
Copy link
Contributor

Context

This PR allows for the app config to reference a json over network. This allows for
fast swapping of data source configuration, OIDC, etc, without recompiling the application.

If the configUrl query string is passed, the worklist and modes will load from the referenced json
rather than the default .env config

If there is no configUrl path provided, the default behaviour is used and there should not be any
deviation from current user experience.

Points to consider

  • User have to enable this feature by setting dangerouslyUseDynamicConfig.enabled:true. By default it is false.
  • Regex helps to avoid easy exploit
  • User must set cross-origin = same-origin to avoid potential harder exploit

Sample local config

/* Dynamic config allows user to pass "configUrl" query string this allows to load config without recompiling application. The regex will ensure valid configuration source */
  dangerouslyUseDynamicConfig: {
    enabled: false,
    regex: /.*/,
  }

Example usage

http://localhost:3000/?configUrl=http://localhost:3000/config/example.json

This PR is related to another PR #2925

Checklist

PR

  • Brief description of changes
  • Links to any relevant issues
  • Required status checks are passing
  • User cases if changes impact the user's experience
  • @mention a maintainer to request a review

Code

  • My code has been well-documented (function documentation, inline comments,
    etc.)

Public Documentation Updates

  • The documentation page has been updated as necessary for any public API
    additions or removals.

@netlify
Copy link

netlify bot commented May 14, 2023

Deploy Preview for ohif-platform-docs ready!

Name Link
🔨 Latest commit 3281fdc
🔍 Latest deploy log https://app.netlify.com/sites/ohif-platform-docs/deploys/64627bf87a3ac100088ef16b
😎 Deploy Preview https://deploy-preview-3391--ohif-platform-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented May 14, 2023

Deploy Preview for ohif-platform-viewer ready!

Name Link
🔨 Latest commit 3281fdc
🔍 Latest deploy log https://app.netlify.com/sites/ohif-platform-viewer/deploys/64627bf88b02de00084efa45
😎 Deploy Preview https://deploy-preview-3391--ohif-platform-viewer.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@codecov
Copy link

codecov bot commented May 14, 2023

Codecov Report

Merging #3391 (3281fdc) into v3-stable (9f1e813) will increase coverage by 13.20%.
The diff coverage is n/a.

Impacted file tree graph

@@              Coverage Diff               @@
##           v3-stable    #3391       +/-   ##
==============================================
+ Coverage      25.15%   38.36%   +13.20%     
==============================================
  Files            119       82       -37     
  Lines           2862     1345     -1517     
  Branches         555      303      -252     
==============================================
- Hits             720      516      -204     
+ Misses          1856      663     -1193     
+ Partials         286      166      -120     

see 77 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4172d04...3281fdc. Read the comment docs.

@anarnoli
Copy link
Contributor Author

@sedghi @wayfarer3130 - request to review this PR.

@cupidchan FYI.

const query = new URLSearchParams(window.location.search);
const configUrl = query.get('configUrl');

const searchQuery = new URLSearchParams();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you just add a TODO here to handle the remembering of the parameters in a better way? Really we should add the relevant parameters to the other queries, and then restore the full query string on going back, but that is NOT your problem here, it is just that I want a reminder that having the viewer page know about hte query page isn't a good idea.

@@ -25,6 +25,16 @@ window.config = {
},
// filterQueryParam: false,
defaultDataSourceName: 'dicomweb',
/* Dynamic config allows user to pass "configUrl" query string this allows to load config without recompiling application. The regex will ensure valid configuration source */
dangerouslyUseDynamicConfig: {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can leave the configuration commented out with the enabled: true set to show how to enable it. That way the entire block just works if someone uncomments it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree @wayfarer3130 .

const useDynamicConfig = config.dangerouslyUseDynamicConfig;

// Check if dangerouslyUseDynamicConfig enabled
if (useDynamicConfig.enabled) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This has to be useDynamicConfig?.enabled so that if the value isn't configured, it won't throw.

// validate regex
const regex = useDynamicConfig.regex;

if (regex.test(configUrl)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use:
configUrl.match(regex) so that if a string is provided int he configuration, it doesn't fail to work.

return (
<Link
key={i}
to={`${dataPath ? '../../' : ''}${mode.routeName}${dataPath ||
''}?StudyInstanceUIDs=${studyInstanceUid}`}
''}?${decodeURIComponent(query.toString())}`}
Copy link
Contributor

Choose a reason for hiding this comment

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

This fails for the situation where the configUrl includes parameters, such as:
configUrl=https://myhost/config?a=b&c=d
because the & is encoded/decoded. The decodeURIComponent, as the name says, needs to apply to individual components.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wayfarer3130 Do you mean decodeURIComponent should be removed and original queryString should be passed?

Copy link
Contributor

@wayfarer3130 wayfarer3130 left a comment

Choose a reason for hiding this comment

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

Just on bug to fix and a couple of comments/very small improvements.

@anarnoli
Copy link
Contributor Author

@wayfarer3130 Observations fixed, request to review.

@wayfarer3130 wayfarer3130 merged commit af8bb27 into OHIF:v3-stable May 15, 2023
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants