fix(overlay-menu): Adding, changing and removing segmentation overlays should update the overlay menu instantly (#5181)

This commit is contained in:
Joe Boccanfuso authored and GitHub committed 2025-07-07 18:09:32 -04:00
1 parent b8b14b8940
commit f08cc303e6
21 files changed
+164 -12

No files matched your search

@@ -1,4 +1,4 @@
import { useMemo } from 'react';
import { useEffect, useMemo, useState } from 'react';
import { useSystem, utils } from '@ohif/core';
import { useViewportGrid } from '@ohif/ui-next';
import {
@@ -122,12 +122,34 @@ export function useViewportDisplaySets(
// Get all available segmentations (only if needed)
const needsSegmentations = includeOverlay;
const segmentationRepresentations = useMemo(
() =>
needsSegmentations ? segmentationService.getSegmentationRepresentations(viewportIdToUse) : [],
[segmentationService, viewportIdToUse, needsSegmentations]
const [segmentationRepresentations, setSegmentationRepresentations] = useState(
needsSegmentations ? segmentationService.getSegmentationRepresentations(viewportIdToUse) : []
);
useEffect(() => {
setSegmentationRepresentations(
needsSegmentations ? segmentationService.getSegmentationRepresentations(viewportIdToUse) : []
);
const unsubscribeArr = needsSegmentations
? [
segmentationService.EVENTS.SEGMENTATION_REPRESENTATION_MODIFIED,
segmentationService.EVENTS.SEGMENTATION_REPRESENTATION_REMOVED,
].map(event =>
segmentationService.subscribe(event, () => {
setSegmentationRepresentations(
segmentationService.getSegmentationRepresentations(viewportIdToUse)
);
})
)
: [];
return () => {
unsubscribeArr.forEach(item => item.unsubscribe());
};
}, [segmentationService, viewportIdToUse, needsSegmentations]);
const overlayDisplaySets = useMemo(() => {
if (!includeOverlay) {
return [];