From 9c5c70d04912a3d0765e07d338253971ff954e24 Mon Sep 17 00:00:00 2001 From: Jose Buitron Date: Fri, 8 Sep 2023 15:26:36 -0500 Subject: [PATCH] fix: Data map annotate step fixes (#1166) --- .../LandscapeSharedDataVisualization.test.js | 1 + .../visualization/components/Visualization.js | 5 +- .../VisualizationConfigForm/AnnotateStep.js | 89 ++++++++++++------- 3 files changed, 61 insertions(+), 34 deletions(-) diff --git a/src/landscape/components/LandscapeSharedDataVisualization.test.js b/src/landscape/components/LandscapeSharedDataVisualization.test.js index 3d16b72e5..ad55c6798 100644 --- a/src/landscape/components/LandscapeSharedDataVisualization.test.js +++ b/src/landscape/components/LandscapeSharedDataVisualization.test.js @@ -75,6 +75,7 @@ test('LandscapeSharedDataVisualization: Display visualization', async () => { setDOMContent: jest.fn().mockReturnThis(), addTo: jest.fn().mockReturnThis(), remove: jest.fn(), + isOpen: jest.fn(), }; mapboxgl.Popup.mockReturnValue(Popup); const events = {}; diff --git a/src/sharedData/visualization/components/Visualization.js b/src/sharedData/visualization/components/Visualization.js index 96ed1e3cd..aa783e203 100644 --- a/src/sharedData/visualization/components/Visualization.js +++ b/src/sharedData/visualization/components/Visualization.js @@ -278,7 +278,10 @@ const MapboxLayer = props => { if (!map || !popupData?.coordinates) { return; } - popup.setLngLat(popupData?.coordinates).addTo(map); + popup.setLngLat(popupData?.coordinates); + if (!popup.isOpen()) { + popup.addTo(map); + } }, [popup, popupData?.coordinates, map]); useEffect(() => { diff --git a/src/sharedData/visualization/components/VisualizationConfigForm/AnnotateStep.js b/src/sharedData/visualization/components/VisualizationConfigForm/AnnotateStep.js index 0ea61e58c..a3b165eb8 100644 --- a/src/sharedData/visualization/components/VisualizationConfigForm/AnnotateStep.js +++ b/src/sharedData/visualization/components/VisualizationConfigForm/AnnotateStep.js @@ -82,6 +82,27 @@ const FORM_FIELDS = [ }, ]; +// Work around for react-beautiful-dnd issue. The issues is that the +// Droppable component is not compatible with React.StrictMode. +// StricMode is used in the development environment by default. +// See: +// - https://stackoverflow.com/a/75807063 +// - https://github.com/atlassian/react-beautiful-dnd/issues/2396 +const StrictModeDroppable = ({ children, ...props }) => { + const [enabled, setEnabled] = useState(false); + useEffect(() => { + const animation = requestAnimationFrame(() => setEnabled(true)); + return () => { + cancelAnimationFrame(animation); + setEnabled(false); + }; + }, []); + if (!enabled) { + return null; + } + return {children}; +}; + const DataPoints = props => { const { t } = useTranslation(); const { value, onChange } = props.field; @@ -167,7 +188,7 @@ const DataPoints = props => { onDragEnd={onDragEnd} onBeforeCapture={() => setDragging(true)} > - + {provided => ( { {...provided.droppableProps} > {dataPoints.map((dataPoint, index) => ( - - {(provided, snapshot) => ( - - - - - - - )} - + + + {(provided, snapshot) => ( + + + + + + + )} + + ))} {dragging && provided.placeholder} )} - + );