Hoist ViewportGrid context so UI Services can access/update it
This commit is contained in:
parent
db76eac047
commit
7487cbb28c
65
extensions/default/src/getCommandsModule.js
Normal file
65
extensions/default/src/getCommandsModule.js
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
// SEE:
|
||||||
|
// https://github.com/OHIF/Viewers/blob/b58aa4575ab72fe3f493cc5a4261b4f8256516ab/platform/viewer/src/appExtensions/MeasurementsPanel/index.js#L18-L49
|
||||||
|
import React from 'react';
|
||||||
|
import { useViewportGrid } from '@ohif/ui';
|
||||||
|
|
||||||
|
|
||||||
|
function getCommandsModule ({ servicesManager }) {
|
||||||
|
const { UIDialogService } = servicesManager.services;
|
||||||
|
|
||||||
|
const definitions = {
|
||||||
|
toggleLayoutSelectionDialog: {
|
||||||
|
commandFn: () => {
|
||||||
|
if (!UIDialogService) {
|
||||||
|
window.alert('Unable to show dialog; no UI Dialog Service available.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: use SimpleDialog component
|
||||||
|
// TODO: update position on window resize
|
||||||
|
// TODO: Expand service API to check if dialog w/ ID is already open
|
||||||
|
// TODO: Import and call `useViewportGrid`
|
||||||
|
UIDialogService.dismiss({ id: 'layoutSelection' });
|
||||||
|
UIDialogService.create({
|
||||||
|
id: 'layoutSelection',
|
||||||
|
centralize: true,
|
||||||
|
isDraggable: false,
|
||||||
|
showOverlay: true,
|
||||||
|
content: Test,
|
||||||
|
});
|
||||||
|
|
||||||
|
},
|
||||||
|
storeContexts: [],
|
||||||
|
options: {},
|
||||||
|
context: 'VIEWER',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
definitions,
|
||||||
|
defaultContext: 'VIEWER',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function Test() {
|
||||||
|
const [
|
||||||
|
{ numCols, numRows, activeViewportIndex, viewports },
|
||||||
|
dispatch,
|
||||||
|
] = useViewportGrid();
|
||||||
|
|
||||||
|
return <div
|
||||||
|
onClick={() => {
|
||||||
|
dispatch({ type: '', payload: {
|
||||||
|
numCols: 3,
|
||||||
|
numRows: 3,
|
||||||
|
activeViewportIndex: 0,
|
||||||
|
viewports: [],
|
||||||
|
}})
|
||||||
|
}}
|
||||||
|
style={{ color: 'white' }}
|
||||||
|
>
|
||||||
|
Hello World!
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
export default getCommandsModule;
|
||||||
@ -9,8 +9,8 @@ const definitions = [
|
|||||||
id: 'Layout',
|
id: 'Layout',
|
||||||
label: 'Layout',
|
label: 'Layout',
|
||||||
icon: 'tool-layout',
|
icon: 'tool-layout',
|
||||||
commandName: TOOLBAR_BUTTON_TYPES.SET_TOOL_ACTIVE,
|
commandName: 'toggleLayoutSelectionDialog',
|
||||||
commandOptions: { toolName: 'Layout' }, // TODO
|
commandOptions: { },
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import getCommandsModule from './getCommandsModule.js';
|
||||||
import getContextModule from './getContextModule.js';
|
import getContextModule from './getContextModule.js';
|
||||||
import getDataSourcesModule from './getDataSourcesModule.js';
|
import getDataSourcesModule from './getDataSourcesModule.js';
|
||||||
import getLayoutTemplateModule from './getLayoutTemplateModule.js';
|
import getLayoutTemplateModule from './getLayoutTemplateModule.js';
|
||||||
@ -11,6 +12,7 @@ export default {
|
|||||||
* Only required property. Should be a unique value across all extensions.
|
* Only required property. Should be a unique value across all extensions.
|
||||||
*/
|
*/
|
||||||
id,
|
id,
|
||||||
|
getCommandsModule,
|
||||||
getContextModule,
|
getContextModule,
|
||||||
getDataSourcesModule,
|
getDataSourcesModule,
|
||||||
getLayoutTemplateModule,
|
getLayoutTemplateModule,
|
||||||
|
|||||||
@ -48,10 +48,31 @@ function App({ config, defaultExtensions }) {
|
|||||||
);
|
);
|
||||||
const { UIDialogService, UIModalService, UINotificationService } = servicesManager.services;
|
const { UIDialogService, UIModalService, UINotificationService } = servicesManager.services;
|
||||||
|
|
||||||
|
// A UI Service may need to use the ViewportGrid context
|
||||||
|
const viewportGridReducer = (state, action) => {
|
||||||
|
console.log(state, action);
|
||||||
|
|
||||||
|
switch (action.type) {
|
||||||
|
case 'DO_TODO':
|
||||||
|
return state;
|
||||||
|
default:
|
||||||
|
return action.payload;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<appConfigContext.Provider value={appConfigContextApi}>
|
<appConfigContext.Provider value={appConfigContextApi}>
|
||||||
<Router basename={routerBasename}>
|
<Router basename={routerBasename}>
|
||||||
<ThemeWrapper>
|
<ThemeWrapper>
|
||||||
|
<ViewportGridProvider
|
||||||
|
initialState={{
|
||||||
|
numRows: 1,
|
||||||
|
numCols: 1,
|
||||||
|
viewports: [],
|
||||||
|
activeViewportIndex: 0,
|
||||||
|
}}
|
||||||
|
reducer={viewportGridReducer}
|
||||||
|
>
|
||||||
<SnackbarProvider service={UINotificationService}>
|
<SnackbarProvider service={UINotificationService}>
|
||||||
<DialogProvider service={UIDialogService}>
|
<DialogProvider service={UIDialogService}>
|
||||||
<ModalProvider modal={Modal} service={UIModalService}>
|
<ModalProvider modal={Modal} service={UIModalService}>
|
||||||
@ -59,6 +80,7 @@ function App({ config, defaultExtensions }) {
|
|||||||
</ModalProvider>
|
</ModalProvider>
|
||||||
</DialogProvider>
|
</DialogProvider>
|
||||||
</SnackbarProvider>
|
</SnackbarProvider>
|
||||||
|
</ViewportGridProvider>
|
||||||
</ThemeWrapper>
|
</ThemeWrapper>
|
||||||
</Router>
|
</Router>
|
||||||
</appConfigContext.Provider>
|
</appConfigContext.Provider>
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import { DicomMetadataStore, ToolBarManager } from '@ohif/core';
|
|||||||
import {
|
import {
|
||||||
DragAndDropProvider,
|
DragAndDropProvider,
|
||||||
ImageViewerProvider,
|
ImageViewerProvider,
|
||||||
ViewportGridProvider,
|
|
||||||
} from '@ohif/ui';
|
} from '@ohif/ui';
|
||||||
//
|
//
|
||||||
import { useQuery } from '@hooks';
|
import { useQuery } from '@hooks';
|
||||||
@ -123,30 +122,10 @@ export default function ModeRoute({
|
|||||||
console.log(state, action);
|
console.log(state, action);
|
||||||
};
|
};
|
||||||
|
|
||||||
const viewportGridReducer = (state, action) => {
|
|
||||||
console.log(state, action);
|
|
||||||
|
|
||||||
switch (action.type) {
|
|
||||||
case 'DO_TODO':
|
|
||||||
return state;
|
|
||||||
default:
|
|
||||||
return action.payload;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ImageViewerProvider
|
<ImageViewerProvider
|
||||||
initialState={{ StudyInstanceUIDs: StudyInstanceUIDsAsArray }}
|
initialState={{ StudyInstanceUIDs: StudyInstanceUIDsAsArray }}
|
||||||
reducer={reducer}
|
reducer={reducer}
|
||||||
>
|
|
||||||
<ViewportGridProvider
|
|
||||||
initialState={{
|
|
||||||
numRows: 1,
|
|
||||||
numCols: 1,
|
|
||||||
viewports: [],
|
|
||||||
activeViewportIndex: 0,
|
|
||||||
}}
|
|
||||||
reducer={viewportGridReducer}
|
|
||||||
>
|
>
|
||||||
<CombinedContextProvider>
|
<CombinedContextProvider>
|
||||||
{/* TODO: extensionManager is already provided to the extension module.
|
{/* TODO: extensionManager is already provided to the extension module.
|
||||||
@ -160,7 +139,6 @@ export default function ModeRoute({
|
|||||||
/>
|
/>
|
||||||
</DragAndDropProvider>
|
</DragAndDropProvider>
|
||||||
</CombinedContextProvider>
|
</CombinedContextProvider>
|
||||||
</ViewportGridProvider>
|
|
||||||
</ImageViewerProvider>
|
</ImageViewerProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user