From c99e0d8a23e3957aca7ebf566b529753cea0fac5 Mon Sep 17 00:00:00 2001 From: Karthik Rao Date: Mon, 14 Oct 2019 18:11:29 +0530 Subject: [PATCH] feat: Implement a 'Exit 2D MPR' button in the toolbar * feat: Implement a 'Exit 2D MPR' button in the toolbar to act as a toggle when '2D MPR' button is clicked * Move logic to exit MPR and toggling into ConnectedPluginSwitch and PluginSwitch. Also, discard the ConnectedExitPluginSwitch and ExitPluginSwitch components. * Update ToolbarRow.js --- .../ConnectedPluginSwitch.js | 49 +++++++++++++------ .../src/connectedComponents/PluginSwitch.js | 31 +++++++++++- 2 files changed, 63 insertions(+), 17 deletions(-) diff --git a/platform/viewer/src/connectedComponents/ConnectedPluginSwitch.js b/platform/viewer/src/connectedComponents/ConnectedPluginSwitch.js index c54e52eff..0e46e77f9 100644 --- a/platform/viewer/src/connectedComponents/ConnectedPluginSwitch.js +++ b/platform/viewer/src/connectedComponents/ConnectedPluginSwitch.js @@ -1,9 +1,16 @@ -// import OHIF from '@ohif/core'; +import OHIF from '@ohif/core'; +import React from 'react'; import PluginSwitch from './PluginSwitch.js'; import { commandsManager } from './../App.js'; import { connect } from 'react-redux'; -// const { setLayout } = OHIF.redux.actions; +const { setLayout } = OHIF.redux.actions; + +const ConnectedPluginSwitch = (props) => { + return ( + + ) +}; const mapStateToProps = state => { const { activeViewportIndex, layout, viewportSpecificData } = state.viewports; @@ -15,13 +22,13 @@ const mapStateToProps = state => { }; }; -// const mapDispatchToProps = dispatch => { -// return { -// setLayout: data => { -// dispatch(setLayout(data)); -// } -// }; -// }; +const mapDispatchToProps = dispatch => { + return { + setLayout: data => { + dispatch(setLayout(data)); + } + }; +}; /*function setSingleLayoutData(originalArray, viewportIndex, data) { const viewports = originalArray.slice(); @@ -34,22 +41,32 @@ const mapStateToProps = state => { const mergeProps = (propsFromState, propsFromDispatch, ownProps) => { //const { activeViewportIndex, layout } = propsFromState; - //const { setLayout } = propsFromDispatch; + const { setLayout } = propsFromDispatch; // TODO: Do not display certain options if the current display set // cannot be displayed using these view types const mpr = () => { - commandsManager.runCommand('mpr2d'); + commandsManager.runCommand("mpr2d"); }; + + const exitMpr = () => { + const layout = { + numRows: 1, + numColumns: 1, + viewports: [{ plugin: 'cornerstone' }], + }; + + setLayout(layout); + }; + return { mpr, + exitMpr }; }; -const ConnectedPluginSwitch = connect( +export default connect( mapStateToProps, - null, // mapDispatchToProps + mapDispatchToProps, mergeProps -)(PluginSwitch); - -export default ConnectedPluginSwitch; +)(ConnectedPluginSwitch); diff --git a/platform/viewer/src/connectedComponents/PluginSwitch.js b/platform/viewer/src/connectedComponents/PluginSwitch.js index c3718a163..8c4666ea5 100644 --- a/platform/viewer/src/connectedComponents/PluginSwitch.js +++ b/platform/viewer/src/connectedComponents/PluginSwitch.js @@ -6,14 +6,43 @@ import './PluginSwitch.css'; class PluginSwitch extends Component { static propTypes = { mpr: PropTypes.func, + exitMpr: PropTypes.func }; static defaultProps = {}; + constructor(props) { + super(props); + this.state = { + isPlugSwitchOn: false, + label: "2D MPR", + icon: "cube" + }; + } + + handleClick = () => { + if (this.state.isPlugSwitchOn) { + this.setState({ + isPlugSwitchOn: false, + label: "2D MPR", + icon: "cube" + }); + this.props.exitMpr(); + } else { + this.setState({ + isPlugSwitchOn: true, + label: "Exit 2D MPR", + icon: "times" + }); + this.props.mpr(); + } + }; render() { + const { label, icon } = this.state; + return (
- +
); }