From 591da1253637102cdf8689310a002502194ba85f Mon Sep 17 00:00:00 2001 From: dannyrb Date: Tue, 19 May 2020 23:28:41 -0400 Subject: [PATCH] Drag and drop w/ dragSource + dragTarget w/o errors --- .../default/src/Panels/PanelStudyBrowser.jsx | 4 +++ .../components/StudyBrowser/StudyBrowser.jsx | 26 ++++++++----------- .../ThumbnailList/ThumbnailList.jsx | 26 +++++++++---------- .../components/ViewportPane/ViewportPane.jsx | 6 ++--- .../viewer/src/components/ViewportGrid.jsx | 3 ++- 5 files changed, 33 insertions(+), 32 deletions(-) diff --git a/extensions/default/src/Panels/PanelStudyBrowser.jsx b/extensions/default/src/Panels/PanelStudyBrowser.jsx index 3a6ae1bdb..99713e1af 100644 --- a/extensions/default/src/Panels/PanelStudyBrowser.jsx +++ b/extensions/default/src/Panels/PanelStudyBrowser.jsx @@ -57,6 +57,10 @@ function PanelStudyBrowser({ StudyInstanceUID: ds.StudyInstanceUID, componentType: 'thumbnail', // 'thumbnailNoImage' || 'thumbnailTracked' // TODO: PUT THIS SOMEWHERE ELSE imageSrc, + dragData: { + type: 'displayset', + // .. Any other data to pass + }, }; }); diff --git a/platform/ui/src/components/StudyBrowser/StudyBrowser.jsx b/platform/ui/src/components/StudyBrowser/StudyBrowser.jsx index e0aca5650..f83a89bf9 100644 --- a/platform/ui/src/components/StudyBrowser/StudyBrowser.jsx +++ b/platform/ui/src/components/StudyBrowser/StudyBrowser.jsx @@ -147,21 +147,6 @@ StudyBrowser.propTypes = { numInstances: PropTypes.number, modalities: PropTypes.string, description: PropTypes.string, - // These apply to each thumbnail; we should set Thumbnails - // As children and kill the component to - // make it easier to set this prop. - // Do much less nesting so we have a bit more control. - /** - * Data the thumbnail should expose to a receiving drop target. Use a matching - * `dragData.type` to identify which targets can receive this draggable item. - * If this is not set, drag-n-drop will be disabled for this thumbnail. - * - * Ref: https://react-dnd.github.io/react-dnd/docs/api/use-drag#specification-object-members - */ - dragData: PropTypes.shape({ - /** Must match the "type" a dropTarget expects */ - type: PropTypes.string.isRequired, - }), displaySets: PropTypes.arrayOf( PropTypes.shape({ displaySetInstanceUID: PropTypes.string.isRequired, @@ -178,6 +163,17 @@ StudyBrowser.propTypes = { ]).isRequired, isTracked: PropTypes.bool, viewportIdentificator: PropTypes.string, + /** + * Data the thumbnail should expose to a receiving drop target. Use a matching + * `dragData.type` to identify which targets can receive this draggable item. + * If this is not set, drag-n-drop will be disabled for this thumbnail. + * + * Ref: https://react-dnd.github.io/react-dnd/docs/api/use-drag#specification-object-members + */ + dragData: PropTypes.shape({ + /** Must match the "type" a dropTarget expects */ + type: PropTypes.string.isRequired, + }), }) ), }) diff --git a/platform/ui/src/components/ThumbnailList/ThumbnailList.jsx b/platform/ui/src/components/ThumbnailList/ThumbnailList.jsx index 0014a667a..fa67bb607 100644 --- a/platform/ui/src/components/ThumbnailList/ThumbnailList.jsx +++ b/platform/ui/src/components/ThumbnailList/ThumbnailList.jsx @@ -4,17 +4,17 @@ import PropTypes from 'prop-types'; import { Thumbnail, ThumbnailNoImage, ThumbnailTracked } from '@ohif/ui'; const ThumbnailList = ({ - dragData, thumbnails, thumbnailActive, onThumbnailClick, }) => { return ( -
+
{thumbnails.map( ({ displaySetInstanceUID, description, + dragData, seriesNumber, numInstances, modality, @@ -80,17 +80,6 @@ const ThumbnailList = ({ }; ThumbnailList.propTypes = { - /** - * Data the thumbnail should expose to a receiving drop target. Use a matching - * `dragData.type` to identify which targets can receive this draggable item. - * If this is not set, drag-n-drop will be disabled for this thumbnail. - * - * Ref: https://react-dnd.github.io/react-dnd/docs/api/use-drag#specification-object-members - */ - dragData: PropTypes.shape({ - /** Must match the "type" a dropTarget expects */ - type: PropTypes.string.isRequired, - }), thumbnails: PropTypes.arrayOf( PropTypes.shape({ displaySetInstanceUID: PropTypes.string.isRequired, @@ -107,6 +96,17 @@ ThumbnailList.propTypes = { ]).isRequired, viewportIdentificator: PropTypes.string, isTracked: PropTypes.bool, + /** + * Data the thumbnail should expose to a receiving drop target. Use a matching + * `dragData.type` to identify which targets can receive this draggable item. + * If this is not set, drag-n-drop will be disabled for this thumbnail. + * + * Ref: https://react-dnd.github.io/react-dnd/docs/api/use-drag#specification-object-members + */ + dragData: PropTypes.shape({ + /** Must match the "type" a dropTarget expects */ + type: PropTypes.string.isRequired, + }), }) ), thumbnailActive: PropTypes.string, diff --git a/platform/ui/src/components/ViewportPane/ViewportPane.jsx b/platform/ui/src/components/ViewportPane/ViewportPane.jsx index f417785f3..3f848126c 100644 --- a/platform/ui/src/components/ViewportPane/ViewportPane.jsx +++ b/platform/ui/src/components/ViewportPane/ViewportPane.jsx @@ -13,7 +13,7 @@ function ViewportPane({ onDrop, acceptDropsFor, }) { - /*const [{ isHovered, isHighlighted }, drop] = useDrop({ + const [{ isHovered, isHighlighted }, drop] = useDrop({ accept: acceptDropsFor, // TODO: pass in as prop? drop: (droppedItem, monitor) => { @@ -29,11 +29,11 @@ function ViewportPane({ isHighlighted: monitor.canDrop(), isHovered: monitor.isOver(), }), - });*/ + }); - // ref={drop} return (
+ /> ); } @@ -101,6 +101,7 @@ function ViewerViewportGrid(props) { { /* setDisplaySet for Viewport */ }}