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 2019-10-09 16:37:26 -03:00 committed by Danny Brown
parent a28984ef1f
commit 2a743554b6
2 changed files with 14 additions and 8 deletions

View File

@ -142,8 +142,8 @@ jobs:
steps: steps:
- attach_workspace: - attach_workspace:
at: ~/repo at: ~/repo
- setup_remote_docker: # - setup_remote_docker:
docker_layer_caching: true # docker_layer_caching: true
- run: - run:
name: Build and push Docker image name: Build and push Docker image
command: | command: |
@ -198,8 +198,8 @@ jobs:
steps: steps:
- attach_workspace: - attach_workspace:
at: ~/repo at: ~/repo
- setup_remote_docker: # - setup_remote_docker:
docker_layer_caching: true # docker_layer_caching: true
- run: - run:
name: Deploy latest version to viewer.ohif.org name: Deploy latest version to viewer.ohif.org
command: | command: |

View File

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