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
Conversation
✅ Deploy Preview for ohif-platform-docs ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for ohif-platform-viewer ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Codecov Report
@@ 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.
|
@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(); |
There was a problem hiding this comment.
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: { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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())}`} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this 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.
@wayfarer3130 Observations fixed, request to review. |
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 jsonrather than the default .env config
If there is no
configUrl
path provided, the default behaviour is used and there should not be anydeviation from current user experience.
Points to consider
dangerouslyUseDynamicConfig.enabled:true
. By default it isfalse
.cross-origin = same-origin
to avoid potential harder exploitSample local config
Example usage
http://localhost:3000/?configUrl=http://localhost:3000/config/example.json
This PR is related to another PR #2925
Checklist
PR
@mention
a maintainer to request a reviewCode
etc.)
Public Documentation Updates
additions or removals.