-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
feat: Add customization URL parameter #5992
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
wayfarer3130
wants to merge
11
commits into
master
Choose a base branch
from
feat/customization-url-parameter
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f360abb
Add customization URL parameter
wayfarer3130 38ddc9c
fix: Preserve should be customizeable
wayfarer3130 cee9d2a
Update customizations docs
wayfarer3130 ca6381b
Merge remote-tracking branch 'origin/master' into feat/customization-…
wayfarer3130 a7ecb45
fix: Overlay items on patient name
wayfarer3130 74c5986
Add customization test
wayfarer3130 7068511
Fix resolve to absolute path
wayfarer3130 60efc1c
fix: Warn on no data in load
wayfarer3130 b80b5ca
Remove unused customization stuff
wayfarer3130 8cc46ad
Merge branch 'master' into feat/customization-url-parameter
wayfarer3130 393fd48
fix: PR comments
wayfarer3130 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| /** | ||
| * Example chaining module: ensures `veterinaryOverlay` is loaded and applied | ||
| * first when using `?customization=veterinary` alone. | ||
| */ | ||
| export default { | ||
| requires: ['veterinaryOverlay'], | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /** | ||
| * Example URL-loaded customization module: veterinaryOverlay | ||
| * | ||
| * Demonstrates a runtime-loaded customization that overrides the default | ||
| * viewport overlay with a veterinary-style demographics layout. Loaded via | ||
| * `?customization=veterinaryOverlay` (see CustomizationService URL handling). | ||
| * | ||
| * Uses the same default-export shape as cornerstone overlay samples | ||
| * (`global` at top level) and `inheritsFrom: 'ohif.overlayItem'` on each | ||
| * row, matching `extensions/cornerstone/.../viewportOverlayCustomization.tsx`. | ||
| */ | ||
| export default { | ||
| global: { | ||
| 'viewportOverlay.topLeft': { | ||
| $set: [ | ||
| { | ||
| id: 'PatientName', | ||
| inheritsFrom: 'ohif.overlayItem', | ||
| attribute: 'PatientName', | ||
| label: 'Patient', | ||
| title: 'Patient name', | ||
| }, | ||
| { | ||
| id: 'PatientID', | ||
| inheritsFrom: 'ohif.overlayItem', | ||
| attribute: 'PatientID', | ||
| label: 'ID', | ||
| title: 'Patient ID', | ||
| }, | ||
| { | ||
| id: 'StudyDate', | ||
| inheritsFrom: 'ohif.overlayItem', | ||
| attribute: 'StudyDate', | ||
| label: 'Date', | ||
| title: 'Study date', | ||
| }, | ||
| ], | ||
| }, | ||
| 'viewportOverlay.topRight': { | ||
| $set: [ | ||
| { | ||
| id: 'PatientSpecies', | ||
| inheritsFrom: 'ohif.overlayItem', | ||
| attribute: 'PatientSpecies', | ||
| label: 'Species', | ||
| title: 'Patient species', | ||
| }, | ||
| { | ||
| id: 'PatientBreed', | ||
| inheritsFrom: 'ohif.overlayItem', | ||
| attribute: 'PatientBreed', | ||
| label: 'Breed', | ||
| title: 'Patient breed', | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import qs from 'qs'; | ||
|
|
||
| import { preserveQueryParameters, preserveQueryStrings } from './preserveQueryParameters'; | ||
|
|
||
| describe('preserveQueryParameters', () => { | ||
| it('preserves base keys as query arrays', () => { | ||
| const current = new URLSearchParams(); | ||
| current.append('configUrl', 'foo.js'); | ||
| const out = new URLSearchParams(); | ||
| preserveQueryParameters(out, undefined, current); | ||
| expect(out.getAll('configUrl')).toEqual(['foo.js']); | ||
| }); | ||
|
|
||
| it('preserves all repeated values for the customization key', () => { | ||
| const current = new URLSearchParams(); | ||
| current.append('customization', 'a'); | ||
| current.append('customization', 'b'); | ||
| const out = new URLSearchParams(); | ||
| preserveQueryParameters(out, undefined, current); | ||
| expect(out.getAll('customization')).toEqual(['a', 'b']); | ||
| }); | ||
|
|
||
| it('does not preserve unrelated keys', () => { | ||
| const current = new URLSearchParams(); | ||
| current.append('foo', 'bar'); | ||
| const out = new URLSearchParams(); | ||
| preserveQueryParameters(out, undefined, current); | ||
| expect(out.get('foo')).toBeNull(); | ||
| }); | ||
|
|
||
| it('uses customization service values for multi-key preservation', () => { | ||
| const customizationService = { | ||
| getValue: jest.fn().mockReturnValue(['customization', 'customizationAlt']), | ||
| }; | ||
| const current = new URLSearchParams(); | ||
| current.append('customizationAlt', 'c'); | ||
| const out = new URLSearchParams(); | ||
| preserveQueryParameters(out, customizationService, current); | ||
| expect(out.getAll('customizationAlt')).toEqual(['c']); | ||
| expect(customizationService.getValue).toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('preserveQueryStrings', () => { | ||
| it('keeps all preserved keys as arrays', () => { | ||
| const current = new URLSearchParams(); | ||
| current.append('configUrl', 'foo.js'); | ||
| current.append('customization', 'a'); | ||
| current.append('customization', 'b'); | ||
|
|
||
| const out: Record<string, string | string[]> = {}; | ||
| preserveQueryStrings(out, undefined, current); | ||
| expect(out.configUrl).toEqual(['foo.js']); | ||
| expect(out.customization).toEqual(['a', 'b']); | ||
| }); | ||
|
|
||
| it('keeps a single customization value as an array', () => { | ||
| const current = new URLSearchParams(); | ||
| current.append('customization', 'only'); | ||
| const out: Record<string, string | string[]> = {}; | ||
| preserveQueryStrings(out, undefined, current); | ||
| expect(out.customization).toEqual(['only']); | ||
| }); | ||
|
|
||
| it('uses customization service values for query string preservation', () => { | ||
| const customizationService = { | ||
| getValue: jest.fn().mockReturnValue(['customization', 'customizationAlt']), | ||
| }; | ||
| const current = new URLSearchParams(); | ||
| current.append('customizationAlt', 'c'); | ||
| const out: Record<string, string | string[]> = {}; | ||
| preserveQueryStrings(out, customizationService, current); | ||
| expect(out.customizationAlt).toEqual(['c']); | ||
| expect(customizationService.getValue).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('serializes single preserved values as plain query keys with arrayFormat repeat', () => { | ||
| const current = new URLSearchParams(); | ||
| current.append('configUrl', 'foo.js'); | ||
| const out: Record<string, string | string[]> = {}; | ||
| preserveQueryStrings(out, undefined, current); | ||
| const search = qs.stringify(out, { | ||
| skipNull: true, | ||
| skipEmptyString: true, | ||
| arrayFormat: 'repeat', | ||
| }); | ||
| expect(search).toBe('configUrl=foo.js'); | ||
| expect(search).not.toMatch(/configUrl\[/); | ||
| }); | ||
|
|
||
| it('serializes repeated preserved values as repeated keys', () => { | ||
| const current = new URLSearchParams(); | ||
| current.append('customization', 'a'); | ||
| current.append('customization', 'b'); | ||
| const out: Record<string, string | string[]> = {}; | ||
| preserveQueryStrings(out, undefined, current); | ||
| const search = qs.stringify(out, { | ||
| skipNull: true, | ||
| skipEmptyString: true, | ||
| arrayFormat: 'repeat', | ||
| }); | ||
| expect(search).toBe('customization=a&customization=b'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,55 @@ | ||
| function preserve(query, current, key) { | ||
| const value = current.get(key); | ||
| if (value) { | ||
| query.append(key, value); | ||
| import type CustomizationService from '@ohif/core/src/services/CustomizationService'; | ||
|
|
||
| /** | ||
| * Keys preserved when navigating between worklist and viewer modes. | ||
| * All preserved keys are handled as multi-valued query parameters. | ||
| */ | ||
| export const PRESERVE_CUSTOMIZATION_KEYS_KEY = 'ohif.preserveCustomizationKeys'; | ||
| export const preserveKeys = [ | ||
| 'configUrl', | ||
| 'multimonitor', | ||
| 'screenNumber', | ||
| 'hangingProtocolId', | ||
| 'customization', | ||
| ]; | ||
|
|
||
| function preserveKey(query: URLSearchParams, current: URLSearchParams, key: string) { | ||
| const values = current.getAll(key); | ||
| for (const value of values) { | ||
| if (value) { | ||
| query.append(key, value); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export const preserveKeys = ['configUrl', 'multimonitor', 'screenNumber', 'hangingProtocolId']; | ||
| function getPreserveKeys(customizationService?: CustomizationService): string[] { | ||
| const customKeys = customizationService?.getValue?.(PRESERVE_CUSTOMIZATION_KEYS_KEY, []) || []; | ||
| if (!customKeys?.length) { | ||
| return preserveKeys; | ||
| } | ||
|
|
||
| return [...preserveKeys, ...customKeys]; | ||
| } | ||
|
|
||
| export function preserveQueryParameters( | ||
| query, | ||
| current = new URLSearchParams(window.location.search) | ||
| ) { | ||
| for (const key of preserveKeys) { | ||
| preserve(query, current, key); | ||
| query: URLSearchParams, | ||
| customizationService?: CustomizationService, | ||
| current: URLSearchParams = new URLSearchParams(window.location.search) | ||
| ): void { | ||
| for (const key of getPreserveKeys(customizationService)) { | ||
| preserveKey(query, current, key); | ||
| } | ||
| } | ||
|
|
||
| export function preserveQueryStrings(query, current = new URLSearchParams(window.location.search)) { | ||
| for (const key of preserveKeys) { | ||
| const value = current.get(key); | ||
| if (value) { | ||
| query[key] = value; | ||
| export function preserveQueryStrings( | ||
| query: Record<string, string | string[]>, | ||
| customizationService?: CustomizationService, | ||
| current: URLSearchParams = new URLSearchParams(window.location.search) | ||
| ): void { | ||
| for (const key of getPreserveKeys(customizationService)) { | ||
| const values = current.getAll(key).filter(Boolean); | ||
| if (values.length) { | ||
| query[key] = values; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.