@ohif/extension-default 3.14.0-beta.10 → 3.14.0-beta.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. package/dist/ohif-extension-default.css +1 -1
  2. package/dist/ohif-extension-default.umd.js +1 -1
  3. package/package.json +14 -10
  4. package/src/Actions/createReportAsync.tsx +45 -0
  5. package/src/Components/DataSourceConfigurationComponent.tsx +142 -0
  6. package/src/Components/DataSourceConfigurationModalComponent.tsx +200 -0
  7. package/src/Components/ItemListComponent.tsx +95 -0
  8. package/src/Components/LineChartViewport/LineChartViewport.tsx +31 -0
  9. package/src/Components/LineChartViewport/index.ts +1 -0
  10. package/src/Components/MoreDropdownMenu.tsx +112 -0
  11. package/src/Components/ProgressDropdownWithService.tsx +101 -0
  12. package/src/Components/SidePanelWithServices.tsx +122 -0
  13. package/src/CustomizableContextMenu/ContextMenuController.tsx +216 -0
  14. package/src/CustomizableContextMenu/ContextMenuItemsBuilder.test.js +29 -0
  15. package/src/CustomizableContextMenu/ContextMenuItemsBuilder.ts +176 -0
  16. package/src/CustomizableContextMenu/index.ts +5 -0
  17. package/src/CustomizableContextMenu/types.ts +126 -0
  18. package/src/DataSourceConfigurationAPI/GoogleCloudDataSourceConfigurationAPI.ts +236 -0
  19. package/src/DicomJSONDataSource/index.js +326 -0
  20. package/src/DicomLocalDataSource/index.js +273 -0
  21. package/src/DicomTagBrowser/DicomTagBrowser.css +49 -0
  22. package/src/DicomTagBrowser/DicomTagBrowser.tsx +454 -0
  23. package/src/DicomTagBrowser/DicomTagTable.tsx +311 -0
  24. package/src/DicomWebDataSource/dcm4cheeReject.js +45 -0
  25. package/src/DicomWebDataSource/exampleInstances.js +280 -0
  26. package/src/DicomWebDataSource/index.ts +808 -0
  27. package/src/DicomWebDataSource/qido.js +215 -0
  28. package/src/DicomWebDataSource/retrieveBulkData.test.ts +35 -0
  29. package/src/DicomWebDataSource/retrieveBulkData.ts +31 -0
  30. package/src/DicomWebDataSource/retrieveRendered.test.ts +147 -0
  31. package/src/DicomWebDataSource/retrieveRendered.ts +141 -0
  32. package/src/DicomWebDataSource/retrieveStudyMetadata.js +108 -0
  33. package/src/DicomWebDataSource/retrieveStudyMetadata.test.js +75 -0
  34. package/src/DicomWebDataSource/retrieveThumbnail.ts +346 -0
  35. package/src/DicomWebDataSource/serviceUrls.test.ts +143 -0
  36. package/src/DicomWebDataSource/utils/StaticWadoClient.ts +272 -0
  37. package/src/DicomWebDataSource/utils/cleanDenaturalizedDataset.ts +78 -0
  38. package/src/DicomWebDataSource/utils/findIndexOfString.ts +47 -0
  39. package/src/DicomWebDataSource/utils/fixBulkDataURI.test.ts +68 -0
  40. package/src/DicomWebDataSource/utils/fixBulkDataURI.ts +78 -0
  41. package/src/DicomWebDataSource/utils/fixMultiValueKeys.ts +12 -0
  42. package/src/DicomWebDataSource/utils/fixMultipart.ts +70 -0
  43. package/src/DicomWebDataSource/utils/getImageId.js +54 -0
  44. package/src/DicomWebDataSource/utils/getWADORSImageId.js +51 -0
  45. package/src/DicomWebDataSource/utils/index.ts +9 -0
  46. package/src/DicomWebDataSource/utils/retrieveMetadataFiltered.js +61 -0
  47. package/src/DicomWebDataSource/wado/retrieveMetadata.js +41 -0
  48. package/src/DicomWebDataSource/wado/retrieveMetadataLoader.js +64 -0
  49. package/src/DicomWebDataSource/wado/retrieveMetadataLoaderAsync.js +159 -0
  50. package/src/DicomWebDataSource/wado/retrieveMetadataLoaderSync.js +58 -0
  51. package/src/DicomWebProxyDataSource/index.ts +90 -0
  52. package/src/MergeDataSource/index.test.ts +212 -0
  53. package/src/MergeDataSource/index.ts +319 -0
  54. package/src/MergeDataSource/types.ts +46 -0
  55. package/src/Panels/DataSourceSelector.tsx +55 -0
  56. package/src/Panels/StudyBrowser/PanelStudyBrowser.tsx +612 -0
  57. package/src/Panels/StudyBrowser/PanelStudyBrowserHeader.tsx +88 -0
  58. package/src/Panels/StudyBrowser/constants/actionIcons.ts +12 -0
  59. package/src/Panels/StudyBrowser/constants/index.ts +4 -0
  60. package/src/Panels/StudyBrowser/constants/viewPresets.ts +16 -0
  61. package/src/Panels/StudyBrowser/resolveThumbnailDetails.test.ts +197 -0
  62. package/src/Panels/StudyBrowser/resolveThumbnailDetails.ts +132 -0
  63. package/src/Panels/StudyBrowser/types/actionIcon.ts +9 -0
  64. package/src/Panels/StudyBrowser/types/index.ts +4 -0
  65. package/src/Panels/StudyBrowser/types/viewPreset.ts +7 -0
  66. package/src/Panels/WrappedPanelStudyBrowser.tsx +61 -0
  67. package/src/Panels/createReportDialogPrompt.tsx +128 -0
  68. package/src/Panels/debounce.js +25 -0
  69. package/src/Panels/getImageSrcFromImageId.js +16 -0
  70. package/src/Panels/getStudiesForPatientByMRN.js +19 -0
  71. package/src/Panels/index.js +5 -0
  72. package/src/Panels/requestDisplaySetCreationForStudy.js +19 -0
  73. package/src/SOPClassHandlers/chartSOPClassHandler.test.ts +81 -0
  74. package/src/SOPClassHandlers/chartSOPClassHandler.ts +127 -0
  75. package/src/Toolbar/ToolBoxWrapper.tsx +64 -0
  76. package/src/Toolbar/ToolButtonListWrapper.tsx +77 -0
  77. package/src/Toolbar/ToolButtonWrapper.tsx +32 -0
  78. package/src/Toolbar/ToolRowWrapper.tsx +41 -0
  79. package/src/Toolbar/Toolbar.tsx +98 -0
  80. package/src/Toolbar/ToolbarDivider.tsx +5 -0
  81. package/src/Toolbar/ToolbarLayoutSelector.tsx +195 -0
  82. package/src/Toolbar/index.ts +7 -0
  83. package/src/ViewerLayout/HeaderPatientInfo/HeaderPatientInfo.tsx +96 -0
  84. package/src/ViewerLayout/HeaderPatientInfo/index.js +3 -0
  85. package/src/ViewerLayout/HeaderUndoRedo.tsx +47 -0
  86. package/src/ViewerLayout/ResizablePanelsHook.tsx +334 -0
  87. package/src/ViewerLayout/ViewerHeader.tsx +124 -0
  88. package/src/ViewerLayout/constants/panels.ts +42 -0
  89. package/src/ViewerLayout/index.tsx +227 -0
  90. package/src/ViewerLayout/useUndoRedoState.ts +75 -0
  91. package/src/__tests__/commandsModuleToggleOneUp.test.ts +147 -0
  92. package/src/commandsModule.ts +970 -0
  93. package/src/customizations/aboutModalCustomization.tsx +42 -0
  94. package/src/customizations/appearanceModalCustomization.tsx +143 -0
  95. package/src/customizations/contextMenuCustomization.ts +25 -0
  96. package/src/customizations/contextMenuUICustomization.ts +5 -0
  97. package/src/customizations/customRoutesCustomization.ts +6 -0
  98. package/src/customizations/dataSourceConfigurationCustomization.ts +19 -0
  99. package/src/customizations/datasourcesCustomization.tsx +14 -0
  100. package/src/customizations/defaultContextMenuCustomization.ts +22 -0
  101. package/src/customizations/hangingProtocolsCustomization.ts +15 -0
  102. package/src/customizations/headerRightSideCustomization.ts +19 -0
  103. package/src/customizations/helloPageCustomization.tsx +14 -0
  104. package/src/customizations/hideHeaderUndoRedoCustomization.ts +22 -0
  105. package/src/customizations/hotkeyBindingsCustomization.ts +5 -0
  106. package/src/customizations/instanceSortingCriteriaCustomization.ts +6 -0
  107. package/src/customizations/labellingFlowCustomization.tsx +5 -0
  108. package/src/customizations/loadingIndicatorProgressCustomization.tsx +5 -0
  109. package/src/customizations/loadingIndicatorTotalPercentCustomization.tsx +5 -0
  110. package/src/customizations/menuContentCustomization.tsx +67 -0
  111. package/src/customizations/metadataContextCustomization.test.ts +22 -0
  112. package/src/customizations/metadataContextCustomization.ts +28 -0
  113. package/src/customizations/metadataDisplaySetCustomization.ts +55 -0
  114. package/src/customizations/missingReferenceDisplaySetHandler.ts +5 -0
  115. package/src/customizations/multimonitorCustomization.ts +63 -0
  116. package/src/customizations/notificationCustomization.ts +29 -0
  117. package/src/customizations/onDropHandlerCustomization.ts +5 -0
  118. package/src/customizations/onboardingCustomization.ts +200 -0
  119. package/src/customizations/overlayItemCustomization.tsx +33 -0
  120. package/src/customizations/progressDropdownCustomization.ts +5 -0
  121. package/src/customizations/progressLoadingBarCustomization.tsx +5 -0
  122. package/src/customizations/reportDialogCustomization.test.ts +701 -0
  123. package/src/customizations/reportDialogCustomization.tsx +661 -0
  124. package/src/customizations/sortingCriteriaCustomization.ts +14 -0
  125. package/src/customizations/studyBrowserCustomization.test.ts +69 -0
  126. package/src/customizations/studyBrowserCustomization.ts +95 -0
  127. package/src/customizations/thumbnailDetailsCustomization.ts +91 -0
  128. package/src/customizations/userPreferencesCustomization.tsx +342 -0
  129. package/src/customizations/workListCustomization.ts +107 -0
  130. package/src/displaySetSplitting/makeDisplaySetFromInstanceGroup.test.ts +181 -0
  131. package/src/displaySetSplitting/makeDisplaySetFromInstanceGroup.ts +240 -0
  132. package/src/displaySetSplitting/makeImageSetDisplaySet.ts +276 -0
  133. package/src/displaySetSplitting/stackSopClassUids.ts +60 -0
  134. package/src/displaySetSplitting/urlSplitModules.test.ts +333 -0
  135. package/src/findViewportsByPosition.ts +102 -0
  136. package/src/getCustomizationModule.tsx +109 -0
  137. package/src/getDataSourcesModule.js +44 -0
  138. package/src/getDisplaySetMessages.ts +54 -0
  139. package/src/getDisplaySetsFromUnsupportedSeries.js +63 -0
  140. package/src/getDisplaySetsFromUnsupportedSeries.test.js +14 -0
  141. package/src/getHangingProtocolModule.js +155 -0
  142. package/src/getLayoutTemplateModule.js +28 -0
  143. package/src/getPTImageIdInstanceMetadata.test.ts +102 -0
  144. package/src/getPTImageIdInstanceMetadata.ts +124 -0
  145. package/src/getPanelModule.tsx +29 -0
  146. package/src/getSopClassHandlerModule.js +152 -0
  147. package/src/getSopClassHandlerModule.test.js +78 -0
  148. package/src/getToolbarModule.tsx +63 -0
  149. package/src/getViewportModule.tsx +12 -0
  150. package/src/hangingprotocols/hpCompare.ts +189 -0
  151. package/src/hangingprotocols/hpEcgCustomization.test.ts +104 -0
  152. package/src/hangingprotocols/hpMNGrid.test.ts +120 -0
  153. package/src/hangingprotocols/hpMNGrid.ts +419 -0
  154. package/src/hangingprotocols/hpMammo.ts +202 -0
  155. package/src/hangingprotocols/hpScale.ts +132 -0
  156. package/src/hangingprotocols/index.ts +16 -0
  157. package/src/hangingprotocols/protocolMatchChanges.test.ts +73 -0
  158. package/src/hangingprotocols/utils/isNewestOfModality.ts +19 -0
  159. package/src/hangingprotocols/utils/laterality.ts +9 -0
  160. package/src/hangingprotocols/utils/mammoDisplaySetSelector.ts +214 -0
  161. package/src/hangingprotocols/utils/registerHangingProtocolAttributes.ts +14 -0
  162. package/src/hangingprotocols/utils/seriesSelectors.ts +62 -0
  163. package/src/hangingprotocols/utils/studySelectors.ts +14 -0
  164. package/src/hangingprotocols/utils/viewCode.test.js +25 -0
  165. package/src/hangingprotocols/utils/viewCode.ts +17 -0
  166. package/src/hangingprotocols/utils/viewportOptions.ts +18 -0
  167. package/src/hooks/usePatientInfo.tsx +63 -0
  168. package/src/id.js +5 -0
  169. package/src/index.ts +113 -0
  170. package/src/init.ts +169 -0
  171. package/src/stores/index.ts +7 -0
  172. package/src/stores/useDisplaySetSelectorStore.ts +83 -0
  173. package/src/stores/useHangingProtocolStageIndexStore.ts +76 -0
  174. package/src/stores/useToggleHangingProtocolStore.ts +76 -0
  175. package/src/stores/useToggleOneUpViewportGridStore.ts +19 -0
  176. package/src/stores/useUIStateStore.ts +87 -0
  177. package/src/stores/useViewportGridStore.ts +89 -0
  178. package/src/stores/useViewportsByPositionStore.ts +100 -0
  179. package/src/types/AppTypes.ts +20 -0
  180. package/src/types/commandModuleTypes.tsx +6 -0
  181. package/src/utils/Toolbox.tsx +123 -0
  182. package/src/utils/_shared/PROMPT_RESPONSES.ts +10 -0
  183. package/src/utils/addIcon.ts +6 -0
  184. package/src/utils/appendFrameQueryToImageId.js +9 -0
  185. package/src/utils/callInputDialog.tsx +126 -0
  186. package/src/utils/colorPickerDialog.css +4 -0
  187. package/src/utils/colorPickerDialog.tsx +45 -0
  188. package/src/utils/createRenderedRetrieve.js +32 -0
  189. package/src/utils/createRenderedRetrieve.test.js +46 -0
  190. package/src/utils/dicomWriter.test.ts +228 -0
  191. package/src/utils/dicomWriter.ts +110 -0
  192. package/src/utils/getBulkdataValue.js +45 -0
  193. package/src/utils/getBulkdataValue.test.js +105 -0
  194. package/src/utils/getDirectURL.test.ts +207 -0
  195. package/src/utils/getDirectURL.ts +65 -0
  196. package/src/utils/getSRSeriesAndInstanceNumber.js +48 -0
  197. package/src/utils/index.ts +2 -0
  198. package/src/utils/layerConfigurationUtils.ts +202 -0
  199. package/src/utils/promptLabelAnnotation.js +47 -0
  200. package/src/utils/promptSaveReport.test.ts +106 -0
  201. package/src/utils/promptSaveReport.tsx +117 -0
  202. package/src/utils/registerNaturalizedDatasetForLocalWadouri.js +146 -0
  203. package/src/utils/registerNaturalizedDatasetForLocalWadouri.test.js +177 -0
  204. package/src/utils/registerStoredInstanceImageId.test.ts +73 -0
  205. package/src/utils/registerStoredInstanceImageId.ts +66 -0
  206. package/src/utils/reuseCachedLayouts.ts +92 -0
  207. package/src/utils/secureConfigFetch.js +115 -0
  208. package/src/utils/secureConfigFetch.test.js +163 -0
  209. package/src/utils/seriesDescriptionHistory.ts +83 -0
  210. package/src/utils/validations/areAllImageComponentsEqual.ts +24 -0
  211. package/src/utils/validations/areAllImageDimensionsEqual.test.ts +41 -0
  212. package/src/utils/validations/areAllImageDimensionsEqual.ts +27 -0
  213. package/src/utils/validations/areAllImagePositionsEqual.ts +75 -0
  214. package/src/utils/validations/areAllImageSpacingEqual.ts +66 -0
  215. package/src/utils/validations/checkMultiframe.ts +25 -0
  216. package/src/utils/validations/checkSingleFrames.ts +36 -0
@@ -0,0 +1,101 @@
1
+ import React, { useEffect, useState, ReactElement } from 'react';
2
+ import { ProgressDropdown } from '@ohif/ui-next';
3
+ import { useSystem } from '@ohif/core';
4
+
5
+ const workflowStepsToDropdownOptions = (steps = []) =>
6
+ steps.map(step => ({
7
+ label: step.name,
8
+ value: step.id,
9
+ info: step.info,
10
+ activated: false,
11
+ completed: false,
12
+ }));
13
+
14
+ export function ProgressDropdownWithService(): ReactElement<any> {
15
+ const { servicesManager } = useSystem();
16
+ const { workflowStepsService } = servicesManager.services;
17
+ const [activeStepId, setActiveStepId] = useState(workflowStepsService.activeWorkflowStep?.id);
18
+
19
+ const [dropdownOptions, setDropdownOptions] = useState(
20
+ workflowStepsToDropdownOptions(workflowStepsService.workflowSteps)
21
+ );
22
+
23
+ const setCurrentAndPreviousOptionsAsCompleted = currentOption => {
24
+ if (currentOption.completed) {
25
+ return;
26
+ }
27
+
28
+ setDropdownOptions(prevOptions => {
29
+ const newOptionsState = [...prevOptions];
30
+ const startIndex = newOptionsState.findIndex(option => option.value === currentOption.value);
31
+
32
+ for (let i = startIndex; i >= 0; i--) {
33
+ const option = newOptionsState[i];
34
+
35
+ if (option.completed) {
36
+ break;
37
+ }
38
+
39
+ newOptionsState[i] = {
40
+ ...option,
41
+ completed: true,
42
+ };
43
+ }
44
+
45
+ return newOptionsState;
46
+ });
47
+ };
48
+
49
+ const handleDropdownChange = ({ selectedOption }) => {
50
+ if (!selectedOption) {
51
+ return;
52
+ }
53
+
54
+ // TODO: Steps should be marked as completed after user has
55
+ // completed some action when required (not implemented)
56
+ setCurrentAndPreviousOptionsAsCompleted(selectedOption);
57
+ setActiveStepId(selectedOption.value);
58
+ };
59
+
60
+ useEffect(() => {
61
+ let timeoutId;
62
+
63
+ if (activeStepId) {
64
+ // We've used setTimeout to give it more time to update the UI since
65
+ // create3DFilterableFromDataArray from Texture.js may take 600+ ms to run
66
+ // when there is a new series to load in the next step but that resulted
67
+ // in the followed React error when updating the content from left/right panels
68
+ // and all component states were being lost:
69
+ // Error: Can't perform a React state update on an unmounted component
70
+ workflowStepsService.setActiveWorkflowStep(activeStepId);
71
+ }
72
+
73
+ return () => clearTimeout(timeoutId);
74
+ }, [activeStepId, workflowStepsService]);
75
+
76
+ useEffect(() => {
77
+ const { unsubscribe: unsubStepsChanged } = workflowStepsService.subscribe(
78
+ workflowStepsService.EVENTS.STEPS_CHANGED,
79
+ () => setDropdownOptions(workflowStepsToDropdownOptions(workflowStepsService.workflowSteps))
80
+ );
81
+
82
+ const { unsubscribe: unsubActiveStepChanged } = workflowStepsService.subscribe(
83
+ workflowStepsService.EVENTS.ACTIVE_STEP_CHANGED,
84
+
85
+ () => setActiveStepId(workflowStepsService.activeWorkflowStep.id)
86
+ );
87
+
88
+ return () => {
89
+ unsubStepsChanged();
90
+ unsubActiveStepChanged();
91
+ };
92
+ }, [servicesManager, workflowStepsService]);
93
+
94
+ return (
95
+ <ProgressDropdown
96
+ options={dropdownOptions}
97
+ value={activeStepId}
98
+ onChange={handleDropdownChange}
99
+ />
100
+ );
101
+ }
@@ -0,0 +1,122 @@
1
+ import React, { useEffect, useState, useCallback } from 'react';
2
+ import { SidePanel } from '@ohif/ui-next';
3
+ import { Types } from '@ohif/core';
4
+
5
+ export type SidePanelWithServicesProps = {
6
+ servicesManager: AppTypes.ServicesManager;
7
+ side: 'left' | 'right';
8
+ className?: string;
9
+ activeTabIndex: number;
10
+ tabs?: any;
11
+ expandedWidth?: number;
12
+ onClose: () => void;
13
+ onOpen: () => void;
14
+ isExpanded: boolean;
15
+ collapsedWidth?: number;
16
+ expandedInsideBorderSize?: number;
17
+ collapsedInsideBorderSize?: number;
18
+ collapsedOutsideBorderSize?: number;
19
+ };
20
+
21
+ const SidePanelWithServices = ({
22
+ servicesManager,
23
+ side,
24
+ activeTabIndex: activeTabIndexProp,
25
+ isExpanded,
26
+ tabs: tabsProp,
27
+ onOpen,
28
+ onClose,
29
+ ...props
30
+ }: SidePanelWithServicesProps) => {
31
+ const { panelService, toolbarService, viewportGridService } = servicesManager.services;
32
+
33
+ // Tracks whether this SidePanel has been opened at least once since this SidePanel was inserted into the DOM.
34
+ // Thus going to the Study List page and back to the viewer resets this flag for a SidePanel.
35
+ const [sidePanelExpanded, setSidePanelExpanded] = useState(isExpanded);
36
+ const [activeTabIndex, setActiveTabIndex] = useState(activeTabIndexProp ?? 0);
37
+ const [closedManually, setClosedManually] = useState(false);
38
+ const [tabs, setTabs] = useState(tabsProp ?? panelService.getPanels(side));
39
+
40
+ const handleActiveTabIndexChange = useCallback(
41
+ ({ activeTabIndex }) => {
42
+ const { activeViewportId: viewportId } = viewportGridService.getState();
43
+ toolbarService.refreshToolbarState({ viewportId });
44
+
45
+ setActiveTabIndex(activeTabIndex);
46
+ },
47
+ [toolbarService, viewportGridService]
48
+ );
49
+
50
+ const handleOpen = useCallback(() => {
51
+ setSidePanelExpanded(true);
52
+ onOpen?.();
53
+ }, [onOpen]);
54
+
55
+ const handleClose = useCallback(() => {
56
+ setSidePanelExpanded(false);
57
+ setClosedManually(true);
58
+ onClose?.();
59
+ }, [onClose]);
60
+
61
+ useEffect(() => {
62
+ setSidePanelExpanded(isExpanded);
63
+ }, [isExpanded]);
64
+
65
+ /** update the active tab index from outside */
66
+ useEffect(() => {
67
+ setActiveTabIndex(activeTabIndexProp ?? 0);
68
+ }, [activeTabIndexProp]);
69
+
70
+ useEffect(() => {
71
+ const { unsubscribe } = panelService.subscribe(
72
+ panelService.EVENTS.PANELS_CHANGED,
73
+ panelChangedEvent => {
74
+ if (panelChangedEvent.position !== side) {
75
+ return;
76
+ }
77
+
78
+ setTabs(panelService.getPanels(side));
79
+ }
80
+ );
81
+
82
+ return () => {
83
+ unsubscribe();
84
+ };
85
+ }, [panelService, side]);
86
+
87
+ useEffect(() => {
88
+ const activatePanelSubscription = panelService.subscribe(
89
+ panelService.EVENTS.ACTIVATE_PANEL,
90
+ (activatePanelEvent: Types.ActivatePanelEvent) => {
91
+ if (sidePanelExpanded || activatePanelEvent.forceActive) {
92
+ const tabIndex = tabs.findIndex(tab => tab.id === activatePanelEvent.panelId);
93
+ if (tabIndex !== -1) {
94
+ if (!closedManually) {
95
+ setSidePanelExpanded(true);
96
+ }
97
+ setActiveTabIndex(tabIndex);
98
+ }
99
+ }
100
+ }
101
+ );
102
+
103
+ return () => {
104
+ activatePanelSubscription.unsubscribe();
105
+ };
106
+ }, [tabs, sidePanelExpanded, panelService, closedManually]);
107
+
108
+ return (
109
+ <SidePanel
110
+ {...props}
111
+ side={side}
112
+ tabs={tabs}
113
+ activeTabIndex={activeTabIndex}
114
+ isExpanded={sidePanelExpanded}
115
+ onOpen={handleOpen}
116
+ onClose={handleClose}
117
+ onActiveTabIndexChange={handleActiveTabIndexChange}
118
+ />
119
+ );
120
+ };
121
+
122
+ export default SidePanelWithServices;
@@ -0,0 +1,216 @@
1
+ import * as ContextMenuItemsBuilder from './ContextMenuItemsBuilder';
2
+ import { CommandsManager } from '@ohif/core';
3
+ import { annotation as CsAnnotation } from '@cornerstonejs/tools';
4
+ import { Menu, MenuItem, Point, ContextMenuProps } from './types';
5
+
6
+ /**
7
+ * The context menu controller is a helper class that knows how
8
+ * to manage context menus based on the UI Customization Service.
9
+ * There are a few parts to this:
10
+ * 1. Basic controls to manage displaying and hiding context menus
11
+ * 2. Menu selection services, which use the UI customization service
12
+ * to choose which menu to display
13
+ * 3. Menu item adapter services to convert menu items into displayable and actionable items.
14
+ *
15
+ * The format for a menu is defined in the exported type MenuItem
16
+ */
17
+ export default class ContextMenuController {
18
+ commandsManager: CommandsManager;
19
+ services: AppTypes.Services;
20
+ menuItems: Menu[] | MenuItem[];
21
+
22
+ constructor(servicesManager: AppTypes.ServicesManager, commandsManager: CommandsManager) {
23
+ this.services = servicesManager.services;
24
+ this.commandsManager = commandsManager;
25
+ }
26
+
27
+ closeContextMenu() {
28
+ this.services.uiDialogService.hide('context-menu');
29
+ }
30
+
31
+ /**
32
+ * Figures out which context menu is appropriate to display and shows it.
33
+ *
34
+ * @param contextMenuProps - the context menu properties, see ./types.ts
35
+ * @param viewportElement - the DOM element this context menu is related to
36
+ * @param defaultPointsPosition - a default position to show the context menu
37
+ */
38
+ showContextMenu(
39
+ contextMenuProps: ContextMenuProps,
40
+ viewportElement,
41
+ defaultPointsPosition
42
+ ): void {
43
+ if (!this.services.uiDialogService) {
44
+ console.warn('Unable to show dialog; no UI Dialog Service available.');
45
+ return;
46
+ }
47
+
48
+ const { event, subMenu, menuId, menus, selectorProps } = contextMenuProps;
49
+ if (!menus) {
50
+ console.warn('No menus found for', menuId);
51
+ return;
52
+ }
53
+
54
+ const { locking, visibility } = CsAnnotation;
55
+ const targetAnnotationId = selectorProps?.nearbyToolData?.annotationUID as string;
56
+
57
+ if (targetAnnotationId) {
58
+ const isLocked = locking.isAnnotationLocked(targetAnnotationId);
59
+ const isVisible = visibility.isAnnotationVisible(targetAnnotationId);
60
+
61
+ if (isLocked || !isVisible) {
62
+ console.warn(`Annotation is ${isLocked ? 'locked' : 'not visible'}.`);
63
+ return;
64
+ }
65
+ }
66
+
67
+ const items = ContextMenuItemsBuilder.getMenuItems(
68
+ selectorProps || contextMenuProps,
69
+ event,
70
+ menus,
71
+ menuId
72
+ );
73
+
74
+ if (!items) {
75
+ return;
76
+ }
77
+
78
+ const ContextMenu = this.services.customizationService.getCustomization('ui.contextMenu');
79
+
80
+ this.services.uiDialogService.hide('context-menu');
81
+ this.services.uiDialogService.show({
82
+ id: 'context-menu',
83
+ showOverlay: false,
84
+ defaultPosition: ContextMenuController._getDefaultPosition(
85
+ defaultPointsPosition,
86
+ event?.detail || event,
87
+ viewportElement
88
+ ),
89
+ content: ContextMenu,
90
+ shouldCloseOnEsc: true,
91
+ shouldCloseOnOverlayClick: true,
92
+ unstyled: true,
93
+ contentProps: {
94
+ items,
95
+ selectorProps,
96
+ menus,
97
+ event,
98
+ subMenu,
99
+ eventData: event?.detail || event,
100
+
101
+ onClose: () => {
102
+ this.services.uiDialogService.hide('context-menu');
103
+ },
104
+
105
+ /**
106
+ * Displays a sub-menu, removing this menu
107
+ * @param {*} item
108
+ * @param {*} itemRef
109
+ * @param {*} subProps
110
+ */
111
+ onShowSubMenu: (item, itemRef, subProps) => {
112
+ if (!itemRef.subMenu) {
113
+ console.warn('No submenu defined for', item, itemRef, subProps);
114
+ return;
115
+ }
116
+ this.showContextMenu(
117
+ {
118
+ ...contextMenuProps,
119
+ menuId: itemRef.subMenu,
120
+ },
121
+ viewportElement,
122
+ defaultPointsPosition
123
+ );
124
+ },
125
+
126
+ // Default is to run the specified commands.
127
+ onDefault: (item, itemRef, subProps) => {
128
+ this.commandsManager.run(item, {
129
+ ...selectorProps,
130
+ ...itemRef,
131
+ subProps,
132
+ });
133
+ },
134
+ },
135
+ });
136
+ }
137
+
138
+ static getDefaultPosition = (): Point => {
139
+ return {
140
+ x: 0,
141
+ y: 0,
142
+ };
143
+ };
144
+
145
+ static _getEventDefaultPosition = eventDetail => ({
146
+ x: eventDetail?.currentPoints?.client[0] ?? eventDetail?.pageX,
147
+ y: eventDetail?.currentPoints?.client[1] ?? eventDetail?.pageY,
148
+ });
149
+
150
+ static _getElementDefaultPosition = element => {
151
+ if (element) {
152
+ const boundingClientRect = element.getBoundingClientRect();
153
+ return {
154
+ x: boundingClientRect.x,
155
+ y: boundingClientRect.y,
156
+ };
157
+ }
158
+
159
+ return {
160
+ x: undefined,
161
+ y: undefined,
162
+ };
163
+ };
164
+
165
+ static _getCanvasPointsPosition = (points = [], element) => {
166
+ const viewerPos = ContextMenuController._getElementDefaultPosition(element);
167
+
168
+ for (let pointIndex = 0; pointIndex < points.length; pointIndex++) {
169
+ const point = {
170
+ x: points[pointIndex][0] || points[pointIndex]['x'],
171
+ y: points[pointIndex][1] || points[pointIndex]['y'],
172
+ };
173
+ if (
174
+ ContextMenuController._isValidPosition(point) &&
175
+ ContextMenuController._isValidPosition(viewerPos)
176
+ ) {
177
+ return {
178
+ x: point.x + viewerPos.x,
179
+ y: point.y + viewerPos.y,
180
+ };
181
+ }
182
+ }
183
+ };
184
+
185
+ static _isValidPosition = (source): boolean => {
186
+ return source && typeof source.x === 'number' && typeof source.y === 'number';
187
+ };
188
+
189
+ /**
190
+ * Returns the context menu default position. It look for the positions of: canvasPoints (got from selected), event that triggers it, current viewport element
191
+ */
192
+ static _getDefaultPosition = (canvasPoints, eventDetail, viewerElement) => {
193
+ function* getPositionIterator() {
194
+ yield ContextMenuController._getCanvasPointsPosition(canvasPoints, viewerElement);
195
+ yield ContextMenuController._getEventDefaultPosition(eventDetail);
196
+ yield ContextMenuController._getElementDefaultPosition(viewerElement);
197
+ yield ContextMenuController.getDefaultPosition();
198
+ }
199
+
200
+ const positionIterator = getPositionIterator();
201
+
202
+ let current = positionIterator.next();
203
+ let position = current.value;
204
+
205
+ while (!current.done) {
206
+ position = current.value;
207
+
208
+ if (ContextMenuController._isValidPosition(position)) {
209
+ positionIterator.return();
210
+ }
211
+ current = positionIterator.next();
212
+ }
213
+
214
+ return position;
215
+ };
216
+ }
@@ -0,0 +1,29 @@
1
+ import * as ContextMenuItemsBuilder from './ContextMenuItemsBuilder';
2
+
3
+ const menus = [
4
+ {
5
+ id: 'one',
6
+ selector: ({ value } = {}) => value === 'one',
7
+ items: [],
8
+ },
9
+ {
10
+ id: 'two',
11
+ selector: ({ value } = {}) => value === 'two',
12
+ items: [],
13
+ },
14
+ {
15
+ id: 'default',
16
+ items: [],
17
+ },
18
+ ];
19
+
20
+ describe('ContextMenuItemsBuilder', () => {
21
+ test('findMenuDefault', () => {
22
+ expect(ContextMenuItemsBuilder.findMenuDefault(menus, {})).toBe(menus[2]);
23
+ expect(
24
+ ContextMenuItemsBuilder.findMenuDefault(menus, { selectorProps: { value: 'two' } })
25
+ ).toBe(menus[1]);
26
+ expect(ContextMenuItemsBuilder.findMenuDefault([], {})).toBeUndefined();
27
+ expect(ContextMenuItemsBuilder.findMenuDefault(undefined, undefined)).toBeNull();
28
+ });
29
+ });
@@ -0,0 +1,176 @@
1
+ import { Types } from '@ohif/ui-next';
2
+ import { Menu, SelectorProps, MenuItem, ContextMenuProps } from './types';
3
+
4
+ type ContextMenuItem = Types.ContextMenuItem;
5
+
6
+ /**
7
+ * Finds menu by menu id
8
+ *
9
+ * @returns Menu having the menuId
10
+ */
11
+ export function findMenuById(menus: Menu[], menuId?: string): Menu {
12
+ if (!menuId) {
13
+ return;
14
+ }
15
+
16
+ return menus.find(menu => menu.id === menuId);
17
+ }
18
+
19
+ /**
20
+ * Default finding menu method. This method will go through
21
+ * the list of menus until it finds the first one which
22
+ * has no selector, OR has the selector, when applied to the
23
+ * check props, return true.
24
+ * The selectorProps are a set of provided properties which can be
25
+ * passed into the selector function to determine when to display a menu.
26
+ * For example, a selector function of:
27
+ * `({displayset}) => displaySet?.SeriesDescription?.indexOf?.('Left')!==-1
28
+ * would match series descriptions containing 'Left'.
29
+ *
30
+ * @param {Object[]} menus List of menus
31
+ * @param {*} subProps
32
+ * @returns
33
+ */
34
+ export function findMenuDefault(menus: Menu[], subProps: Record<string, unknown>): Menu {
35
+ if (!menus) {
36
+ return null;
37
+ }
38
+ return menus.find(menu => !menu.selector || menu.selector(subProps.selectorProps));
39
+ }
40
+
41
+ /**
42
+ * Finds the menu to be used for different scenarios:
43
+ * This will first look for a subMenu with the specified subMenuId
44
+ * Next it will look for the first menu whose selector returns true.
45
+ *
46
+ * @param menus - List of menus
47
+ * @param props - root props
48
+ * @param menuIdFilter - menu id identifier (to be considered on selection)
49
+ * This is intended to support other types of filtering in the future.
50
+ */
51
+ export function findMenu(menus: Menu[], props?: Types.IProps, menuIdFilter?: string) {
52
+ const { subMenu } = props;
53
+
54
+ function* findMenuIterator() {
55
+ yield findMenuById(menus, menuIdFilter || subMenu);
56
+ yield findMenuDefault(menus, props);
57
+ }
58
+
59
+ const findIt = findMenuIterator();
60
+
61
+ let current = findIt.next();
62
+ let menu = current.value;
63
+
64
+ while (!current.done) {
65
+ menu = current.value;
66
+
67
+ if (menu) {
68
+ findIt.return();
69
+ }
70
+ current = findIt.next();
71
+ }
72
+
73
+ return menu;
74
+ }
75
+
76
+ /**
77
+ * Returns the menu from a list of possible menus, based on the actual state of component props and tool data nearby.
78
+ * This uses the findMenu command above to first find the appropriate
79
+ * menu, and then it chooses the actual contents of that menu.
80
+ * A menu item can be optional by implementing the 'selector',
81
+ * which will be called with the selectorProps, and if it does not return true,
82
+ * then the item is excluded.
83
+ *
84
+ * Other menus can be delegated to by setting the delegating value to
85
+ * a string id for another menu. That menu's content will replace the
86
+ * current menu item (only if the item would be included).
87
+ *
88
+ * This allows single id menus to be chosen by id, but have varying contents
89
+ * based on the delegated menus.
90
+ *
91
+ * Finally, for each item, the adaptItem call is made. This allows
92
+ * items to modify themselves before being displayed, such as
93
+ * incorporating additional information from translation sources.
94
+ * See the `test-mode` examples for details.
95
+ *
96
+ * @param selectorProps
97
+ * @param {*} event event that originates the context menu
98
+ * @param {*} menus List of menus
99
+ * @param {*} menuIdFilter
100
+ * @returns
101
+ */
102
+ export function getMenuItems(
103
+ selectorProps: SelectorProps,
104
+ event: Event,
105
+ menus: Menu[],
106
+ menuIdFilter?: string
107
+ ): MenuItem[] | void {
108
+ // Include both the check props and the ...check props as one is used
109
+ // by the child menu and the other used by the selector function
110
+ const subProps = { selectorProps, event };
111
+
112
+ const menu = findMenu(menus, subProps, menuIdFilter);
113
+
114
+ if (!menu) {
115
+ return undefined;
116
+ }
117
+
118
+ if (!menu.items) {
119
+ console.warn('Must define items in menu', menu);
120
+ return [];
121
+ }
122
+
123
+ let menuItems = [];
124
+ menu.items.forEach(item => {
125
+ const { delegating, selector, subMenu } = item;
126
+
127
+ if (!selector || selector(selectorProps)) {
128
+ if (delegating) {
129
+ menuItems = [...menuItems, ...getMenuItems(selectorProps, event, menus, subMenu)];
130
+ } else {
131
+ const toAdd = adaptItem(item, subProps);
132
+ menuItems.push(toAdd);
133
+ }
134
+ }
135
+ });
136
+
137
+ return menuItems;
138
+ }
139
+
140
+ /**
141
+ * Returns item adapted to be consumed by ContextMenu component
142
+ * and then goes through the item to add action behaviour for clicking the item,
143
+ * making it compatible with the default ContextMenu display.
144
+ *
145
+ * @param {Object} item
146
+ * @param {Object} subProps
147
+ * @returns a MenuItem that is compatible with the base ContextMenu
148
+ * This requires having a label and set of actions to be called.
149
+ */
150
+ export function adaptItem(item: MenuItem, subProps: ContextMenuProps): ContextMenuItem {
151
+ const newItem: ContextMenuItem = {
152
+ ...item,
153
+ value: subProps.selectorProps?.value,
154
+ };
155
+
156
+ if (item.actionType === 'ShowSubMenu' && !newItem.iconRight) {
157
+ newItem.iconRight = 'chevron-down';
158
+ }
159
+ if (!item.action) {
160
+ newItem.action = (itemRef, componentProps) => {
161
+ const { event = {} } = componentProps;
162
+ const { detail = {} } = event;
163
+ newItem.element = detail.element;
164
+
165
+ componentProps.onClose();
166
+ const action = componentProps[`on${itemRef.actionType || 'Default'}`];
167
+ if (action) {
168
+ action.call(componentProps, newItem, itemRef, subProps);
169
+ } else {
170
+ console.warn('No action defined for', itemRef);
171
+ }
172
+ };
173
+ }
174
+
175
+ return newItem;
176
+ }
@@ -0,0 +1,5 @@
1
+ import ContextMenuController from './ContextMenuController';
2
+ import * as ContextMenuItemsBuilder from './ContextMenuItemsBuilder';
3
+ import * as CustomizableContextMenuTypes from './types';
4
+
5
+ export { ContextMenuController, CustomizableContextMenuTypes, ContextMenuItemsBuilder };