fix: 🐛 set current viewport as active when switching layouts (#1018)

* fix: 🐛 set current viewport as active when switching layouts

check if current viewport index is less than the current layout lenght
and set 0 if so or keep current selected cell index as active viewport

Closes: 999

* chore: 🤖 commenting out docker layer caching in the short-term

commenting out docker layer caching in the short-term

* refactor: 💡 refactor layout matrix index conditional
This commit is contained in:
Igor Octaviano authored and Danny Brown committed 2019-10-09 15:37:26 -04:00
1 parent a28984ef1f
commit 2a743554b6
2 files changed
+14 -8

No files matched your search

@@ -2,18 +2,19 @@ import { LayoutButton } from '@ohif/ui';
import OHIF from '@ohif/core';
import { connect } from 'react-redux';
const { setLayout } = OHIF.redux.actions;
const { setLayout, setViewportActive } = OHIF.redux.actions;
const mapStateToProps = state => {
return {
currentLayout: state.viewports.layout,
activeViewportIndex: state.viewports.activeViewportIndex
};
};
const mapDispatchToProps = dispatch => {
return {
// TODO: Change if layout switched becomes more complex
onChange: (selectedCell, currentLayout) => {
onChange: (selectedCell, currentLayout, activeViewportIndex) => {
let viewports = [];
const rows = selectedCell.row + 1;
const columns = selectedCell.col + 1;
@@ -36,6 +37,11 @@ const mapDispatchToProps = dispatch => {
viewports,
};
const maxActiveIndex = rows * columns - 1;
if (activeViewportIndex > maxActiveIndex) {
dispatch(setViewportActive(0));
}
dispatch(setLayout(layout));
},
};
@@ -43,10 +49,10 @@ const mapDispatchToProps = dispatch => {
const mergeProps = (propsFromState, propsFromDispatch) => {
const onChangeFromDispatch = propsFromDispatch.onChange;
const { currentLayout } = propsFromState;
const { currentLayout, activeViewportIndex } = propsFromState;
return {
onChange: (selectedCell) => onChangeFromDispatch(selectedCell, currentLayout)
onChange: selectedCell => onChangeFromDispatch(selectedCell, currentLayout, activeViewportIndex)
};
}