Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions extensions/cornerstone/src/panels/PanelSegmentation.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useCallback, useEffect } from 'react';
import {
Icons,
IconPresentationProvider,
Popover,
PopoverAnchor,
Expand Down Expand Up @@ -232,6 +233,18 @@ export default function PanelSegmentation({
};
});

const saveModality =
segmentationRepresentationTypes?.[0] === SegmentationRepresentations.Contour
? 'RTSTRUCT'
: 'SEG';
Comment on lines +236 to +239

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Derive saveModality from the selected representation, not the first configured type.

Line 236 always keys off segmentationRepresentationTypes?.[0], but the active selectedSegmentationIdForType can come from any entry in that array. In a mixed labelmap/contour panel, the Save click at Line 303 can therefore send the wrong modality for the selected segmentation, and the downstream store flow uses that field to build the save dialog path and default filename.

Suggested fix
-  const saveModality =
-    segmentationRepresentationTypes?.[0] === SegmentationRepresentations.Contour
+  const selectedRepresentationType = segmentationRepresentationTypes?.find(
+    type => selectedSegmentationsForViewportMap?.get(type) === selectedSegmentationIdForType
+  );
+
+  const saveModality =
+    selectedRepresentationType === SegmentationRepresentations.Contour
       ? 'RTSTRUCT'
       : 'SEG';

Also applies to: 303-309

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@extensions/cornerstone/src/panels/PanelSegmentation.tsx` around lines 236 -
239, The save modality is being derived from segmentationRepresentationTypes[0]
instead of the currently selected segmentation, which can make the Save flow use
the wrong modality for mixed representations. Update PanelSegmentation so
saveModality is computed from selectedSegmentationIdForType and its matching
representation entry, and ensure the Save handler in the same component passes
that selected modality through the downstream store flow that builds the save
dialog path and default filename.


const isCurrentSegExportable = !!(
selectedSegmentationIdForType &&
exportOptions.some(
o => o.segmentationId === selectedSegmentationIdForType && o.isExportable
)
);

// Common props for SegmentationTable
const tableProps = {
disabled,
Expand Down Expand Up @@ -276,6 +289,32 @@ export default function PanelSegmentation({
);
};

const renderSaveButton = () => {
if (!isCurrentSegExportable) {
return null;
}
return (
<button
type="button"
className="text-foreground hover:text-primary ml-auto cursor-pointer"
title="Save segmentation"
onClick={e => {
e.stopPropagation();
commandsManager.run({
commandName: 'storeSegmentation',
commandOptions: {
segmentationId: selectedSegmentationIdForType,
modality: saveModality,
},
context: 'CORNERSTONE',
});
}}
>
<Icons.Save className="h-4 w-4" />
</button>
);
};

// Render content based on mode
const renderModeContent = () => {
if (tableProps.mode === 'collapsed') {
Expand All @@ -288,6 +327,7 @@ export default function PanelSegmentation({
</SegmentationTable.Collapsed.DropdownMenu>
<SegmentationTable.Collapsed.Selector />
<SegmentationTable.Collapsed.Info />
{renderSaveButton()}
</SegmentationTable.Collapsed.Header>
<SegmentationTable.Collapsed.Content>
<SegmentationTable.AddSegmentRow />
Expand All @@ -307,6 +347,7 @@ export default function PanelSegmentation({
</SegmentationTable.Expanded.DropdownMenu>
<SegmentationTable.Expanded.Label />
<SegmentationTable.Expanded.Info />
{renderSaveButton()}
</SegmentationTable.Expanded.Header>

<SegmentationTable.Expanded.Content>
Expand Down
Loading