From 5a95f427f329ee0e178f261b1a96c504b2fe6af0 Mon Sep 17 00:00:00 2001 From: Pedro Kohler Date: Thu, 4 Jan 2024 16:38:24 -0300 Subject: [PATCH] feat: improve disableEditing flag --- .../ContextMenuController.tsx | 13 ++++++ .../hydrateStructuredReport.tsx | 4 +- .../PanelMeasurementTableTracking/index.tsx | 32 +++++++------- .../MeasurementTable/MeasurementItem.tsx | 42 ++++++++++++------- .../MeasurementTable/MeasurementTable.tsx | 35 ++++++++++------ 5 files changed, 82 insertions(+), 44 deletions(-) diff --git a/extensions/default/src/CustomizableContextMenu/ContextMenuController.tsx b/extensions/default/src/CustomizableContextMenu/ContextMenuController.tsx index 9d65b971d87..75292906364 100644 --- a/extensions/default/src/CustomizableContextMenu/ContextMenuController.tsx +++ b/extensions/default/src/CustomizableContextMenu/ContextMenuController.tsx @@ -1,6 +1,7 @@ import * as ContextMenuItemsBuilder from './ContextMenuItemsBuilder'; import ContextMenu from '../../../../platform/ui/src/components/ContextMenu/ContextMenu'; import { CommandsManager, ServicesManager, Types } from '@ohif/core'; +import { annotation as CsAnnotation } from '@cornerstonejs/tools'; import { Menu, MenuItem, Point, ContextMenuProps } from './types'; /** @@ -47,6 +48,18 @@ export default class ContextMenuController { const { event, subMenu, menuId, menus, selectorProps } = contextMenuProps; + const annotationManager = CsAnnotation.state.getAnnotationManager(); + const { locking } = CsAnnotation; + const targetAnnotationId = selectorProps?.nearbyToolData?.annotationUID as string; + const isLocked = locking.isAnnotationLocked( + annotationManager.getAnnotation(targetAnnotationId) + ); + + if (isLocked) { + console.warn('Annotation is locked.'); + return; + } + console.log('Getting items from', menus); const items = ContextMenuItemsBuilder.getMenuItems( selectorProps || contextMenuProps, diff --git a/extensions/measurement-tracking/src/contexts/TrackedMeasurementsContext/hydrateStructuredReport.tsx b/extensions/measurement-tracking/src/contexts/TrackedMeasurementsContext/hydrateStructuredReport.tsx index 22d04aaf70a..480b3331066 100644 --- a/extensions/measurement-tracking/src/contexts/TrackedMeasurementsContext/hydrateStructuredReport.tsx +++ b/extensions/measurement-tracking/src/contexts/TrackedMeasurementsContext/hydrateStructuredReport.tsx @@ -1,13 +1,13 @@ import { hydrateStructuredReport as baseHydrateStructuredReport } from '@ohif/extension-cornerstone-dicom-sr'; -function hydrateStructuredReport({ servicesManager, extensionManager }, ctx, evt) { +function hydrateStructuredReport({ servicesManager, extensionManager, appConfig }, ctx, evt) { const { displaySetService } = servicesManager.services; const { viewportId, displaySetInstanceUID } = evt; const srDisplaySet = displaySetService.getDisplaySetByUID(displaySetInstanceUID); return new Promise((resolve, reject) => { const hydrationResult = baseHydrateStructuredReport( - { servicesManager, extensionManager }, + { servicesManager, extensionManager, appConfig }, displaySetInstanceUID ); diff --git a/extensions/measurement-tracking/src/panels/PanelMeasurementTableTracking/index.tsx b/extensions/measurement-tracking/src/panels/PanelMeasurementTableTracking/index.tsx index 7b0ca797719..3605995c636 100644 --- a/extensions/measurement-tracking/src/panels/PanelMeasurementTableTracking/index.tsx +++ b/extensions/measurement-tracking/src/panels/PanelMeasurementTableTracking/index.tsx @@ -10,6 +10,7 @@ import { } from '@ohif/ui'; import { DicomMetadataStore, utils } from '@ohif/core'; import { useDebounce } from '@hooks'; +import { useAppConfig } from '@state'; import ActionButtons from './ActionButtons'; import { useTrackedMeasurements } from '../../getContextModule'; import debounce from 'lodash.debounce'; @@ -36,6 +37,7 @@ function PanelMeasurementTableTracking({ servicesManager, extensionManager }) { ); const [displayMeasurements, setDisplayMeasurements] = useState([]); const measurementsPanelRef = useRef(null); + const [appConfig] = useAppConfig(); useEffect(() => { const measurements = measurementService.getMeasurements(); @@ -244,20 +246,22 @@ function PanelMeasurementTableTracking({ servicesManager, extensionManager }) { /> )} -
- { - sendTrackedMeasurementsEvent('SAVE_REPORT', { - viewportId: viewportGrid.activeViewportId, - isBackupSave: true, - }); - }} - disabled={ - additionalFindings.length === 0 && displayMeasurementsWithoutFindings.length === 0 - } - /> -
+ {!appConfig?.disableEditing && ( +
+ { + sendTrackedMeasurementsEvent('SAVE_REPORT', { + viewportId: viewportGrid.activeViewportId, + isBackupSave: true, + }); + }} + disabled={ + additionalFindings.length === 0 && displayMeasurementsWithoutFindings.length === 0 + } + /> +
+ )} ); } diff --git a/platform/ui/src/components/MeasurementTable/MeasurementItem.tsx b/platform/ui/src/components/MeasurementTable/MeasurementItem.tsx index d807616a27a..7e3bbeb2bca 100644 --- a/platform/ui/src/components/MeasurementTable/MeasurementItem.tsx +++ b/platform/ui/src/components/MeasurementTable/MeasurementItem.tsx @@ -4,7 +4,17 @@ import classnames from 'classnames'; import Icon from '../Icon'; -const MeasurementItem = ({ uid, index, label, displayText, isActive, onClick, onEdit, item }) => { +const MeasurementItem = ({ + uid, + index, + label, + displayText, + isActive, + isLocked, + onClick, + onEdit, + item, +}) => { const [isHovering, setIsHovering] = useState(false); const onEditHandler = event => { @@ -49,20 +59,22 @@ const MeasurementItem = ({ uid, index, label, displayText, isActive, onClick, on dangerouslySetInnerHTML={{ __html: line }} > ))} - + {!isLocked && ( + + )} ); diff --git a/platform/ui/src/components/MeasurementTable/MeasurementTable.tsx b/platform/ui/src/components/MeasurementTable/MeasurementTable.tsx index 5316263e8b6..bc6d2364727 100644 --- a/platform/ui/src/components/MeasurementTable/MeasurementTable.tsx +++ b/platform/ui/src/components/MeasurementTable/MeasurementTable.tsx @@ -2,6 +2,7 @@ import React from 'react'; import { ServicesManager } from '@ohif/core'; import PropTypes from 'prop-types'; import { useTranslation } from 'react-i18next'; +import { annotation as CsAnnotation } from '@cornerstonejs/tools'; import MeasurementItem from './MeasurementItem'; @@ -16,6 +17,8 @@ const MeasurementTable = ({ data, title, onClick, onEdit, servicesManager }) => contentProps: {}, }); const CustomMeasurementItem = itemCustomization.content; + const annotationManager = CsAnnotation.state.getAnnotationManager(); + const { locking } = CsAnnotation; return (
@@ -25,19 +28,25 @@ const MeasurementTable = ({ data, title, onClick, onEdit, servicesManager }) =>
{data.length !== 0 && - data.map((measurementItem, index) => ( - - ))} + data.map((measurementItem, index) => { + const isLocked = locking.isAnnotationLocked( + annotationManager.getAnnotation(measurementItem.uid) + ); + return ( + + ); + })} {data.length === 0 && (