fix: Exit MPR mode if Layout is changed (#984)

This commit is contained in:
Erik Ziegler 2019-10-01 11:55:58 +02:00 committed by GitHub
parent 7a4b97b4e8
commit 674ca9f96f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,15 +13,23 @@ const mapStateToProps = state => {
const mapDispatchToProps = dispatch => {
return {
// TODO: Change if layout switched becomes more complex
onChange: selectedCell => {
onChange: (selectedCell, currentLayout) => {
let viewports = [];
const rows = selectedCell.row + 1;
const columns = selectedCell.col + 1;
const numViewports = rows * columns;
for (let i = 0; i < numViewports; i++) {
// Hacky way to allow users to exit MPR "mode"
const viewport = currentLayout.viewports[i];
let plugin = viewport && viewport.plugin;
if (viewport && viewport.vtk) {
plugin = 'cornerstone';
}
viewports.push({
height: `${100 / rows}%`,
width: `${100 / columns}%`,
plugin,
});
}
const layout = {
@ -33,9 +41,19 @@ const mapDispatchToProps = dispatch => {
};
};
const mergeProps = (propsFromState, propsFromDispatch) => {
const onChangeFromDispatch = propsFromDispatch.onChange;
const { currentLayout } = propsFromState;
return {
onChange: (selectedCell) => onChangeFromDispatch(selectedCell, currentLayout)
};
}
const ConnectedLayoutButton = connect(
mapStateToProps,
mapDispatchToProps
mapDispatchToProps,
mergeProps
)(LayoutButton);
export default ConnectedLayoutButton;