Interactive interface for browsing global, full-resolution satellite imagery
Consolidate setIsWithinWings updates to a single useEffect. (#6701)
Tom Carielloaa560bd36925
diff --git a/web/js/components/sidebar/charting-mode-options.js b/web/js/components/sidebar/charting-mode-options.jsindex fd3d68af0..c6df6130d 100644--- a/web/js/components/sidebar/charting-mode-options.js+++ b/web/js/components/sidebar/charting-mode-options.js@@ -188,11 +188,6 @@ function ChartingModeOptions(props) {setTopRightLatLong(topRight);debouncedUpdateAOICoordinates([...bottomLeft, ...topRight]);setMapViewChecked(false);- if (maxExtent) {- const inLeftWing = bottomLeft[0] < maxExtent[0] && topRight[0] < maxExtent[0];- const inRightWing = bottomLeft[0] > maxExtent[2] && topRight[0] > maxExtent[2];- setIsWithinWings(inLeftWing || inRightWing);- }};const { initialStartDate, initialEndDate } = initializeDates(timeSpanStartDate, timeSpanEndDate);@@ -250,20 +245,10 @@ function ChartingModeOptions(props) {if (!aoiCoordinates || aoiCoordinates.length === 0) {debouncedUpdateAOICoordinates([...bottomLeftLatLong, ...topRightLatLong]);}- if (maxExtent) {- let inLeftWing;- let inRightWing;- if (aoiCoordinates && aoiCoordinates.length > 0) {- inLeftWing = aoiCoordinates[0] < maxExtent[0] && aoiCoordinates[2] < maxExtent[0];- inRightWing = aoiCoordinates[0] > maxExtent[2] && aoiCoordinates[2] > maxExtent[2];- } else {- inLeftWing = bottomLeftLatLong[0] < maxExtent[0] && topRightLatLong[0] < maxExtent[0];- inRightWing = bottomLeftLatLong[0] > maxExtent[2] && topRightLatLong[0] > maxExtent[2];- }- setIsWithinWings(inLeftWing || inRightWing);- }return () => {isMounted.current = false;+ updateAOICoordinates([]);+ setIsWithinWings(null);};}, []);@@ -273,6 +258,22 @@ function ChartingModeOptions(props) {}}, [fromButton]);+ // Track whether the bounding box is within the wings of the map+ useEffect(() => {+ if (!maxExtent) return;++ let inLeftWing, inRightWing;++ if (aoiCoordinates && aoiCoordinates.length > 0) {+ inLeftWing = aoiCoordinates[0] < maxExtent[0];+ inRightWing = aoiCoordinates[2] > maxExtent[2];+ } else {+ inLeftWing = bottomLeftLatLong[0] < maxExtent[0];+ inRightWing = topRightLatLong[0] > maxExtent[2];+ }+ setIsWithinWings(inLeftWing || inRightWing);+ }, [maxExtent, aoiCoordinates, bottomLeftLatLong, topRightLatLong]);+function formatDateForImageStat(dateObj) {const dateString = new Date(dateObj);const year = dateString.getUTCFullYear();@@ -695,17 +696,13 @@ function ChartingModeOptions(props) {onUpdateStartDate(startDate);onUpdateEndDate(endDate);}+if (!aoiCoordinates || aoiCoordinates.length === 0) {const bottomLeft = getLatLongFromPixelValue(x, y2);const topRight = getLatLongFromPixelValue(x2, y);setBottomLeftLatLong(bottomLeft);setTopRightLatLong(topRight);debouncedUpdateAOICoordinates([...bottomLeft, ...topRight]);- if (maxExtent) {- const inLeftWing = bottomLeft[0] < maxExtent[0] && topRight[0] < maxExtent[0];- const inRightWing = bottomLeft[0] > maxExtent[2] && topRight[0] > maxExtent[2];- setIsWithinWings(inLeftWing || inRightWing);- }return;}if (viewExtent.every((val, index) => val === aoiCoordinates[index])) {@@ -722,11 +719,6 @@ function ChartingModeOptions(props) {setBoundaries(newBoundaries);setBottomLeftLatLong([aoiCoordinates[0], aoiCoordinates[1]]);setTopRightLatLong([aoiCoordinates[2], aoiCoordinates[3]]);- if (maxExtent) {- const inLeftWing = aoiCoordinates[0] < maxExtent[0] && aoiCoordinates[2] < maxExtent[0];- const inRightWing = aoiCoordinates[0] > maxExtent[2] && aoiCoordinates[2] > maxExtent[2];- setIsWithinWings(inLeftWing || inRightWing);- }});const onLatLongChange = (coordsArray) => {@@ -745,16 +737,21 @@ function ChartingModeOptions(props) {setTopRightLatLong(topRight);debouncedUpdateAOICoordinates([...bottomLeft, ...topRight]);setMapViewChecked(false);- if (maxExtent) {- const inLeftWing = bottomLeft[0] < maxExtent[0] && topRight[0] < maxExtent[0];- const inRightWing = bottomLeft[0] > maxExtent[2] && topRight[0] > maxExtent[2];- setIsWithinWings(inLeftWing || inRightWing);- }};const toggleMapView = () => {if (!mapViewChecked) {- onLatLongChange(viewExtent);+ // Clamp extent values to the visible map area+ const clampedViewExtent = viewExtent.map((val, index) => {+ if (!maxExtent) return val;+ if (index % 2 === 0) {+ // Longitude value (x)+ return Math.min(Math.max(val, maxExtent[0]), maxExtent[2]);+ }+ // Latitude value (y)+ return Math.min(Math.max(val, maxExtent[1]), maxExtent[3]);+ });+ onLatLongChange(clampedViewExtent);} else {const boundariesObj = {x: screenWidth / 2 - 100,@@ -880,6 +877,21 @@ function ChartingModeOptions(props) {valid={!chartRequestInProgress && !isWithinWings}text={requestBtnText}/>+ <style>{`+ #charting-create-button:disabled {+ pointer-events: auto !important;+ cursor: not-allowed;+ }+ `}</style>+ {isWithinWings && (+ <UncontrolledTooltip+ id="charting-create-button"+ target="charting-create-button"+ placement="right"+ >+ Please adjust your AOI to be within the current day's extent to generate a chart.+ </UncontrolledTooltip>+ )}</div>{chartRequestInProgress && (<WaitOverlaydiff --git a/web/js/modules/charting/reducers.js b/web/js/modules/charting/reducers.jsindex d33412eb2..995de04ff 100644--- a/web/js/modules/charting/reducers.js+++ b/web/js/modules/charting/reducers.js@@ -61,7 +61,10 @@ export function chartingReducer(state = initialChartingState, action) {isChartOpen: action.status,});case UPDATE_AOI_COORDINATES:- // action.extent = the geometry from the drawn AOI box+ // Don't update the coordinates if charting mode isn't active+ if (!state.active) {+ return state;+ }return lodashAssign({}, state, {aoiCoordinates: action.extent,});diff --git a/web/js/modules/charting/reducers.test.js b/web/js/modules/charting/reducers.test.jsindex 3cc161bff..9dead6b16 100644--- a/web/js/modules/charting/reducers.test.js+++ b/web/js/modules/charting/reducers.test.js@@ -114,9 +114,10 @@ describe('chartingReducer', () => {});describe('UPDATE_AOI_COORDINATES', () => {- it('updates aoiCoordinates with the provided extent', () => {+ it('updates aoiCoordinates with the provided extent when', () => {+ const activeState = { ...initialChartingState, active: true };const extent = [10, 20, 30, 40];- const state = chartingReducer(initialChartingState, { type: UPDATE_AOI_COORDINATES, extent });+ const state = chartingReducer(activeState, { type: UPDATE_AOI_COORDINATES, extent });expect(state.aoiCoordinates).toEqual(extent);});});