From 33cee9e898f3565c36223e0e883d48a6896363e3 Mon Sep 17 00:00:00 2001 From: dannyrb Date: Tue, 16 Jun 2020 00:43:16 -0400 Subject: [PATCH] fix null dropdowncontent --- .../src/Toolbar/ToolbarLayoutSelector.jsx | 44 +++++++------------ 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/extensions/default/src/Toolbar/ToolbarLayoutSelector.jsx b/extensions/default/src/Toolbar/ToolbarLayoutSelector.jsx index 0a3186c87..36236b93b 100644 --- a/extensions/default/src/Toolbar/ToolbarLayoutSelector.jsx +++ b/extensions/default/src/Toolbar/ToolbarLayoutSelector.jsx @@ -1,24 +1,23 @@ import React, { useEffect, useState } from 'react'; -import PropTypes from 'prop-types'; import { LayoutSelector as OHIFLayoutSelector, ToolbarButton, useViewportGrid, } from '@ohif/ui'; -function LayoutSelector({ onSelection }) { +function LayoutSelector() { const [isOpen, setIsOpen] = useState(false); const [viewportGridState, dispatch] = useViewportGrid(); useEffect(() => { - function LayoutSelector() { + function closeOnOutsideClick() { if (isOpen) { setIsOpen(false); } } - window.addEventListener('click', LayoutSelector); + window.addEventListener('click', closeOnOutsideClick); return () => { - window.removeEventListener('click', LayoutSelector); + window.removeEventListener('click', closeOnOutsideClick); }; }, [isOpen]); @@ -33,17 +32,19 @@ function LayoutSelector({ onSelection }) { setIsOpen(!isOpen); }} dropdownContent={ - { - dispatch({ - type: 'SET_LAYOUT', - payload: { - numCols, - numRows, - }, - }); - }} - /> + DropdownContent !== null && ( + { + dispatch({ + type: 'SET_LAYOUT', + payload: { + numCols, + numRows, + }, + }); + }} + /> + ) } isActive={isOpen} type="primary" @@ -51,15 +52,4 @@ function LayoutSelector({ onSelection }) { ); } -LayoutSelector.propTypes = { - /* Callback for grid selection */ - onSelection: PropTypes.func.isRequired, -}; - -LayoutSelector.defaultProps = { - onSelection: () => { - console.warn('layoutSelector missing `onSelection` prop'); - }, -}; - export default LayoutSelector;