Skip to content

Commit

Permalink
Disable canvas if not active (#1890)
Browse files Browse the repository at this point in the history
  • Loading branch information
igoroctaviano authored Jul 10, 2020
1 parent 8b1a6b2 commit 4985fbf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
6 changes: 3 additions & 3 deletions platform/ui/src/components/ViewportPane/ViewportPane.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ function ViewportPane({
}
};

const onInteractionHandler = () => {
onInteraction();
const onInteractionHandler = (event) => {
focus();
onInteraction(event);
};

const refHandler = element => {
Expand Down Expand Up @@ -101,7 +101,7 @@ ViewportPane.propTypes = {
onDoubleClick: PropTypes.func,
};

const noop = () => {};
const noop = () => { };

ViewportPane.defaultProps = {
onInteraction: noop,
Expand Down
31 changes: 19 additions & 12 deletions platform/viewer/src/components/ViewportGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ViewportGrid, ViewportPane, useViewportGrid } from '@ohif/ui';
import EmptyViewport from './EmptyViewport';
import { classes } from '@ohif/core';
const { ImageSet } = classes;
import classNames from 'classnames';

function ViewerViewportGrid(props) {
const { servicesManager, viewportComponents, dataSource } = props;
Expand All @@ -15,10 +16,6 @@ function ViewerViewportGrid(props) {
viewportGridService,
] = useViewportGrid();

const setActiveViewportIndex = index => {
viewportGridService.setActiveViewportIndex(index);
};

// TODO -> Need some way of selecting which displaySets hit the viewports.
const { DisplaySetService } = servicesManager.services;

Expand Down Expand Up @@ -148,6 +145,7 @@ function ViewerViewportGrid(props) {

for (let i = 0; i < numViewportPanes; i++) {
const viewportIndex = i;
const isActive = activeViewportIndex === viewportIndex;
const paneMetadata = viewports[i] || {};
const { displaySetInstanceUID } = paneMetadata;

Expand All @@ -159,8 +157,15 @@ function ViewerViewportGrid(props) {
viewportComponents
);

const onInterationHandler = () => {
setActiveViewportIndex(viewportIndex);
const onInterationHandler = (event) => {
if (isActive) return;

if (event) {
event.preventDefault();
event.stopPropagation();
}

viewportGridService.setActiveViewportIndex(viewportIndex);
};

// TEMP -> Double click disabled for now
Expand All @@ -173,13 +178,15 @@ function ViewerViewportGrid(props) {
acceptDropsFor="displayset"
onDrop={onDropHandler.bind(null, viewportIndex)}
onInteraction={onInterationHandler}
isActive={activeViewportIndex === viewportIndex}
isActive={isActive}
>
<ViewportComponent
displaySet={displaySet}
viewportIndex={viewportIndex}
dataSource={dataSource}
/>
<div className={classNames('h-full w-full flex flex-col align-center', { 'pointer-events-none': !isActive })}>
<ViewportComponent
displaySet={displaySet}
viewportIndex={viewportIndex}
dataSource={dataSource}
/>
</div>
</ViewportPane>
);
}
Expand Down

0 comments on commit 4985fbf

Please sign in to comment.