Skip to content

Commit

Permalink
fix: 🐛 1241: Make Plugin switch part of ToolbarModule (OHIF#1322)
Browse files Browse the repository at this point in the history
* fix: 🐛 Make Plugin switch part of ToolbarModule

Closes: OHIF#1241

* Move setCornerstoneViewport command into cornerstone extension

* Exposing extensionManager into extension's get modules functions

* Remove Plugin switch

* Updating set cornerstonelayout to work on VIEWER context

* Creating a customComponent for 2D MPR button

* Use extensionManager to show or not buttons
Adding isHidden option into toolbarModules

* Make buttons hidden depending on extension registration

* Fix unit test after changes on extensionManager

* Remove workaround for extensionManager

* Use studyMeatadataManager and remove TODO's

* Remove storeContext not needed

* Moving Exit 2D MPR into cornerstone extension with VTK context

* Remove PluginSwitch files

* Fix E2E tests

* Adding cypress screenshots into gitignore

* Remove extensionManager from getModuleFn functions and moving CustomComponent for VTK button to VTK extension

Co-authored-by: Danny Brown <[email protected]>
  • Loading branch information
galelis and dannyrb committed Dec 20, 2019
1 parent a436436 commit 6540e36
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 185 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ docker/dcm4che/dcm4che-arc

# Cypress test results
videos/
screenshots/

# Locize settings
.locize
10 changes: 10 additions & 0 deletions extensions/cornerstone/src/commandsModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import cornerstone from 'cornerstone-core';
import cornerstoneTools from 'cornerstone-tools';
import OHIF from '@ohif/core';

import setCornerstoneLayout from './utils/setCornerstoneLayout.js';
import { getEnabledElement } from './state';
import CornerstoneViewportDownloadForm from './CornerstoneViewportDownloadForm';
const scroll = cornerstoneTools.import('util/scroll');
Expand Down Expand Up @@ -242,6 +243,9 @@ const commandsModule = ({ servicesManager }) => {
cornerstoneTools.removeToolState(element, toolType, tool);
cornerstone.updateImage(element);
},
setCornerstoneLayout: () => {
setCornerstoneLayout();
}
};

const definitions = {
Expand Down Expand Up @@ -348,6 +352,12 @@ const commandsModule = ({ servicesManager }) => {
storeContexts: [],
options: {},
},
setCornerstoneLayout: {
commandFn: actions.setCornerstoneLayout,
storeContexts: [],
options: {},
context: 'VIEWER',
},
};

return {
Expand Down
9 changes: 9 additions & 0 deletions extensions/cornerstone/src/toolbarModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ const definitions = [
},
],
},
{
id: 'Exit2DMPR',
label: 'Exit 2D MPR',
icon: 'times',
//
type: TOOLBAR_BUTTON_TYPES.COMMAND,
commandName: 'setCornerstoneLayout',
context: 'ACTIVE_VIEWPORT::VTK',
}
];

export default {
Expand Down
22 changes: 22 additions & 0 deletions extensions/cornerstone/src/utils/setCornerstoneLayout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { redux } from '@ohif/core';

const { setLayout } = redux.actions;

/**
* Update the current layout with a simple Cornerstone one
*
* @return void
*/
const setCornerstoneLayout = () => {
const layout = {
numRows: 1,
numColumns: 1,
viewports: [{ plugin: 'cornerstone' }],
};

const action = setLayout(layout);

window.store.dispatch(action);
}

export default setCornerstoneLayout;
87 changes: 87 additions & 0 deletions extensions/vtk/src/toolbarComponents/VTKMPRToolbarButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import React from 'react';
import { useSelector } from 'react-redux';
import PropTypes from 'prop-types';
import { ToolbarButton } from '@ohif/ui';
import { utils } from '@ohif/core';

const { studyMetadataManager } = utils;

let isVisible = true;

const _isDisplaySetReconstructable = (viewportSpecificData = {}, activeViewportIndex) => {
if (!viewportSpecificData[activeViewportIndex]) {
return false;
};

const { displaySetInstanceUid, studyInstanceUid } = viewportSpecificData[
activeViewportIndex
];

const studies = studyMetadataManager.all();

const study = studies.find(
study => study.studyInstanceUID === studyInstanceUid
);

if (!study) {
return false;
}

const displaySet = study._displaySets.find(set => set.displaySetInstanceUid === displaySetInstanceUid);

if (!displaySet) {
return false;
};

return displaySet.isReconstructable;
};

function VTKMPRToolbarButton({
parentContext,
toolbarClickCallback,
button,
activeButtons,
isActive,
className,
}) {
const { id, label, icon } = button;
const { viewportSpecificData, activeViewportIndex } = useSelector(state => {
const { viewports = {} } = state;
const { viewportSpecificData, activeViewportIndex } = viewports;

return {
viewportSpecificData,
activeViewportIndex,
}
});

isVisible = _isDisplaySetReconstructable(
viewportSpecificData,
activeViewportIndex,
);

return (
<React.Fragment>
{isVisible && (
<ToolbarButton
key={id}
label={label}
icon={icon}
onClick={evt => toolbarClickCallback(button, evt)}
isActive={isActive}
/>
)}
</React.Fragment>
);
}

VTKMPRToolbarButton.propTypes = {
parentContext: PropTypes.object.isRequired,
toolbarClickCallback: PropTypes.func.isRequired,
button: PropTypes.object.isRequired,
activeButtons: PropTypes.array.isRequired,
isActive: PropTypes.bool,
className: PropTypes.string,
};

export default VTKMPRToolbarButton;
13 changes: 12 additions & 1 deletion extensions/vtk/src/toolbarModule.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SlabThicknessToolbarComponent from './toolbarComponents/SlabThicknessToolbarComponent';
import VTKMPRToolbarButton from './toolbarComponents/VTKMPRToolbarButton';

const TOOLBAR_BUTTON_TYPES = {
COMMAND: 'command',
Expand Down Expand Up @@ -115,9 +116,19 @@ const definitions = [
},
],
},
{
id: '2DMPR',
label: '2D MPR',
icon: 'cube',
//
CustomComponent: VTKMPRToolbarButton,
type: TOOLBAR_BUTTON_TYPES.COMMAND,
commandName: 'mpr2d',
context: 'ACTIVE_VIEWPORT::CORNERSTONE',
},
];

export default {
definitions,
defaultContext: 'ACTIVE_VIEWPORT::VTK',
};
}
2 changes: 1 addition & 1 deletion platform/core/src/extensions/ExtensionManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ describe('ExtensionManager.js', () => {
return {
definitions: {
exampleDefinition: {
commandFn: () => {},
commandFn: () => { },
storeContexts: [],
options: {},
},
Expand Down
1 change: 1 addition & 0 deletions platform/viewer/cypress/support/aliases.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function initRouteAliases() {

//Creating aliases for VTK tools buttons
export function initVTKToolsAliases() {
cy.get('[data-cy="exit 2d mpr"]').as('exit2dmprBtn');
cy.get('[data-cy="crosshairs"]').as('crosshairsBtn');
cy.get('[data-cy="wwwc"]').as('wwwcBtn');
cy.get('[data-cy="rotate"]').as('rotateBtn');
Expand Down
72 changes: 0 additions & 72 deletions platform/viewer/src/connectedComponents/ConnectedPluginSwitch.js

This file was deleted.

3 changes: 0 additions & 3 deletions platform/viewer/src/connectedComponents/PluginSwitch.css

This file was deleted.

106 changes: 0 additions & 106 deletions platform/viewer/src/connectedComponents/PluginSwitch.js

This file was deleted.

Loading

0 comments on commit 6540e36

Please sign in to comment.