@ohif/extension-default 3.14.0-beta.1 → 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,124 @@
1
+ import React from 'react';
2
+ import { useNavigate, useLocation } from 'react-router-dom';
3
+ import { useTranslation } from 'react-i18next';
4
+
5
+ import { Header, useModal } from '@ohif/ui-next';
6
+ import { useSystem } from '@ohif/core';
7
+ import { Toolbar } from '../Toolbar/Toolbar';
8
+ import { preserveQueryParameters } from '@ohif/app';
9
+ import { Types } from '@ohif/core';
10
+
11
+ function ViewerHeader({ appConfig }: withAppTypes<{ appConfig: AppTypes.Config }>) {
12
+ const { servicesManager, extensionManager } = useSystem();
13
+ const { customizationService } = servicesManager.services;
14
+
15
+ const navigate = useNavigate();
16
+ const location = useLocation();
17
+
18
+ const onClickReturnButton = () => {
19
+ const { pathname } = location;
20
+ const dataSourceIdx = pathname.indexOf('/', 1);
21
+
22
+ const dataSourceName = pathname.substring(dataSourceIdx + 1);
23
+ const existingDataSource = extensionManager.getDataSources(dataSourceName);
24
+
25
+ const searchQuery = new URLSearchParams();
26
+ if (dataSourceIdx !== -1 && existingDataSource) {
27
+ searchQuery.append('datasources', pathname.substring(dataSourceIdx + 1));
28
+ }
29
+ preserveQueryParameters(searchQuery, customizationService);
30
+
31
+ navigate({
32
+ pathname: '/',
33
+ search: decodeURIComponent(searchQuery.toString()),
34
+ });
35
+ };
36
+
37
+ const { t } = useTranslation();
38
+ const { show } = useModal();
39
+
40
+ const AboutModal = customizationService.getCustomization(
41
+ 'ohif.aboutModal'
42
+ ) as Types.MenuComponentCustomization;
43
+
44
+ const AppearanceModal = customizationService.getCustomization(
45
+ 'ohif.appearanceModal'
46
+ ) as Types.MenuComponentCustomization;
47
+
48
+ const UserPreferencesModal = customizationService.getCustomization(
49
+ 'ohif.userPreferencesModal'
50
+ ) as Types.MenuComponentCustomization;
51
+
52
+ // Whatever fills the right side of the menu bar, in order: undo/redo then
53
+ // patient info by default. Each item is rendered as a component, so it can
54
+ // bring its own hooks, and reordering the list reorders the header.
55
+ const rightSideItems =
56
+ customizationService.getCustomization('ohif.headerRightSide')?.items ?? [];
57
+
58
+ const menuOptions = [
59
+ {
60
+ title: AboutModal?.menuTitle ?? t('Header:About'),
61
+ icon: 'info',
62
+ onClick: () =>
63
+ show({
64
+ content: AboutModal,
65
+ title: AboutModal?.title ?? t('AboutModal:About OHIF Viewer'),
66
+ containerClassName: AboutModal?.containerClassName ?? 'max-w-md',
67
+ }),
68
+ },
69
+ {
70
+ title: UserPreferencesModal.menuTitle ?? t('Header:Preferences'),
71
+ icon: 'settings',
72
+ onClick: () =>
73
+ show({
74
+ content: UserPreferencesModal,
75
+ title: UserPreferencesModal.title ?? t('UserPreferencesModal:User preferences'),
76
+ containerClassName:
77
+ UserPreferencesModal?.containerClassName ?? 'flex max-w-4xl p-6 flex-col',
78
+ }),
79
+ },
80
+ ];
81
+
82
+ if (AppearanceModal) {
83
+ menuOptions.splice(1, 0, {
84
+ title: AppearanceModal.menuTitle ?? t('Header:Appearance'),
85
+ icon: 'ColorChange',
86
+ onClick: () =>
87
+ show({
88
+ content: AppearanceModal,
89
+ title: AppearanceModal.title ?? t('AppearanceModal:Appearance'),
90
+ containerClassName: AppearanceModal.containerClassName ?? 'max-w-md',
91
+ }),
92
+ });
93
+ }
94
+
95
+ if (appConfig.oidc) {
96
+ menuOptions.push({
97
+ title: t('Header:Logout'),
98
+ icon: 'power-off',
99
+ onClick: async () => {
100
+ navigate(`/logout?redirect_uri=${encodeURIComponent(window.location.href)}`);
101
+ },
102
+ });
103
+ }
104
+
105
+ return (
106
+ <Header
107
+ menuOptions={menuOptions}
108
+ isReturnEnabled={!!appConfig.showStudyList}
109
+ onClickReturnButton={onClickReturnButton}
110
+ WhiteLabeling={appConfig.whiteLabeling}
111
+ Secondary={<Toolbar buttonSection="secondary" />}
112
+ RightSide={rightSideItems.map((Item, index) => (
113
+ // The list is static per configuration, so the index is a stable key.
114
+ <Item key={index} />
115
+ ))}
116
+ >
117
+ <div className="relative flex justify-center gap-[4px]">
118
+ <Toolbar buttonSection="primary" />
119
+ </div>
120
+ </Header>
121
+ );
122
+ }
123
+
124
+ export default ViewerHeader;
@@ -0,0 +1,42 @@
1
+ const expandedInsideBorderSize = 0;
2
+ const collapsedInsideBorderSize = 4;
3
+ const collapsedOutsideBorderSize = 4;
4
+ const collapsedWidth = 25;
5
+
6
+ const getPanelGroupDefinition = ({
7
+ leftPanelInitialExpandedWidth = 282,
8
+ rightPanelInitialExpandedWidth = 280,
9
+ leftPanelMinimumExpandedWidth = 145,
10
+ rightPanelMinimumExpandedWidth = 280,
11
+ }) => {
12
+ return {
13
+ groupId: 'viewerLayoutResizablePanelGroup',
14
+ shared: {
15
+ expandedInsideBorderSize,
16
+ collapsedInsideBorderSize,
17
+ collapsedOutsideBorderSize,
18
+ collapsedWidth,
19
+ },
20
+ left: {
21
+ // id
22
+ panelId: 'viewerLayoutResizableLeftPanel',
23
+ // expanded width
24
+ initialExpandedWidth: leftPanelInitialExpandedWidth,
25
+ // expanded width + expanded inside border
26
+ minimumExpandedOffsetWidth: leftPanelMinimumExpandedWidth + expandedInsideBorderSize,
27
+ // initial expanded width
28
+ initialExpandedOffsetWidth: leftPanelInitialExpandedWidth + expandedInsideBorderSize,
29
+ // collapsed width + collapsed inside border + collapsed outside border
30
+ collapsedOffsetWidth: collapsedWidth + collapsedInsideBorderSize + collapsedOutsideBorderSize,
31
+ },
32
+ right: {
33
+ panelId: 'viewerLayoutResizableRightPanel',
34
+ initialExpandedWidth: rightPanelInitialExpandedWidth,
35
+ minimumExpandedOffsetWidth: rightPanelMinimumExpandedWidth + expandedInsideBorderSize,
36
+ initialExpandedOffsetWidth: rightPanelInitialExpandedWidth + expandedInsideBorderSize,
37
+ collapsedOffsetWidth: collapsedWidth + collapsedInsideBorderSize + collapsedOutsideBorderSize,
38
+ },
39
+ };
40
+ };
41
+
42
+ export { getPanelGroupDefinition };
@@ -0,0 +1,227 @@
1
+ import React, { useEffect, useState, useCallback } from 'react';
2
+
3
+ import { InvestigationalUseDialog } from '@ohif/ui-next';
4
+ import { HangingProtocolService, CommandsManager } from '@ohif/core';
5
+ import { useAppConfig } from '@state';
6
+ import ViewerHeader from './ViewerHeader';
7
+ import SidePanelWithServices from '../Components/SidePanelWithServices';
8
+ import { Onboarding, ResizablePanelGroup, ResizablePanel, ResizableHandle } from '@ohif/ui-next';
9
+ import useResizablePanels from './ResizablePanelsHook';
10
+
11
+ const resizableHandleClassName = 'mt-[1px] bg-background';
12
+
13
+ function ViewerLayout({
14
+ // From Extension Module Params
15
+ extensionManager,
16
+ servicesManager,
17
+ hotkeysManager,
18
+ commandsManager,
19
+ // From Modes
20
+ viewports,
21
+ ViewportGridComp,
22
+ leftPanelClosed = false,
23
+ rightPanelClosed = false,
24
+ leftPanelResizable = false,
25
+ rightPanelResizable = false,
26
+ leftPanelInitialExpandedWidth,
27
+ rightPanelInitialExpandedWidth,
28
+ leftPanelMinimumExpandedWidth,
29
+ rightPanelMinimumExpandedWidth,
30
+ }: withAppTypes): React.FunctionComponent {
31
+ const [appConfig] = useAppConfig();
32
+
33
+ const { panelService, hangingProtocolService, customizationService } = servicesManager.services;
34
+ const [showLoadingIndicator, setShowLoadingIndicator] = useState(appConfig.showLoadingIndicator);
35
+
36
+ const hasPanels = useCallback(
37
+ (side): boolean => !!panelService.getPanels(side).length,
38
+ [panelService]
39
+ );
40
+
41
+ const [hasRightPanels, setHasRightPanels] = useState(hasPanels('right'));
42
+ const [hasLeftPanels, setHasLeftPanels] = useState(hasPanels('left'));
43
+ const [leftPanelClosedState, setLeftPanelClosed] = useState(leftPanelClosed);
44
+ const [rightPanelClosedState, setRightPanelClosed] = useState(rightPanelClosed);
45
+
46
+ const [
47
+ leftPanelProps,
48
+ rightPanelProps,
49
+ resizablePanelGroupProps,
50
+ resizableLeftPanelProps,
51
+ resizableViewportGridPanelProps,
52
+ resizableRightPanelProps,
53
+ onHandleDragging,
54
+ ] = useResizablePanels(
55
+ leftPanelClosed,
56
+ setLeftPanelClosed,
57
+ rightPanelClosed,
58
+ setRightPanelClosed,
59
+ hasLeftPanels,
60
+ hasRightPanels,
61
+ leftPanelInitialExpandedWidth,
62
+ rightPanelInitialExpandedWidth,
63
+ leftPanelMinimumExpandedWidth,
64
+ rightPanelMinimumExpandedWidth
65
+ );
66
+
67
+ const handleMouseEnter = () => {
68
+ (document.activeElement as HTMLElement)?.blur();
69
+ };
70
+
71
+ const LoadingIndicatorProgress = customizationService.getCustomization(
72
+ 'ui.loadingIndicatorProgress'
73
+ );
74
+
75
+ /**
76
+ * Set body classes (tailwindcss) that don't allow vertical
77
+ * or horizontal overflow (no scrolling). Also guarantee window
78
+ * is sized to our viewport.
79
+ */
80
+ useEffect(() => {
81
+ document.body.classList.add('bg-background');
82
+ document.body.classList.add('overflow-hidden');
83
+
84
+ return () => {
85
+ document.body.classList.remove('bg-background');
86
+ document.body.classList.remove('overflow-hidden');
87
+ };
88
+ }, []);
89
+
90
+ const getComponent = id => {
91
+ const entry = extensionManager.getModuleEntry(id);
92
+
93
+ if (!entry || !entry.component) {
94
+ throw new Error(
95
+ `${id} is not valid for an extension module or no component found from extension ${id}. Please verify your configuration or ensure that the extension is properly registered. It's also possible that your mode is utilizing a module from an extension that hasn't been included in its dependencies (add the extension to the "extensionDependencies" array in your mode's index.js file). Check the reference string to the extension in your Mode configuration`
96
+ );
97
+ }
98
+
99
+ return { entry };
100
+ };
101
+
102
+ useEffect(() => {
103
+ const { unsubscribe } = hangingProtocolService.subscribe(
104
+ HangingProtocolService.EVENTS.PROTOCOL_CHANGED,
105
+
106
+ // Todo: right now to set the loading indicator to false, we need to wait for the
107
+ // hangingProtocolService to finish applying the viewport matching to each viewport,
108
+ // however, this might not be the only approach to set the loading indicator to false. we need to explore this further.
109
+ () => {
110
+ setShowLoadingIndicator(false);
111
+ }
112
+ );
113
+
114
+ return () => {
115
+ unsubscribe();
116
+ };
117
+ }, [hangingProtocolService]);
118
+
119
+ const getViewportComponentData = viewportComponent => {
120
+ const { entry } = getComponent(viewportComponent.namespace);
121
+
122
+ return {
123
+ component: entry.component,
124
+ isReferenceViewable: entry.isReferenceViewable,
125
+ displaySetsToDisplay: viewportComponent.displaySetsToDisplay,
126
+ };
127
+ };
128
+
129
+ useEffect(() => {
130
+ const { unsubscribe } = panelService.subscribe(
131
+ panelService.EVENTS.PANELS_CHANGED,
132
+ ({ options }) => {
133
+ setHasLeftPanels(hasPanels('left'));
134
+ setHasRightPanels(hasPanels('right'));
135
+ if (options?.leftPanelClosed !== undefined) {
136
+ setLeftPanelClosed(options.leftPanelClosed);
137
+ }
138
+ if (options?.rightPanelClosed !== undefined) {
139
+ setRightPanelClosed(options.rightPanelClosed);
140
+ }
141
+ }
142
+ );
143
+
144
+ return () => {
145
+ unsubscribe();
146
+ };
147
+ }, [panelService, hasPanels]);
148
+
149
+ const viewportComponents = viewports.map(getViewportComponentData);
150
+
151
+ return (
152
+ <div>
153
+ <ViewerHeader
154
+ hotkeysManager={hotkeysManager}
155
+ extensionManager={extensionManager}
156
+ servicesManager={servicesManager}
157
+ appConfig={appConfig}
158
+ />
159
+ <div
160
+ className="relative flex w-full flex-row flex-nowrap items-stretch overflow-hidden bg-background"
161
+ style={{ height: 'calc(100vh - 52px)' }}
162
+ >
163
+ <React.Fragment>
164
+ {showLoadingIndicator && <LoadingIndicatorProgress className="h-full w-full bg-background" />}
165
+ <ResizablePanelGroup {...resizablePanelGroupProps}>
166
+ {/* LEFT SIDEPANELS */}
167
+ {hasLeftPanels ? (
168
+ <>
169
+ <ResizablePanel {...resizableLeftPanelProps}>
170
+ <SidePanelWithServices
171
+ side="left"
172
+ isExpanded={!leftPanelClosedState}
173
+ servicesManager={servicesManager}
174
+ {...leftPanelProps}
175
+ />
176
+ </ResizablePanel>
177
+ <ResizableHandle
178
+ onDragging={onHandleDragging}
179
+ disabled={!leftPanelResizable}
180
+ className={resizableHandleClassName}
181
+ />
182
+ </>
183
+ ) : null}
184
+ {/* TOOLBAR + GRID */}
185
+ <ResizablePanel {...resizableViewportGridPanelProps}>
186
+ <div className="flex h-full flex-1 flex-col">
187
+ <div
188
+ className="relative flex h-full flex-1 items-center justify-center overflow-hidden bg-background"
189
+ onMouseEnter={handleMouseEnter}
190
+ >
191
+ <ViewportGridComp
192
+ servicesManager={servicesManager}
193
+ viewportComponents={viewportComponents}
194
+ commandsManager={commandsManager}
195
+ />
196
+ </div>
197
+ </div>
198
+ </ResizablePanel>
199
+ {hasRightPanels ? (
200
+ <>
201
+ <ResizableHandle
202
+ onDragging={onHandleDragging}
203
+ disabled={!rightPanelResizable}
204
+ className={resizableHandleClassName}
205
+ />
206
+ <ResizablePanel {...resizableRightPanelProps}>
207
+ <SidePanelWithServices
208
+ side="right"
209
+ isExpanded={!rightPanelClosedState}
210
+ servicesManager={servicesManager}
211
+ {...rightPanelProps}
212
+ />
213
+ </ResizablePanel>
214
+ </>
215
+ ) : null}
216
+ </ResizablePanelGroup>
217
+ </React.Fragment>
218
+ </div>
219
+ <Onboarding tours={customizationService.getCustomization('ohif.tours')} />
220
+ <InvestigationalUseDialog dialogConfiguration={appConfig?.investigationalUseDialog} />
221
+ </div>
222
+ );
223
+ }
224
+
225
+
226
+
227
+ export default ViewerLayout;
@@ -0,0 +1,75 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { eventTarget, utilities as csUtilities } from '@cornerstonejs/core';
3
+ import { Enums as csToolsEnums } from '@cornerstonejs/tools';
4
+
5
+ const { DefaultHistoryMemo } = csUtilities.HistoryMemo;
6
+
7
+ // Cornerstone events after which the undo/redo history may have changed.
8
+ // `undo`/`redo` emit the HISTORY_* events, but any tool action that records a
9
+ // memo (drawing an annotation, editing a labelmap, deleting an annotation)
10
+ // pushes onto the history WITHOUT emitting a history event, so we also listen
11
+ // for the tool events that produce those memos in order to keep the enabled
12
+ // state of the buttons in sync.
13
+ const HISTORY_CHANGING_EVENTS = [
14
+ csToolsEnums.Events.HISTORY_UNDO,
15
+ csToolsEnums.Events.HISTORY_REDO,
16
+ csToolsEnums.Events.ANNOTATION_COMPLETED,
17
+ csToolsEnums.Events.ANNOTATION_MODIFIED,
18
+ csToolsEnums.Events.ANNOTATION_REMOVED,
19
+ csToolsEnums.Events.SEGMENTATION_DATA_MODIFIED,
20
+ ];
21
+
22
+ // A drag of an existing annotation fires ANNOTATION_MODIFIED only while the
23
+ // pointer moves; the tool pushes the memo on mouse up and fires no event for
24
+ // it. So also re-read the state after each mouse up / touch end.
25
+ const POINTER_END_EVENTS = ['mouseup', 'touchend'];
26
+
27
+ /**
28
+ * Tracks whether an undo/redo is currently available so the header buttons can
29
+ * be disabled (greyed out) when there is nothing to undo/redo.
30
+ */
31
+ export function useUndoRedoState(): { canUndo: boolean; canRedo: boolean } {
32
+ const [state, setState] = useState(() => ({
33
+ canUndo: DefaultHistoryMemo.canUndo,
34
+ canRedo: DefaultHistoryMemo.canRedo,
35
+ }));
36
+
37
+ useEffect(() => {
38
+ // A memo is often pushed synchronously *after* the triggering event is
39
+ // dispatched, so defer the read until the current call stack unwinds to
40
+ // make sure we observe the up-to-date availability.
41
+ let scheduled: ReturnType<typeof setTimeout> | null = null;
42
+
43
+ const readState = () => {
44
+ scheduled = null;
45
+ setState(prev => {
46
+ const { canUndo, canRedo } = DefaultHistoryMemo;
47
+ return prev.canUndo === canUndo && prev.canRedo === canRedo ? prev : { canUndo, canRedo };
48
+ });
49
+ };
50
+
51
+ const schedule = () => {
52
+ if (scheduled === null) {
53
+ scheduled = setTimeout(readState, 0);
54
+ }
55
+ };
56
+
57
+ HISTORY_CHANGING_EVENTS.forEach(evt => eventTarget.addEventListener(evt, schedule));
58
+ POINTER_END_EVENTS.forEach(evt => window.addEventListener(evt, schedule, true));
59
+
60
+ // Sync once on mount in case the history already has content.
61
+ readState();
62
+
63
+ return () => {
64
+ HISTORY_CHANGING_EVENTS.forEach(evt => eventTarget.removeEventListener(evt, schedule));
65
+ POINTER_END_EVENTS.forEach(evt => window.removeEventListener(evt, schedule, true));
66
+ if (scheduled !== null) {
67
+ clearTimeout(scheduled);
68
+ }
69
+ };
70
+ }, []);
71
+
72
+ return state;
73
+ }
74
+
75
+ export default useUndoRedoState;
@@ -0,0 +1,147 @@
1
+ /**
2
+ * The one-up toggle store (`useToggleOneUpViewportGridStore`) must only ever
3
+ * hold a one-up that is currently active and can be toggled back. Any explicit
4
+ * layout change that actually proceeds — a common grid (`setViewportGridLayout`)
5
+ * or a protocol/preset (`setHangingProtocol`) — abandons a pending one-up, so
6
+ * those commands clear the store. Without this, reaching a 1x1 preset (e.g.
7
+ * "3D only") and double-clicking it restores a stale grid left over from an
8
+ * earlier one-up.
9
+ *
10
+ * A layout change that does NOT proceed must leave the store untouched: if the
11
+ * protocol's `onLayoutChange` callback vetoes the grid change, we are still in
12
+ * the pending one-up and the toggle-back state must survive.
13
+ *
14
+ * The command module pulls a large dependency graph (OHIF core/app, cornerstone,
15
+ * the context-menu controller, …), so the heavy imports are mocked out; the real
16
+ * store is kept so we can assert the clearing behaviour, and the services are
17
+ * stubbed enough for each command to run its happy path to completion.
18
+ */
19
+
20
+ // --- Mock the heavy / resolution-breaking imports (keep the real store) ------
21
+ jest.mock('@ohif/core', () => ({ Types: {}, DicomMetadataStore: {}, utils: {} }), {
22
+ virtual: true,
23
+ });
24
+ jest.mock('@ohif/app', () => ({ history: {} }), { virtual: true });
25
+ jest.mock('../utils/dicomWriter', () => ({
26
+ datasetToDicomBlob: jest.fn(),
27
+ setNonEnumerableInstanceProperty: jest.fn(),
28
+ }));
29
+ jest.mock('../utils/registerNaturalizedDatasetForLocalWadouri', () => ({
30
+ registerNaturalizedDatasetsForLocalWadouri: jest.fn(),
31
+ }));
32
+ jest.mock('../utils/registerStoredInstanceImageId', () => ({
33
+ registerStoredInstanceImageId: jest.fn(),
34
+ registerStoredInstanceImageIds: jest.fn(),
35
+ }));
36
+ jest.mock('../CustomizableContextMenu', () => ({ ContextMenuController: class {} }));
37
+ jest.mock('../DicomTagBrowser/DicomTagBrowser', () => ({ __esModule: true, default: class {} }));
38
+ jest.mock('../utils/reuseCachedLayouts', () => ({ __esModule: true, default: jest.fn() }));
39
+ jest.mock('../utils/layerConfigurationUtils', () => ({
40
+ configureViewportForLayerAddition: jest.fn(),
41
+ configureViewportForLayerRemoval: jest.fn(),
42
+ canAddDisplaySetToViewport: jest.fn(),
43
+ DERIVED_OVERLAY_MODALITIES: [],
44
+ }));
45
+ jest.mock('../findViewportsByPosition', () => ({
46
+ __esModule: true,
47
+ default: jest.fn(),
48
+ findOrCreateViewport: jest.fn(),
49
+ }));
50
+ jest.mock('../Panels/requestDisplaySetCreationForStudy', () => ({
51
+ __esModule: true,
52
+ default: jest.fn(),
53
+ }));
54
+ jest.mock('../utils/promptSaveReport', () => ({ __esModule: true, default: jest.fn() }));
55
+
56
+ import commandsModule from '../commandsModule';
57
+ import { useToggleOneUpViewportGridStore } from '../stores/useToggleOneUpViewportGridStore';
58
+
59
+ /**
60
+ * Build the commands module with services stubbed enough that the two layout
61
+ * commands complete their happy path. `onLayoutChange` lets a test install a
62
+ * grid-change veto callback on the active protocol.
63
+ */
64
+ function makeCommandsModule({ onLayoutChange }: { onLayoutChange?: () => unknown } = {}) {
65
+ const noop = () => undefined;
66
+ const services = {
67
+ customizationService: { getCustomization: noop },
68
+ measurementService: {},
69
+ hangingProtocolService: {
70
+ // setViewportGridLayout reads the active protocol's onLayoutChange callback.
71
+ getActiveProtocol: () => ({ protocol: { callbacks: { onLayoutChange } } }),
72
+ getState: () => ({ protocolId: 'someProtocol', stageIndex: 0, activeStudyUID: 'study' }),
73
+ getStageIndex: () => 0,
74
+ setActiveStudyUID: () => false,
75
+ setProtocol: noop,
76
+ run: noop,
77
+ },
78
+ uiNotificationService: { show: noop },
79
+ viewportGridService: {
80
+ getState: () => ({ layout: { numRows: 1, numCols: 1 }, viewports: new Map() }),
81
+ setLayout: noop,
82
+ set: noop,
83
+ getLayoutOptionsFromState: () => [],
84
+ },
85
+ displaySetService: { getActiveDisplaySets: () => [] },
86
+ multiMonitorService: {},
87
+ };
88
+ // Run function-valued commands (the onLayoutChange callback) so a veto is
89
+ // observable; ignore string command ids used elsewhere.
90
+ const commandsManager = {
91
+ run: (cmd: unknown, options: unknown) => (typeof cmd === 'function' ? cmd(options) : undefined),
92
+ runCommand: noop,
93
+ };
94
+ const extensionManager = { getActiveDataSource: () => [] };
95
+ return commandsModule({
96
+ servicesManager: { services },
97
+ commandsManager,
98
+ extensionManager,
99
+ } as any);
100
+ }
101
+
102
+ const store = () => useToggleOneUpViewportGridStore.getState();
103
+ const seedPendingOneUp = () =>
104
+ store().setToggleOneUpViewportGridStore({
105
+ activeViewportId: 'v',
106
+ layout: { numRows: 2, numCols: 3 },
107
+ viewports: new Map(),
108
+ });
109
+
110
+ describe('commandsModule — one-up store is cleared only on layout changes that proceed', () => {
111
+ beforeEach(() => {
112
+ store().clearToggleOneUpViewportGridStore();
113
+ });
114
+
115
+ it('setViewportGridLayout clears a pending one-up when the change proceeds', () => {
116
+ const { actions } = makeCommandsModule();
117
+ seedPendingOneUp();
118
+ expect(store().toggleOneUpViewportGridStore).not.toBeNull();
119
+
120
+ actions.setViewportGridLayout({ numRows: 1, numCols: 1 });
121
+
122
+ expect(store().toggleOneUpViewportGridStore).toBeNull();
123
+ });
124
+
125
+ it('setViewportGridLayout keeps the one-up when onLayoutChange vetoes the change', () => {
126
+ const { actions } = makeCommandsModule({ onLayoutChange: () => false });
127
+ seedPendingOneUp();
128
+ expect(store().toggleOneUpViewportGridStore).not.toBeNull();
129
+
130
+ actions.setViewportGridLayout({ numRows: 1, numCols: 1 });
131
+
132
+ // Change was rejected — the toggle-back state must survive so the next
133
+ // double-click still restores.
134
+ expect(store().toggleOneUpViewportGridStore).not.toBeNull();
135
+ });
136
+
137
+ it('setHangingProtocol clears a pending one-up (advanced presets like "3D only")', () => {
138
+ const { actions } = makeCommandsModule();
139
+ seedPendingOneUp();
140
+ expect(store().toggleOneUpViewportGridStore).not.toBeNull();
141
+
142
+ const applied = actions.setHangingProtocol({ protocolId: 'someProtocol' });
143
+
144
+ expect(applied).toBe(true);
145
+ expect(store().toggleOneUpViewportGridStore).toBeNull();
146
+ });
147
+ });