import React from 'react'; import { DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuSeparator, DropdownMenuSub, DropdownMenuSubTrigger, DropdownMenuSubContent, Icons, useSegmentationTableContext, useSegmentationExpanded, } from '@ohif/ui-next'; import { useTranslation } from 'react-i18next'; import { useSystem } from '@ohif/core/src'; /** * Custom dropdown menu component for segmentation panel that uses context for data */ export const CustomDropdownMenuContent = () => { const { commandsManager } = useSystem(); const { t } = useTranslation('SegmentationTable'); const { onSegmentationAdd, onSegmentationRemoveFromViewport, onSegmentationEdit, onSegmentationDelete, exportOptions, activeSegmentation, activeSegmentationId, } = useSegmentationTableContext('CustomDropdownMenu'); // Try to get segmentation data from expanded context first, fall back to table context let segmentation; let segmentationId; let allowExport = false; try { // Try to get from expanded context const context = useSegmentationExpanded(); segmentation = context.segmentation; segmentationId = segmentation.segmentationId; } catch (e) { // If not in expanded context, fallback to active segmentation from table context segmentation = activeSegmentation; segmentationId = activeSegmentationId; } // Determine if export is allowed for this segmentation if (exportOptions && segmentationId) { const exportOption = exportOptions.find(opt => opt.segmentationId === segmentationId); allowExport = exportOption?.isExportable || false; } if (!segmentation || !segmentationId) { return null; } const actions = { storeSegmentation: async segmentationId => { commandsManager.run({ commandName: 'storeSegmentation', commandOptions: { segmentationId }, context: 'CORNERSTONE', }); }, onSegmentationDownloadRTSS: segmentationId => { commandsManager.run('downloadRTSS', { segmentationId }); }, onSegmentationDownload: segmentationId => { commandsManager.run('downloadSegmentation', { segmentationId }); }, downloadCSVSegmentationReport: segmentationId => { commandsManager.run('downloadCSVSegmentationReport', { segmentationId }); }, }; return ( onSegmentationAdd(segmentationId)}> {t('Create New Segmentation')} {t('Manage Current Segmentation')} onSegmentationRemoveFromViewport(segmentationId)}> {t('Remove from Viewport')} onSegmentationEdit(segmentationId)}> {t('Rename')} {t('Download & Export')} {t('Download')} { e.preventDefault(); actions.downloadCSVSegmentationReport(segmentationId); }} disabled={!allowExport} > {t('CSV Report')} { e.preventDefault(); actions.onSegmentationDownload(segmentationId); }} disabled={!allowExport} > {t('DICOM SEG')} { e.preventDefault(); actions.onSegmentationDownloadRTSS(segmentationId); }} disabled={!allowExport} > {t('DICOM RTSS')} {t('Export')} { e.preventDefault(); actions.storeSegmentation(segmentationId); }} disabled={!allowExport} > {t('DICOM SEG')} onSegmentationDelete(segmentationId)}> {t('Delete')} ); };