-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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(grid): remove viewportIndex and only rely on viewportId #3591
Conversation
✅ Deploy Preview for ohif-platform-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for ohif-dev ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
throw new Error('Should have viewport ID afterwards'); | ||
} | ||
|
||
public enableViewport(viewportId: string, elementRef: HTMLDivElement): void { |
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.
Why doesn't this have the viewport options any longer - are those always already provided?
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.
we were only using viewportOptions to grab viewportId, so just using viewportId now
extensions/cornerstone/src/utils/stackSync/toggleStackImageSync.ts
Outdated
Show resolved
Hide resolved
extensions/cornerstone/src/utils/stackSync/toggleStackImageSync.ts
Outdated
Show resolved
Hide resolved
@jbocce Thanks for thorough review, applied/fixed based on your comment |
Great work fixing the issues I found! Thanks so much. I think the following comments should be discussed and/or addressed... |
@jbocce applied all three comments |
@jbocce I think I got it working for the double click too |
Yes. Thank you for that. See my comments. |
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.
Approved.
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.
There are some smallish changes, and a couple of questions, but I think this is important enough that we should proceed on it.
If you decide to include any of the fixes, that is great, but otherwise I wouldn't worry about them - you decide which comments are still worth applying.
const nextViewportIndex = (activeViewportIndex + 1) % viewports.length; | ||
viewportGridService.setActiveViewportIndex(nextViewportIndex); | ||
const { activeViewportId, viewports } = viewportGridService.getState(); | ||
const nextViewportIndex = (activeViewportId + 1) % viewports.size; |
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.
What about adding get viewport ids function that returns a list, and takes an optional sorting parameter. Then you still setActiveViewportId, but you provide it an actual viewport - and you can decide based on the mode or extension how things get sorted. That is, implement in the service itself, based on the getState call:
getViewportIds(sortFunction) {
return [...getState().viewports].map(viewport => viewport.viewportId).sort(sortFunction)
That says nothing about indices, just gets the ids of interest. You could add a filter function to it too.
import viewportLabels from '../utils/viewportLabels'; | ||
|
||
const DEFAULT_STATE = { | ||
activeViewportIndex: 0, | ||
interface Viewport { |
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 add export types on the interfaces?
if (setActiveViewportIndexImplementation) { | ||
this.serviceImplementation._setActiveViewportIndex = | ||
setActiveViewportIndexImplementation; | ||
if (setActiveViewportIdImplementation) { |
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 might consider:
this.serviceImplementation._setActiveViewport = setActiveViewportIdImplementation || this.serviceImplementation._setActiveViewport;
extensions/cornerstone/src/utils/stackSync/toggleStackImageSync.ts
Outdated
Show resolved
Hide resolved
@@ -16,12 +16,18 @@ describe('OHIF Double Click', () => { | |||
.should('be.eq', numExpectedViewports); | |||
|
|||
for (let i = 0; i < numExpectedViewports; i += 1) { | |||
cy.wait(2000); |
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.
If you merge the CINE fix in CS3D, then this wait gets removed and you just do a waitDicomImage() above line 18.
I'd really like to see it do waitDicomImage instead of cy.wait as it is much more reliable, and is fast on fast systems, and slow on slower connections.
} | ||
displaySet, | ||
seriesMatchingRules, | ||
// Todo: why we have images here since the matching type does not have 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 don't think we need the actual instance any longer.
...(updatedViewport.viewportOptions || | ||
previousViewport.viewportOptions), | ||
}; | ||
const viewportOptions = merge( |
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.
Does this need a real merge? It feels like it might cause mixtures that aren't intended, where one version has a value for key A, and the next one has a value for keyB, but doesn't specifically null out keyA, then keyA still applies.
Not saying it doesn't, just asking.
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 think it is fine
Co-authored-by: Bill Wallace <wayfarer3130@gmail.com>
Context
During the development of OHIF, the reliance on viewport index has proven to be problematic. This issue has seen in several ways:
Inconsistent Viewport Indexing with Layout Changes: A change from a 2x2 to a 3x3 grid alters the viewport index, causing unnecessary re-rendering, even though the display sets remain the same. This has resulted in a lack of optimization in grid rendering during stage and layout changes.
Viewport Movement Problems: for moving a viewport (similar to moving a person's window in Zoom, which we have in plan to support in future), the change in viewport index forces React to re-render the whole grid (as right now we have the key as viewportIndex). While the element itself hasn't changed, the viewport index change causes a problematic full re-render.
Changes Made
Migration Guide
You should not rely on viewportIndex and activeViewportIndex anymore.
Instead try
Viewports
also has been changed from an array to a MapSo you need to
viewports.get(viewportId
instead ofviewports[viewportIndex]
Testing
The implemented changes have been tested, and the following features are working as expected:
Cheers