Handle for interaction outside of the ViewportDialog (default to cancel)

This commit is contained in:
dannyrb 2020-06-29 23:29:40 -04:00
parent 9403a091d9
commit a0b0f365dd
7 changed files with 64 additions and 7 deletions

View File

@ -50,6 +50,10 @@ function _askTrackMeasurements(UIViewportDialogService, viewportIndex) {
message,
actions,
onSubmit,
onOutsideClick: () => {
UIViewportDialogService.hide();
resolve(RESPONSE.CANCEL);
},
});
});
}

View File

@ -63,6 +63,10 @@ function _askShouldAddMeasurements(UIViewportDialogService, viewportIndex) {
message,
actions,
onSubmit,
onOutsideClick: () => {
UIViewportDialogService.hide();
resolve(RESPONSE.CANCEL);
},
});
});
}
@ -91,10 +95,14 @@ function _askSaveDiscardOrCancel(UIViewportDialogService, viewportIndex) {
UIViewportDialogService.show({
viewportIndex,
type: 'info', // TODO: warn
type: 'warning',
message,
actions,
onSubmit,
onOutsideClick: () => {
UIViewportDialogService.hide();
resolve(RESPONSE.CANCEL);
},
});
});
}

View File

@ -57,6 +57,10 @@ function _askTrackMeasurements(UIViewportDialogService, viewportIndex) {
message,
actions,
onSubmit,
onOutsideClick: () => {
UIViewportDialogService.hide();
resolve(RESPONSE.CANCEL);
},
});
});
}
@ -85,10 +89,14 @@ function _askSaveDiscardOrCancel(UIViewportDialogService, viewportIndex) {
UIViewportDialogService.show({
viewportIndex,
type: 'info', // TODO: warn
type: 'warning',
message,
actions,
onSubmit,
onOutsideClick: () => {
UIViewportDialogService.hide();
resolve(RESPONSE.CANCEL);
},
});
});
}

View File

@ -277,6 +277,7 @@ function TrackedCornerstoneViewport({
type={viewportDialogState.type}
actions={viewportDialogState.actions}
onSubmit={viewportDialogState.onSubmit}
onOutsideClick={viewportDialogState.onOutsideClick}
/>
)}
</div>

View File

@ -26,13 +26,21 @@ const serviceImplementation = {
*
* @param {ViewportDialogProps} props { content, contentProps, viewportIndex }
*/
function _show({ viewportIndex, type, message, actions, onSubmit }) {
function _show({
viewportIndex,
type,
message,
actions,
onSubmit,
onOutsideClick,
}) {
return serviceImplementation._show({
viewportIndex,
type,
message,
actions,
onSubmit,
onOutsideClick,
});
}

View File

@ -1,16 +1,35 @@
import React from 'react';
import React, { useEffect, useRef } from 'react';
import classnames from 'classnames';
import PropTypes from 'prop-types';
import { Button, Icon } from '@ohif/ui';
const Notification = ({ type, message, actions, onSubmit }) => {
const Notification = ({ type, message, actions, onSubmit, onOutsideClick }) => {
const notificationRef = useRef(null);
useEffect(() => {
const notificationElement = notificationRef.current;
const handleClick = function(event) {
const isClickInside = notificationElement.contains(event.target);
if (!isClickInside) {
onOutsideClick();
}
};
document.addEventListener('mousedown', handleClick);
return () => {
document.removeEventListener('mousedown', handleClick);
};
}, [onOutsideClick]);
const iconsByType = {
error: {
icon: 'info',
color: 'text-red-700',
},
warning: {
icon: 'info',
icon: 'notificationwarning-diamond',
color: 'text-yellow-500',
},
info: {
@ -35,7 +54,10 @@ const Notification = ({ type, message, actions, onSubmit }) => {
const { icon, color } = getIconData();
return (
<div className="flex flex-col p-2 mx-2 mt-2 rounded bg-common-bright">
<div
ref={notificationRef}
className="flex flex-col p-2 mx-2 mt-2 rounded bg-common-bright"
>
<div className="flex flex-grow">
<Icon name={icon} className={classnames('w-5', color)} />
<span className="ml-2 text-base text-black">{message}</span>
@ -65,6 +87,7 @@ const Notification = ({ type, message, actions, onSubmit }) => {
Notification.defaultProps = {
type: 'info',
onOutsideClick: () => {},
};
Notification.propTypes = {
@ -78,6 +101,8 @@ Notification.propTypes = {
})
).isRequired,
onSubmit: PropTypes.func.isRequired,
/** Can be used as a callback to dismiss the notification for clicks that occur outside of it */
onOutsideClick: PropTypes.func,
};
export default Notification;

View File

@ -18,6 +18,9 @@ const DEFAULT_STATE = {
onSubmit: () => {
console.log('btn value?');
},
onOutsideClick: () => {
console.warn('default: onOutsideClick')
},
onDismiss: () => {
console.log('dismiss? -1');
},