Interactive interface for browsing global, full-resolution satellite imagery
various updates
Jason Kent71d7acf24ad7
diff --git a/config/default/common/config/wv.json/naturalEvents.json b/config/default/common/config/wv.json/naturalEvents.jsonindex 35b7eb8ec..0392e498b 100644--- a/config/default/common/config/wv.json/naturalEvents.json+++ b/config/default/common/config/wv.json/naturalEvents.json@@ -1,5 +1,84 @@{"naturalEvents": {+ "categories": [+ {+ "id": "drought",+ "title": "Drought",+ "link": "https://eonet.sci.gsfc.nasa.gov/api/v3/categories/drought",+ "description": "Long lasting absence of precipitation affecting agriculture and livestock, and the overall availability of food and water.",+ "layers": "https://eonet.sci.gsfc.nasa.gov/api/v3/layers/drought"+ },+ {+ "id": "dustHaze",+ "title": "Dust and Haze",+ "link": "https://eonet.sci.gsfc.nasa.gov/api/v3/categories/dustHaze",+ "description": "Related to dust storms, air pollution and other non-volcanic aerosols. Volcano-related plumes shall be included with the originating eruption event.",+ "layers": "https://eonet.sci.gsfc.nasa.gov/api/v3/layers/dustHaze"+ },+ {+ "id": "earthquakes",+ "title": "Earthquakes",+ "link": "https://eonet.sci.gsfc.nasa.gov/api/v3/categories/earthquakes",+ "description": "Related to all manner of shaking and displacement. Certain aftermath of earthquakes may also be found under landslides and floods.",+ "layers": "https://eonet.sci.gsfc.nasa.gov/api/v3/layers/earthquakes"+ },+ {+ "id": "manmade",+ "title": "Manmade",+ "link": "https://eonet.sci.gsfc.nasa.gov/api/v3/categories/manmade",+ "description": "Events that have been human-induced and are extreme in their extent.",+ "layers": "https://eonet.sci.gsfc.nasa.gov/api/v3/layers/manmade"+ },+ {+ "id": "seaLakeIce",+ "title": "Sea and Lake Ice",+ "link": "https://eonet.sci.gsfc.nasa.gov/api/v3/categories/seaLakeIce",+ "description": "Related to all ice that resides on oceans and lakes, including sea and lake ice (permanent and seasonal) and icebergs.",+ "layers": "https://eonet.sci.gsfc.nasa.gov/api/v3/layers/seaLakeIce"+ },+ {+ "id": "severeStorms",+ "title": "Severe Storms",+ "link": "https://eonet.sci.gsfc.nasa.gov/api/v3/categories/severeStorms",+ "description": "Related to the atmospheric aspect of storms (hurricanes, cyclones, tornadoes, etc.). Results of storms may be included under floods, landslides, etc.",+ "layers": "https://eonet.sci.gsfc.nasa.gov/api/v3/layers/severeStorms"+ },+ {+ "id": "snow",+ "title": "Snow",+ "link": "https://eonet.sci.gsfc.nasa.gov/api/v3/categories/snow",+ "description": "Related to snow events, particularly extreme/anomalous snowfall in either timing or extent/depth.",+ "layers": "https://eonet.sci.gsfc.nasa.gov/api/v3/layers/snow"+ },+ {+ "id": "tempExtremes",+ "title": "Temperature Extremes",+ "link": "https://eonet.sci.gsfc.nasa.gov/api/v3/categories/tempExtremes",+ "description": "Related to anomalous land temperatures, either heat or cold.",+ "layers": "https://eonet.sci.gsfc.nasa.gov/api/v3/layers/tempExtremes"+ },+ {+ "id": "volcanoes",+ "title": "Volcanoes",+ "link": "https://eonet.sci.gsfc.nasa.gov/api/v3/categories/volcanoes",+ "description": "Related to both the physical effects of an eruption (rock, ash, lava) and the atmospheric (ash and gas plumes).",+ "layers": "https://eonet.sci.gsfc.nasa.gov/api/v3/layers/volcanoes"+ },+ {+ "id": "waterColor",+ "title": "Water Color",+ "link": "https://eonet.sci.gsfc.nasa.gov/api/v3/categories/waterColor",+ "description": "Related to events that alter the appearance of water: phytoplankton, red tide, algae, sediment, whiting, etc.",+ "layers": "https://eonet.sci.gsfc.nasa.gov/api/v3/layers/waterColor"+ },+ {+ "id": "wildfires",+ "title": "Wildfires",+ "link": "https://eonet.sci.gsfc.nasa.gov/api/v3/categories/wildfires",+ "description": "Wildfires includes all nature of fire, including forest and plains fires, as well as urban and industrial fire events. Fires may be naturally caused or manmade.",+ "layers": "https://eonet.sci.gsfc.nasa.gov/api/v3/layers/wildfires"+ }+ ],"layers": {"arctic": {"Wildfires": [diff --git a/web/css/button.css b/web/css/button.cssindex f060a7f0a..ea07800db 100644--- a/web/css/button.css+++ b/web/css/button.css@@ -47,11 +47,10 @@cursor: not-allowed;}-/** Bootstrap/Reactstrap Button Overrides*/.btn.disabled, .btn:disabled {cursor: not-allowed;-}\ No newline at end of file+}diff --git a/web/css/events.css b/web/css/events.cssindex 07ca189d7..812d9f898 100644--- a/web/css/events.css+++ b/web/css/events.css@@ -385,7 +385,7 @@margin-left: 6px;justify-content: center;display: grid;- grid-template-columns: repeat(auto-fit, minmax(10px, max-content)) ;+ grid-template-columns: repeat(auto-fit, minmax(10px, max-content));max-width: 205px;max-height: 32px;}@@ -415,12 +415,12 @@& svg {stroke: #fff;&:hover {- stroke: #007bff+ stroke: #007bff;}}}& .category-toggles {- margin: 14px 10px 0px 10px;+ margin: 14px 10px 0;}}@@ -431,4 +431,4 @@background: #bbb;border-color: #666;box-shadow: 1px 1px 20px rgba(0, 0, 0, 0.75);-}\ No newline at end of file+}diff --git a/web/css/modal.css b/web/css/modal.cssindex f0e3844f9..366471533 100644--- a/web/css/modal.css+++ b/web/css/modal.css@@ -42,7 +42,7 @@border-bottom-right-radius: 6px;& .modal-footer {padding-bottom: 0;- margin: 14px -13px 0 -13px;+ margin: 14px -13px 0;}}.modal-footer {diff --git a/web/js/components/sidebar/events-filter.js b/web/js/components/sidebar/events-filter.jsindex dd7cd3a11..4f1700f40 100644--- a/web/js/components/sidebar/events-filter.js+++ b/web/js/components/sidebar/events-filter.js@@ -7,6 +7,7 @@ import Switch from '../util/switch';import {setEventsFilter as setEventsFilterAction,} from '../../modules/natural-events/actions';+import util from '../../util/util';function EventsFilter (props) {const {@@ -18,9 +19,13 @@ function EventsFilter (props) {closeModal,} = props;- const [dateRange, setDateRange] = useState([selectedStartDate, selectedEndDate]);+ const [dateRange, setDateRange] = useState([+ new Date(selectedStartDate),+ new Date(selectedEndDate),+ ]);const [allNone, setAllNone] = useState(!!selectedCategories.length);const [categories, setCategories] = useState(selectedCategories);+ const [startDate, endDate] = dateRange || [];const toggleCategory = (category) => {const isActive = categories.some(({ id }) => id === category.id);@@ -34,7 +39,9 @@ function EventsFilter (props) {};const applyFilter = () => {- setFilter(categories, startDate, endDate);+ const start = util.toISOStringDate(startDate);+ const end = util.toISOStringDate(endDate);+ setFilter(categories, start, end);closeModal();};@@ -47,7 +54,7 @@ function EventsFilter (props) {setAllNone(!allNone);};- const [startDate, endDate] = dateRange || [];+const disableApply = !startDate || !endDate || !categories.length;const getDisableApplyMsg = () => {let msg = '';@@ -118,16 +125,18 @@ EventsFilter.propTypes = {closeModal: PropTypes.func,eventCategories: PropTypes.array,selectedCategories: PropTypes.array,- selectedStartDate: PropTypes.object,- selectedEndDate: PropTypes.object,+ selectedStartDate: PropTypes.string,+ selectedEndDate: PropTypes.string,setFilter: PropTypes.func,};const mapStateToProps = (state) => {- const { events, requestedEventCategories } = state;- const { selectedCategories, selectedStartDate, selectedEndDate } = events;+ const { events } = state;+ const {+ selectedCategories, selectedStartDate, selectedEndDate, allCategories,+ } = events;return {- eventCategories: requestedEventCategories.response || [],+ eventCategories: allCategories,selectedCategories,selectedStartDate,selectedEndDate,@@ -136,7 +145,13 @@ const mapStateToProps = (state) => {const mapDispatchToProps = (dispatch) => ({setFilter: (categories, startDate, endDate) => {- dispatch(setEventsFilterAction(categories, startDate, endDate));+ dispatch(+ setEventsFilterAction(+ categories,+ startDate,+ endDate,+ ),+ );},});diff --git a/web/js/components/util/switch.js b/web/js/components/util/switch.jsindex 5937d17b0..454f47e6b 100644--- a/web/js/components/util/switch.js+++ b/web/js/components/util/switch.js@@ -86,7 +86,7 @@ Switch.propTypes = {id: PropTypes.string.isRequired,label: PropTypes.string,toggle: PropTypes.func,- tooltip: PropTypes.object,+ tooltip: PropTypes.string,};export default Switch;diff --git a/web/js/containers/sidebar/events.js b/web/js/containers/sidebar/events.jsindex 097258c4f..f09da12f5 100644--- a/web/js/containers/sidebar/events.js+++ b/web/js/containers/sidebar/events.js@@ -69,7 +69,12 @@ function Events(props) {<div className="filter-icons">{selectedCategories.map(({ title }) => (- <EventIcon id="filter-" category={title} title={title} />+ <EventIcon+ id="filter-"+ key={title}+ category={title}+ title={title}+ />))}</div></div>@@ -81,7 +86,7 @@ function Events(props) {color="primary"size="sm"block- disable={isLoading}+ disabled={isLoading}><FontAwesomeIcon icon="filter" /></Button>@@ -213,8 +218,8 @@ const mapStateToProps = (state, ownProps) => {isEmbedModeActive,isAnimatingToEvent: events.isAnimatingToEvent,selectedCategories,- selectedStartDate: util.toISOStringDate(selectedStartDate),- selectedEndDate: util.toISOStringDate(selectedEndDate),+ selectedStartDate,+ selectedEndDate,selectedDate: util.toISOStringDate(getSelectedDate(state)),};};diff --git a/web/js/containers/sidebar/sidebar.js b/web/js/containers/sidebar/sidebar.jsindex 095618537..9c315057a 100644--- a/web/js/containers/sidebar/sidebar.js+++ b/web/js/containers/sidebar/sidebar.js@@ -20,7 +20,6 @@ import { getPermalink } from '../../modules/link/util';import {requestEvents as requestEventsActionCreator,requestSources as requestSourcesActionCreator,- requestCategories as requestCategoriesActionCreator,} from '../../modules/natural-events/actions';import { getAllActiveLayers } from '../../modules/layers/selectors';import ErrorBoundary from '../error-boundary';@@ -101,18 +100,17 @@ class Sidebar extends React.Component {config,requestEvents,requestSources,- requestCategories,selectedStartDate,selectedEndDate,+ selectedCategories,} = this.props;if (!isLoadingEvents && !hasEventRequestError && !eventsData) {const {- sourcesURL, eventsURL, categoriesURL,- } = initialEventsLoad(config, selectedStartDate, selectedEndDate);+ sourcesURL, eventsURL,+ } = initialEventsLoad(config, selectedStartDate, selectedEndDate, selectedCategories);requestEvents(eventsURL);requestSources(sourcesURL);- requestCategories(categoriesURL);}}@@ -352,16 +350,13 @@ const mapStateToProps = (state) => {requestedEvents,requestedEventSources,sidebar,- requestedEventCategories,ui,} = state;const isLoadingEvents = requestedEvents.isLoading- || requestedEventSources.isLoading- || requestedEventCategories.isLoading;+ || requestedEventSources.isLoading;const hasEventRequestError = !!(requestedEvents.error- || requestedEventSources.error- || requestedEventCategories.error);+ || requestedEventSources.error);const eventsData = lodashGet(requestedEvents, 'response');const eventsSources = lodashGet(requestedEventSources, 'response');const { screenHeight } = browser;@@ -397,6 +392,7 @@ const mapStateToProps = (state) => {isMobile,selectedStartDate: events.selectedStartDate,selectedEndDate: events.selectedEndDate,+ selectedCategories: events.selectedCategories,screenHeight,selectedDate: getSelectedDate(state),tabTypes,@@ -429,9 +425,6 @@ const mapDispatchToProps = (dispatch) => ({requestSources: (url) => {dispatch(requestSourcesActionCreator(url));},- requestCategories: (url) => {- dispatch(requestCategoriesActionCreator(url));- },});export default connect(@@ -460,11 +453,11 @@ Sidebar.propTypes = {numberOfLayers: PropTypes.number,onTabClick: PropTypes.func,screenHeight: PropTypes.number,- selectedStartDate: PropTypes.object,- selectedEndDate: PropTypes.object,+ selectedStartDate: PropTypes.string,+ selectedEndDate: PropTypes.string,+ selectedCategories: PropTypes.array,tabTypes: PropTypes.object,requestEvents: PropTypes.func,requestSources: PropTypes.func,selectedDate: PropTypes.object,- requestCategories: PropTypes.func,};diff --git a/web/js/location.js b/web/js/location.jsindex b52371fb4..cebfbd4b6 100644--- a/web/js/location.js+++ b/web/js/location.js@@ -14,7 +14,9 @@ import {mapLocationToTourState,} from './modules/tour/util';import { getMapParameterSetup } from './modules/map/util';-import { eventParse, serializeEvent } from './modules/natural-events/util';+import {+ parseEvent, serializeEvent, serializeCategories, mapLocationToEventFilterState,+} from './modules/natural-events/util';import { mapLocationToCompareState } from './modules/compare/util';import {mapLocationToProjState,@@ -105,6 +107,11 @@ export const mapLocationToState = (state, location) => {parameters,stateFromLocation,);+ stateFromLocation = mapLocationToEventFilterState(+ parameters,+ stateFromLocation,+ state,+ );// one level deep merge of newState with defaultStateObject.keys(stateFromLocation).forEach((key) => {@@ -298,10 +305,37 @@ const getParameters = function(config, parameters) {type: 'object',initialState: eventsReducerState,options: {- parse: eventParse,+ parse: parseEvent,serialize: serializeEvent,},},+ efsd: {+ stateKey: 'events.selectedStartDate',+ type: 'string',+ initialState: eventsReducerState.selectedStartDate,+ options: {+ parse: (date) => date,+ serialize: (date) => date,+ },+ },+ efed: {+ stateKey: 'events.selectedEndDate',+ type: 'string',+ initialState: eventsReducerState.selectedEndDate,+ options: {+ parse: (date) => date,+ serialize: (date) => date,+ },+ },+ efc: {+ stateKey: 'events.selectedCategories',+ type: 'array',+ initialState: [],+ options: {+ serialize: serializeCategories,+ serializeNeedsGlobalState: true,+ },+ },l: {stateKey: 'layers.active.layers',initialState: startingLayers,diff --git a/web/js/map/natural-events/util.js b/web/js/map/natural-events/util.jsindex bbe7d2891..255d501fe 100644--- a/web/js/map/natural-events/util.js+++ b/web/js/map/natural-events/util.js@@ -22,11 +22,10 @@ export function getEventsRequestURL (baseUrl, startDate, endDate, categories = [return `${baseUrl}/events${util.toQueryString(params)}`;}-export function initialEventsLoad (config, startDate, endDate) {+export function initialEventsLoad (config, startDate, endDate, categories) {const baseUrl = lodashGet(config, 'features.naturalEvents.host');- let eventsURL = getEventsRequestURL(baseUrl, startDate, endDate);+ let eventsURL = getEventsRequestURL(baseUrl, startDate, endDate, categories);let sourcesURL = `${baseUrl}/sources`;- const categoriesURL = `${baseUrl}/categories`;const mockEvents = lodashGet(config, 'parameters.mockEvents');const mockSources = lodashGet(config, 'parameters.mockSources');@@ -44,7 +43,6 @@ export function initialEventsLoad (config, startDate, endDate) {return {sourcesURL,eventsURL,- categoriesURL,};}diff --git a/web/js/modules/combine-reducers.js b/web/js/modules/combine-reducers.jsindex 837fbd5fc..ed26891da 100644--- a/web/js/modules/combine-reducers.js+++ b/web/js/modules/combine-reducers.js@@ -1,15 +1,15 @@import { combineReducers } from 'redux';import { createResponsiveStateReducer } from 'redux-responsive';-import { get as lodashGet, assign as lodashAssign } from 'lodash';+import { assign as lodashAssign } from 'lodash';import { modalReducer, modalAboutPage } from './modal/reducers';import feedbackReducer from './feedback/reducers';import projectionReducer from './projection/reducer';import { locationSearchReducer } from './location-search/reducers';import { shortLink } from './link/reducers';import {+ getInitialEventsState,requestedEvents,requestedEventSources,- requestedEventCategories,eventsReducer,eventRequestResponse,} from './natural-events/reducers';@@ -75,10 +75,6 @@ const responsiveStateReducer = createResponsiveStateReducer(* @param {Object} parameters | parameters parsed from permalink*/export function getInitialState(models, config, parameters) {- const eventsIgnoreArray = {- ignore: lodashGet(config, 'naturalEvents.skip') || [],- };-return {parameters,config,@@ -86,9 +82,9 @@ export function getInitialState(models, config, parameters) {date: getDateInitialState(config),proj: getProjInitialState(config),layers: getLayersInitialState(config),- requestedEvents: eventRequestResponse(eventsIgnoreArray),- requestedEventSources: eventRequestResponse(eventsIgnoreArray),- requestedEventCategories: eventRequestResponse(eventsIgnoreArray),+ events: getInitialEventsState(config),+ requestedEvents: eventRequestResponse(),+ requestedEventSources: eventRequestResponse(),palettes: getInitialPaletteState(config),productPicker: getProductPickerInitialState(config),vectorStyles: getInitialVectorStyleState(config),@@ -125,7 +121,6 @@ const reducers = {imageDownload: imageDownloadReducer,requestedEvents,requestedEventSources,- requestedEventCategories,modalAboutPage,shortLink,smartHandoffs: smartHandoffReducer,diff --git a/web/js/modules/core/actions.js b/web/js/modules/core/actions.jsindex 6acb3c50e..fbcdef09a 100644--- a/web/js/modules/core/actions.js+++ b/web/js/modules/core/actions.js@@ -5,7 +5,6 @@ export function requestAction(mimeType,id,options,- state,) {dispatch(startRequest(actionName, id));return new Promise((resolve, reject) => fetch(url, options)@@ -14,7 +13,7 @@ export function requestAction(: response.text())).then((data) => {- dispatch(fetchSuccess(actionName, data, id, state));+ dispatch(fetchSuccess(actionName, data, id));resolve(data);}).catch((error) => {@@ -31,15 +30,10 @@ export function startRequest(actionName, id) {}export function fetchSuccess(actionName, response, id) {- return (dispatch, getState) => {- const state = getState();- const action = {- type: `${actionName}_SUCCESS`,- response,- ...!!id && { id },- };- if (state) action.state = state;- dispatch(action);+ return {+ type: `${actionName}_SUCCESS`,+ response,+ ...!!id && { id },};}diff --git a/web/js/modules/natural-events/actions.js b/web/js/modules/natural-events/actions.jsindex f992fc482..705c8cb40 100644--- a/web/js/modules/natural-events/actions.js+++ b/web/js/modules/natural-events/actions.js@@ -1,11 +1,9 @@import {get as lodashGet,} from 'lodash';-import { _ } from 'core-js';import {REQUEST_EVENTS,REQUEST_SOURCES,- REQUEST_CATEGORIES,SELECT_EVENT,DESELECT_EVENT,SHOW_ALL_EVENTS,@@ -35,21 +33,6 @@ export function requestSources(location) {);}-export function requestCategories(location) {- return (dispatch, getState) => {- const state = getState();- return requestAction(- dispatch,- REQUEST_CATEGORIES,- location,- 'application/json',- null,- null,- state,- );- };-}-export function selectEvent(id, eventDate) {return {type: SELECT_EVENT,@@ -96,6 +79,7 @@ export function onlyShowVisible() {type: ONLY_SHOW_VISIBLE,};}+export function selected() {return {type: FINISHED_ANIMATING_TO_EVENT,diff --git a/web/js/modules/natural-events/constants.js b/web/js/modules/natural-events/constants.jsindex cc3819808..64291c2b1 100644--- a/web/js/modules/natural-events/constants.js+++ b/web/js/modules/natural-events/constants.js@@ -8,11 +8,6 @@ export const REQUEST_SOURCES_START = 'EVENTS/REQUEST_SOURCES_START';export const REQUEST_SOURCES_FAILURE = 'EVENTS/REQUEST_SOURCES_FAILURE';export const REQUEST_SOURCES_SUCCESS = 'EVENTS/REQUEST_SOURCES_SUCCESS';-export const REQUEST_CATEGORIES = 'EVENTS/REQUEST_CATEGORIES';-export const REQUEST_CATEGORIES_START = 'EVENTS/REQUEST_CATEGORIES_START';-export const REQUEST_CATEGORIES_FAILURE = 'EVENTS/REQUEST_CATEGORIES_FAILURE';-export const REQUEST_CATEGORIES_SUCCESS = 'EVENTS/REQUEST_CATEGORIES_SUCCESS';-export const SET_EVENTS_FILTER = 'EVENTS/SET_FILTER';export const DESELECT_EVENT = 'EVENTS/DESELECT_EVENT';export const SELECT_EVENT = 'EVENTS/SELECT_EVENT';@@ -22,5 +17,3 @@ export const REMOVE_CATEGORY = 'EVENTS/REMOVE_CATEGORY';export const ONLY_SHOW_VISIBLE = 'EVENTS/ONLY_SHOW_VISIBLE';export const TOGGLE_SHOW_ALL = 'EVENTS/TOGGLE_SHOW_ALL';export const FINISHED_ANIMATING_TO_EVENT = 'EVENTS/FINISHED_ANIMATING_TO_EVENT';--export const ALL_CATEGORY = 'All Event Categories';diff --git a/web/js/modules/natural-events/reducers.js b/web/js/modules/natural-events/reducers.jsindex 8de404d19..ed65d6afd 100644--- a/web/js/modules/natural-events/reducers.js+++ b/web/js/modules/natural-events/reducers.js@@ -2,12 +2,10 @@ import {assign as lodashAssign,orderBy as lodashOrderBy,uniqBy as lodashUniqBy,- get as lodashGet,} from 'lodash';import {REQUEST_EVENTS,REQUEST_SOURCES,- REQUEST_CATEGORIES,SELECT_EVENT,DESELECT_EVENT,SET_EVENTS_FILTER,@@ -15,9 +13,9 @@ import {ONLY_SHOW_VISIBLE,TOGGLE_SHOW_ALL,FINISHED_ANIMATING_TO_EVENT,- REQUEST_CATEGORIES_SUCCESS,} from './constants';import { CHANGE_TAB as CHANGE_SIDEBAR_TAB } from '../sidebar/constants';+import util from '../../util/util';/*** Sort events by date, filter by categories@@ -41,22 +39,17 @@ const sortEvents = function(events) {});};-const formatResponse = function(item, ignored) {- if (item.categories) {- const category = Array.isArray(item.categories)- ? item.categories[0]- : item.categories;- // Add slug to categories- category.slug = category.title- .toLowerCase()- .split(' ')- .join('-');- return !ignored.includes(category.title);- }- return !ignored.includes(item.title);-};+const endDate = util.toISOStringDate(new Date());+const startDate = util.toISOStringDate(new Date(new Date().setDate(new Date().getDate() - 60)));-const endDate = new Date();+export function getInitialEventsState(config) {+ const { categories } = config.naturalEvents;+ return {+ ...eventsReducerState,+ allCategories: categories,+ selectedCategories: categories,+ };+}export const eventsReducerState = {selected: {@@ -68,9 +61,10 @@ export const eventsReducerState = {active: false,showAll: true,isAnimatingToEvent: false,+ allCategories: [],selectedCategories: [],- selectedStartDate: new Date(new Date().setDate(endDate.getDate() - 60)),- selectedEndDate: new Date(),+ selectedStartDate: startDate,+ selectedEndDate: endDate,};export function eventsReducer(state = eventsReducerState, action) {@@ -93,15 +87,6 @@ export function eventsReducer(state = eventsReducerState, action) {...state,selected: eventsReducerState.selected,};- case REQUEST_CATEGORIES_SUCCESS: {- const skipCategories = lodashGet(action.state, 'config.naturalEvents.skip') || [];- const { categories } = action.response;- return {- ...state,- selectedCategories: categories- .filter(({ title }) => !skipCategories.includes(title)),- };- }case SET_EVENTS_FILTER:return {@@ -159,7 +144,6 @@ export function eventsRequestReducer(actionName, state, action) {const START = `${actionName}_START`;const SUCCESS = `${actionName}_SUCCESS`;const FAILURE = `${actionName}_FAILURE`;- const selectedCategories = lodashGet(action, 'state.events.selectedCategories') || [];switch (action.type) {case START:@@ -172,14 +156,11 @@ export function eventsRequestReducer(actionName, state, action) {case SUCCESS: {const key = actionName === REQUEST_EVENTS? 'events'- : actionName === REQUEST_CATEGORIES- ? 'categories'- : 'sources';- const filtered = action.response[key].filter((item) => formatResponse(item, state.ignore));+ : 'sources';return eventRequestResponse({response: actionName === REQUEST_EVENTS- ? sortEvents(filtered, selectedCategories)- : filtered,+ ? sortEvents(action.response[key])+ : action.response[key],isLoading: false,});}@@ -202,7 +183,3 @@ export function requestedEvents(state = {}, action) {export function requestedEventSources(state = {}, action) {return eventsRequestReducer(REQUEST_SOURCES, state, action);}--export function requestedEventCategories(state = {}, action) {- return eventsRequestReducer(REQUEST_CATEGORIES, state, action);-}diff --git a/web/js/modules/natural-events/selectors.js b/web/js/modules/natural-events/selectors.jsdeleted file mode 100644index 9daec7688..000000000--- a/web/js/modules/natural-events/selectors.js+++ /dev/null@@ -1,26 +0,0 @@-// import { createSelector } from 'reselect';-// import {-// get as lodashGet,-// } from 'lodash';--const getEvents = ({ requestedEvents }) => (requestedEvents- ? requestedEvents.response- : []-);--const getCategories = ({ requestedEventCategories }) => (requestedEventCategories- ? requestedEventCategories.response- : []-);--// eslint-disable-next-line import/prefer-default-export-// export const getEventCategories = createSelector(-// [getEvents],-// (events) => (events || []).reduce((categories, event) => {-// const categoryTitle = lodashGet(event, 'categories[0].title');-// if (categories.indexOf(categoryTitle) === -1) {-// categories.push(categoryTitle);-// }-// return categories;-// }, []),-// );diff --git a/web/js/modules/natural-events/util.js b/web/js/modules/natural-events/util.jsindex e7655d75c..ecc7cbe0b 100644--- a/web/js/modules/natural-events/util.js+++ b/web/js/modules/natural-events/util.js@@ -1,7 +1,8 @@import { get } from 'lodash';+import update from 'immutability-helper';-export function eventParse(state) {- const values = state.split(',');+export function parseEvent(eventString) {+ const values = eventString.split(',');let id = values[0] || '';let date = values[1] || '';id = id.match(/^EONET_[0-9]+/i) ? values[0] : '';@@ -27,3 +28,23 @@ export function serializeEvent(currentItemState) {? 'true': undefined;}++export function serializeCategories(categories, state) {+ const eventsTabActive = state.events.active;+ return eventsTabActive && categories.map(({ id }) => id);+}++export function mapLocationToEventFilterState(parameters, stateFromLocation, state) {+ const allCategories = state.config.naturalEvents.categories;+ const selectedIds = parameters.efc.split(',');+ const selectedCategories = !allCategories.length+ ? []+ : selectedIds.map((id) => allCategories.find((c) => c.id === id));+ return update(stateFromLocation, {+ events: {+ selectedCategories: {+ $set: selectedCategories,+ },+ },+ });+}