Interactive interface for browsing global, full-resolution satellite imagery
WV-4125 (#6845)
Tom Cariello395314ffb442
diff --git a/e2e/features/events/event-test.spec.js b/e2e/features/events/event-test.spec.jsindex fc1e4d940..b568fe366 100644--- a/e2e/features/events/event-test.spec.js+++ b/e2e/features/events/event-test.spec.js@@ -1,7 +1,7 @@// @ts-checkconst { test, expect } = require('@playwright/test')const createSelectors = require('../../test-utils/global-variables/selectors')-const { mockEvents } = require('../../test-utils/global-variables/querystrings')+const { mockEvents, malformedMockEvents } = require('../../test-utils/global-variables/querystrings')const { closeModal } = require('../../test-utils/hooks/wvHooks')/** @type {import('@playwright/test').Page} */@@ -52,3 +52,14 @@ test('Use Mock to make sure appropriate number of event markers are appended toawait expect(listOfEvents).toBeVisible()await expect(eventIcons).toHaveCount(8)})++test('Gracefully handle malformed EONET mock data without crashing', async () => {+ const { eventIcons, listOfEvents } = selectors;++ await page.goto(malformedMockEvents);+ await closeModal(page);++ await expect(listOfEvents).toBeVisible();++ await expect(eventIcons).toHaveCount(6);+});diff --git a/e2e/test-utils/global-variables/querystrings.js b/e2e/test-utils/global-variables/querystrings.jsindex f40a2db89..d740b5a59 100644--- a/e2e/test-utils/global-variables/querystrings.js+++ b/e2e/test-utils/global-variables/querystrings.js@@ -25,6 +25,7 @@ module.exports = {// eventsmockEvents: 'http://localhost:3000/?e2e=true&p=geographic&l=VIIRS_SNPP_CorrectedReflectance_TrueColor(hidden),MODIS_Aqua_CorrectedReflectance_TrueColor(hidden),MODIS_Terra_CorrectedReflectance_TrueColor,Reference_Labels_15m(hidden),Reference_Features_15m(hidden),Coastlines_15m&t=2018-05-02-T00%3A00%3A00Z&z=3&v=-409.00147812273656,-205.62883007565202,270.5880270080828,219.11461063111003&e=true&mockEvents=20170530',+ malformedMockEvents: 'http://localhost:3000/?e2e=true&p=geographic&l=VIIRS_SNPP_CorrectedReflectance_TrueColor(hidden),MODIS_Aqua_CorrectedReflectance_TrueColor(hidden),MODIS_Terra_CorrectedReflectance_TrueColor,Reference_Labels_15m(hidden),Reference_Features_15m(hidden),Coastlines_15m&t=2018-05-02-T00%3A00%3A00Z&z=3&v=-409.00147812273656,-205.62883007565202,270.5880270080828,219.11461063111003&e=true&mockEvents=malformed',stormEventSelected: 'http://localhost:3000/?e2e=true&v=175.65863037109375,10.918751525878907,182.25042724609375,22.643360900878907&e=EONET_2777,2017-05-31&l=IMERG_Precipitation_Rate,VIIRS_SNPP_DayNightBand_ENCC(hidden),VIIRS_SNPP_DayNightBand_At_Sensor_Radiance(hidden),Reference_Labels,Reference_Features,Coastlines(hidden),VIIRS_NOAA20_CorrectedReflectance_TrueColor(hidden),VIIRS_SNPP_CorrectedReflectance_TrueColor,MODIS_Aqua_CorrectedReflectance_TrueColor(hidden),MODIS_Terra_CorrectedReflectance_TrueColor(hidden)&lg=true&t=2017-05-31-T00%3A00%3A00Z&mockEvents=20170530',fixedAppNow: 'http://localhost:3000/?e2e=true&now=2012-01-01T00%3A00%3A00Z',wildfiresWithDates: 'http://localhost:3000/?e2e=true&v=-139.02635001706034,25.660099233568406,-85.27770827186355,43.288373996427595&e=true&efs=false&efd=2020-01-16,2020-06-16&efc=wildfires&t=2020-06-16-T18%3A31%3A28Z',diff --git a/package-lock.json b/package-lock.jsonindex 1288a1aa1..233b76699 100644--- a/package-lock.json+++ b/package-lock.json@@ -4344,9 +4344,6 @@"arm"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -4368,9 +4365,6 @@"arm"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -4392,9 +4386,6 @@"arm64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -4416,9 +4407,6 @@"arm64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -4440,9 +4428,6 @@"x64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -4464,9 +4449,6 @@"x64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -5686,9 +5668,6 @@"arm64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -5703,9 +5682,6 @@"arm64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -5720,9 +5696,6 @@"loong64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -5737,9 +5710,6 @@"loong64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -5754,9 +5724,6 @@"ppc64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -5771,9 +5738,6 @@"riscv64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -5788,9 +5752,6 @@"riscv64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -5805,9 +5766,6 @@"s390x"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -5822,9 +5780,6 @@"x64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -5839,9 +5794,6 @@"x64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [diff --git a/web/js/modules/core/actions.js b/web/js/modules/core/actions.jsindex 0baf98dfd..7de144555 100644--- a/web/js/modules/core/actions.js+++ b/web/js/modules/core/actions.js@@ -27,14 +27,31 @@ export async function requestAction(url,mimeType,id,- options,+ options = {},) {+ const opts = options || {};+dispatch(startRequest(actionName, id));try {- const response = await fetch(url, options);- const data = mimeType === 'application/json'- ? await response.json()- : await response.text();+ const response = await fetch(url, opts);++ let data;+ if (mimeType === 'application/json') {+ if (opts.parser) {+ const rawText = await response.text();+ data = opts.parser(rawText);+ } else {+ if (typeof response.json === 'function') {+ data = await response.json();+ } else {+ const rawText = await response.text();+ data = rawText ? JSON.parse(rawText) : null;+ }+ }+ } else {+ data = await response.text();+ }+dispatch(fetchSuccess(actionName, data, id));return data;} catch (error) {diff --git a/web/js/modules/natural-events/actions.js b/web/js/modules/natural-events/actions.jsindex f2f447cdd..5a6abedca 100644--- a/web/js/modules/natural-events/actions.js+++ b/web/js/modules/natural-events/actions.js@@ -17,6 +17,7 @@ import {UNHIGHLIGHT_EVENT,} from './constants';import { requestAction } from '../core/actions';+import { safeParseEonet } from './util';export function requestEvents() {return (dispatch, getState) => {@@ -27,6 +28,8 @@ export function requestEvents() {REQUEST_EVENTS,requestUrl,'application/json',+ null,+ { parser: safeParseEonet },);};}diff --git a/web/js/modules/natural-events/actions.test.js b/web/js/modules/natural-events/actions.test.jsindex f8d7ea543..5929bdf96 100644--- a/web/js/modules/natural-events/actions.test.js+++ b/web/js/modules/natural-events/actions.test.js@@ -28,7 +28,7 @@ jest.mock('../core/actions', () => ({requestAction: jest.fn(),}));-import { getEventsRequestURL } from './util';+import { getEventsRequestURL, safeParseEonet } from './util';import { requestAction } from '../core/actions';describe('requestEvents', () => {@@ -55,6 +55,8 @@ describe('requestEvents', () => {'REQUEST_EVENTS','http://mock-url/events','application/json',+ null,+ { parser: safeParseEonet},);});});diff --git a/web/js/modules/natural-events/util.js b/web/js/modules/natural-events/util.jsindex 5dca043e3..6981e82d2 100644--- a/web/js/modules/natural-events/util.js+++ b/web/js/modules/natural-events/util.js@@ -196,3 +196,27 @@ export const validateGeometryCoords = (geometry, proj) => {}return undefined;};++/**+* Helper to safely recover valid EONET events from a malformed JSON payload.+*/+export function safeParseEonet(rawText) {+ try {+ return JSON.parse(rawText);+ } catch (err) {+ console.warn('[EONET] Malformed payload received. Salvaging valid events...', err);+ const matches = rawText.match(/\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\}/g) || [];+ const events = [];++ for (const match of matches) {+ if (match.includes('"id"') && match.includes('"geometry"')) {+ try {+ events.push(JSON.parse(match));+ } catch (e) {+ console.log('Invalid event format:', e);+ }+ }+ }+ return { events };+ }+}diff --git a/web/mock/events_data.json-malformed b/web/mock/events_data.json-malformednew file mode 100644index 000000000..b5a50a818--- /dev/null+++ b/web/mock/events_data.json-malformed@@ -0,0 +1,441 @@++{+ "title": "EONET Events",+ "description": "Natural events from EONET.",+ "link": "https://eonet.gsfc.nasa.gov/api/v3/events",+ "events": [+ {+ "id": "EONET_2793",+ "title": "Elm Fire, California",+ "description": "",+ "link": "http://eonet.gsfc.nasa.gov/api/v3/events/EONET_2793",+ "categories": [+ {+ "id": "wildfires",+ "title": "Wildfires"+ }+ ],+ "sources": [+ {+ "id": "CALFIRE",+ "url": "http://www.fire.ca.gov/current_incidents/incidentdetails/Index/1496"+ }++ ],+ "geometry": [+ {+ "date": "2017-05-18T00:00:00Z",+ "type": "Point", "coordinates": [ -120.37116, 36.12089 ]+ },+ {+ "date": "2017-06-18T00:00:00Z",+ "type": "Point", "coordinates": [ -120.37116, 36.12089 ]+ }++ ]+ },+ {+ "id": "EONET_2792",+ "title": "Santiago, Chile Flooding",+ "description": "",+ "link": "http://eonet.gsfc.nasa.gov/api/v3/events/EONET_2792",+ "categories": [+ {+ "id": "floods",+ "title": "Floods"+ }+ ],+ "sources": [+ {+ "id": "IDC",+ "url": "https://www.disasterscharter.org/web/guest/-/flood-in-chile-call-609-"+ }++ ],+ "geometry": [+ {+ "date": "2017-05-13T00:00:00Z",+ "type": "Point", "coordinates": [ -70.6640625, -33.45894275368763 ]+ },+ {+ "date": "2017-06-13T00:00:00Z",+ "type": "Point", "coordinates": [ -70.6640625, -33.45894275368763 ]+ }++ ]+ },+ {+ "id": "EONET_2781",+ "title": "Langila Volcano, Papua New Guinea",+ "description": "",+ "link": "http://eonet.gsfc.nasa.gov/api/v3/events/EONET_2781",+ "categories": [+ {+ "id": "volcanoes",+ "title": "Volcanoes"+ }+ ],+ "sources": [+ {+ "id": "SIVolcano",+ "url": "http://volcano.si.edu/volcano.cfm?vn=252010"+ }++ ],+ "geometry": [+ {+ "date": "2017-04-23T00:00:00Z",+ "type": "Point", "coordinates": [ 148.42, -5.525 ]+ },+ {+ "date": "2017-05-23T00:00:00Z",+ "type": "Point", "coordinates": [ 148.42, -5.525 ]+ }++ ]+ },+ {+ "id": "EONET_2733",+ "title": "Iceberg B30",+ "description": "",+ "link": "http://eonet.gsfc.nasa.gov/api/v3/events/EONET_2733",+ "categories": [+ {+ "id": "seaLakeIce",+ "title": "Sea and Lake Ice"+ }+ ],+ "sources": [+ {+ "id": "NATICE",+ "url": ""+ }+ ],+ "geometry": [+ {+ "date": "2012-08-08T00:00:00Z",+ "type": "Point", "coordinates": [ -107.0791, -74.6012 ]+ },+ {+ "date": "2012-09-09T00:00:00Z",+ "type": "Point", "coordinates": [ -107.0791, -74.6012 ]+ },+ {+ "date": "2012-10-01T00:00:00Z",+ "type": "Point", "coordinates": [ -106.8485, -74.4301 ]+ },+ {+ "date": "2012-11-09T00:00:00Z",+ "type": "Point", "coordinates": [ -107.0473, -73.9919 ]+ },+ {+ "date": "2012-12-04T00:00:00Z",+ "type": "Point", "coordinates": [ -108.3369, -73.3476 ]+ },+ {+ "date": "2013-01-21T00:00:00Z",+ "type": "Point", "coordinates": [ -109.1054, -72.9535 ]+ },+ {+ "date": "2013-02-10T00:00:00Z",+ "type": "Point", "coordinates": [ -109.9264, -72.6757 ]+ },+ {+ "date": "2013-03-12T00:00:00Z",+ "type": "Point", "coordinates": [ -110.5143, -72.7185 ]+ },+ {+ "date": "2013-04-04T00:00:00Z",+ "type": "Point", "coordinates": [ -112.2076, -72.3576 ]+ },+ {+ "date": "2013-09-04T00:00:00Z",+ "type": "Point", "coordinates": [ -114.8741, -71.4385 ]+ },+ {+ "date": "2013-10-03T00:00:00Z",+ "type": "Point", "coordinates": [ -115.4525, -71.5515 ]+ },+ {+ "date": "2013-11-03T00:00:00Z",+ "type": "Point", "coordinates": [ -119.1569, -71.6348 ]+ },+ {+ "date": "2013-12-03T00:00:00Z",+ "type": "Point", "coordinates": [ -119.6126, -71.4968 ]+ },+ {+ "date": "2014-01-03T00:00:00Z",+ "type": "Point", "coordinates": [ -118.7164, -71.5061 ]+ },+ {+ "date": "2014-02-04T00:00:00Z",+ "type": "Point", "coordinates": [ -120.0084, -71.3578 ]+ },+ {+ "date": "2014-04-02T00:00:00Z",+ "type": "Point", "coordinates": [ -120.3049, -71.4506 ]+ },+ {+ "date": "2014-09-02T00:00:00Z",+ "type": "Point", "coordinates": [ -122.4766, -71.7122 ]+ },+ {+ "date": "2014-10-03T00:00:00Z",+ "type": "Point", "coordinates": [ -129.4619, -73.2982 ]+ },+ {+ "date": "2014-11-15T00:00:00Z",+ "type": "Point", "coordinates": [ -128.7063, -73.5593 ]+ },+ {+ "date": "2014-12-05T00:00:00Z",+ "type": "Point", "coordinates": [ -128.3491, -73.9525 ]+ },+ {+ "date": "2015-01-18T00:00:00Z",+ "type": "Point", "coordinates": [ -128.7291, -73.7930 ]+ },+ {+ "date": "2015-02-14T00:00:00Z",+ "type": "Point", "coordinates": [ -130.1039, -73.9265 ]+ },+ {+ "date": "2015-03-06T00:00:00Z",+ "type": "Point", "coordinates": [ -131.3582, -74.0653 ]+ },+ {+ "date": "2015-11-15T00:00:00Z",+ "type": "Point", "coordinates": [ -131.6436, -73.8799 ]+ },+ {+ "date": "2015-12-10T00:00:00Z",+ "type": "Point", "coordinates": [ -131.7159, -73.6767 ]+ },+ {+ "date": "2016-01-15T00:00:00Z",+ "type": "Point", "coordinates": [ -132.3065, -73.8905 ]+ },+ {+ "date": "2016-02-01T00:00:00Z",+ "type": "Point", "coordinates": [ -134.2615, -73.7783 ]+ },+ {+ "date": "2016-03-12T00:00:00Z",+ "type": "Point", "coordinates": [ -137.2411, -74.0321 ]+ },+ {+ "date": "2016-04-09T00:00:00Z",+ "type": "Point", "coordinates": [ -140.9370, -74.0345 ]+ },+ {+ "date": "2017-02-24T00:00:00Z",+ "type": "Point", "coordinates": [ -155.23, -73.63 ]+ }++ ]+ },+ {+ "id": "EONET_2733",+ "title": "Iceberg B30-TEST",+ "description": "",+ "link": "http://eonet.gsfc.nasa.gov/api/v3/events/EONET_2733",+ "categories": [+ {+ "id": "seaLakeIce",+ "title": "Sea and Lake Ice"+ }+ ],+ "sources": [+ {+ "id": "NATICE",+ "url": ""+ }++ ],+ "geometry": [+ {+ "date": "2012-08-08T00:00:00Z",+ "type": "Point", "coordinates": [ -107.0791, -74.6012 ]+ },+ {+ "date": "2012-09-09T00:00:00Z",+ "type": "Point", "coordinates": [ -107.0791, -74.6012 ]+ },+ {+ "date": "2012-10-01T00:00:00Z",+ "type": "Point", "coordinates": [ -106.8485, -74.4301 ]+ },+ {+ "date": "2012-11-09T00:00:00Z",+ "type": "Point", "coordinates": [ -107.0473, -73.9919 ]+ },+ {+ "date": "2012-12-04T00:00:00Z",+ "type": "Point", "coordinates": [ -108.3369, -73.3476 ]+ },+ {+ "date": "2013-01-21T00:00:00Z",+ "type": "Point", "coordinates": [ -109.1054, -72.9535 ]+ },+ {+ "date": "2013-02-10T00:00:00Z",+ "type": "Point", "coordinates": [ -109.9264, -72.6757 ]+ },+ {+ "date": "2013-03-12T00:00:00Z",+ "type": "Point", "coordinates": [ -110.5143, -72.7185 ]+ },+ {+ "date": "2013-04-04T00:00:00Z",+ "type": "Point", "coordinates": [ -112.2076, -72.3576 ]+ },+ {+ "date": "2013-09-04T00:00:00Z",+ "type": "Point", "coordinates": [ -114.8741, -71.4385 ]+ },+ {+ "date": "2013-10-03T00:00:00Z",+ "type": "Point", "coordinates": [ -115.4525, -71.5515 ]+ },+ {+ "date": "2013-11-03T00:00:00Z",+ "type": "Point", "coordinates": [ -119.1569, -71.6348 ]+ },+ {+ "date": "2013-12-03T00:00:00Z",+ "type": "Point", "coordinates": [ -119.6126, -71.4968 ]+ },+ {+ "date": "2014-01-03T00:00:00Z",+ "type": "Point", "coordinates": [ -118.7164, -71.5061 ]+ },+ {+ "date": "2014-02-04T00:00:00Z",+ "type": "Point", "coordinates": [ -120.0084, -71.3578 ]+ },+ {+ "date": "2014-04-02T00:00:00Z",+ "type": "Point", "coordinates": [ -120.3049, -71.4506 ]+ },+ {+ "date": "2014-09-02T00:00:00Z",+ "type": "Point", "coordinates": [ -122.4766, -71.7122 ]+ },+ {+ "date": "2014-10-03T00:00:00Z",+ "type": "Point", "coordinates": [ -129.4619, -73.2982 ]+ },+ {+ "date": "2014-11-15T00:00:00Z",+ "type": "Point", "coordinates": [ -128.7063, -73.5593 ]+ },+ {+ "date": "2014-12-05T00:00:00Z",+ "type": "Point", "coordinates": [ -128.3491, -73.9525 ]+ },+ {+ "date": "2015-01-18T00:00:00Z",+ "type": "Point", "coordinates": [ -128.7291, -73.7930 ]+ },+ {+ "date": "2015-02-14T00:00:00Z",+ "type": "Point", "coordinates": [ -130.1039, -73.9265 ]+ },+ {+ "date": "2015-03-06T00:00:00Z",+ "type": "Point", "coordinates": [ -131.3582, -74.0653 ]+ },+ {+ "date": "2015-11-15T00:00:00Z",+ "type": "Point", "coordinates": [ -131.6436, -73.8799 ]+ },+ {+ "date": "2015-12-10T00:00:00Z",+ "type": "Point", "coordinates": [ -131.7159, -73.6767 ]+ },+ {+ "date": "2016-01-15T00:00:00Z",+ "type": "Point", "coordinates": [ -132.3065, -73.8905 ]+ },+ {+ "date": "2016-02-01T00:00:00Z",+ "type": "Point", "coordinates": [ -134.2615, -73.7783 ]+ },+ {+ "date": "2016-03-12T00:00:00Z",+ "type": "Point", "coordinates": [ -137.2411, -74.0321 ]+ },+ {+ "date": "2016-04-09T00:00:00Z",+ "type": "Point", "coordinates": [ -140.9370, -74.0345 ]+ },+ {+ "date": "2017-02-24T00:00:00Z",+ "type": "Point", "coordinates": [ -155.23, -73.63 ]+ },+ {+ "date": "2017-05-24T00:00:00Z",+ "type": "Point", "coordinates": [ -155.23, -73.63 ]+ }++ ]+ },+ {+ "id": "EONET_0001",+ "title": "Example id 1",+ "description": "",+ "link": "http://eonet.gsfc.nasa.gov/api/v3/events/EONET_0001",+ "categories": [+ {+ "id": "seaLakeIce",+ "title": "Sea and Lake Ice"+ }+ ],+ "sources": [+ {+ "id": "NATICE",+ "url": ""+ }+ ],+ "geometry": [+ {+ "date": "2012-10-04T00:00:00Z",+ "type": "Point", "coordinates": [ -41.3934, -75.8634 ]+ },+ {+ "date": "2012-11-04T00:00:00Z",+ "type": "Point", "coordinates": [ -41.3934, -75.8634 ]+ }+ ]+ },+ {+ "id": "EONET_5001",+ "title": "Example id 5001",+ "description": "Malformed coordinates array",+ "link": "http://eonet.gsfc.nasa.gov/api/v3/events/EONET_5001",+ "categories": [+ {+ "id": "seaLakeIce",+ "title": "Sea and Lake Ice"+ }+ ],+ "sources": [+ {+ "id": "NATICE",+ "url": ""+ }+ ],+ "geometry": [+ {+ "date": "2012-10-04T00:00:00Z",+ "type": "Point", "coordinates": [ -41.3934, -75.8634+ },+ {+ "date": "2012-11-04T00:00:00Z",+ "type": "Point", "coordinates": [ -41.3934, -75.8634 ]+ }+ ]+ }+ ]+}