Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

#3429 events on mobile fix

Jason Kent557db8459169
diff --git a/e2e/features/events/events-mobile-test.js b/e2e/features/events/events-mobile-test.js
new file mode 100644
index 000000000..6505076d4
--- /dev/null
+++ b/e2e/features/events/events-mobile-test.js
@@ -0,0 +1,43 @@
+const reuseables = require('../../reuseables/skip-tour.js');
+const localQueryStrings = require('../../reuseables/querystrings.js');
+
+const TIME_LIMIT = 10000;
+
+const sidebarButton = '#accordion-toggler-button';
+const sidebarContent = '#productsHolder';
+const eventsTab = '#events-sidebar-tab';
+const icebergEvent = '#wv-events #sidebar-event-EONET_2703';
+const selectedMarker = '.marker-selected';
+const trackMarker = '.track-marker';
+
+module.exports = {
+ before(c) {
+ reuseables.loadAndSkipTour(c, TIME_LIMIT);
+ c.resizeWindow(375, 667); // iPhone 6/7/8 dimensions
+ },
+ 'Events populated in sidebar': (c) => {
+ c.url(c.globals.url + localQueryStrings.mockEvents);
+ c.click(sidebarButton);
+ c.waitForElementVisible(sidebarContent, TIME_LIMIT);
+ c.click(eventsTab);
+ c.waitForElementVisible(icebergEvent, TIME_LIMIT);
+ },
+ 'Clicking event in list closes sidebar and selects marker for event on map': (c) => {
+ c.click(icebergEvent);
+ c.waitForElementVisible(selectedMarker, TIME_LIMIT);
+ c.expect.element(sidebarContent).to.not.be.visible;
+ c.expect.element(sidebarButton).to.be.present;
+ c.expect.element(selectedMarker).to.be.present;
+ },
+ 'Events load when arriving via permalink': (c) => {
+ c.url(c.globals.url + localQueryStrings.stormEventSelected);
+ c.waitForElementVisible(selectedMarker, TIME_LIMIT);
+ c.expect.element(sidebarContent).to.not.be.visible;
+ c.expect.element(sidebarButton).to.be.present;
+ c.expect.element(selectedMarker).to.be.present;
+ c.expect.element(trackMarker).to.be.present;
+ },
+ after(c) {
+ c.end();
+ },
+};
diff --git a/e2e/reuseables/querystrings.js b/e2e/reuseables/querystrings.js
index f0ac44092..c5868a2c6 100644
--- a/e2e/reuseables/querystrings.js
+++ b/e2e/reuseables/querystrings.js
@@ -25,6 +25,7 @@ module.exports = {
// events
eventsTabActive: '?e=true',
mockEvents: '?p=geographic&l=VIIRS_SNPP_CorrectedReflectance_TrueColor(hidden),MODIS_Aqua_CorrectedReflectance_TrueColor(hidden),MODIS_Terra_CorrectedReflectance_TrueColor,Reference_Labels(hidden),Reference_Features(hidden),Coastlines&t=2018-05-02-T00%3A00%3A00Z&z=3&v=-409.00147812273656,-205.62883007565202,270.5880270080828,219.11461063111003&e=true&mockEvents=20170530',
+ stormEventSelected: '?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',
closedEvent: '?e=EONET_5133',
// layers
diff --git a/web/js/containers/sidebar/events.js b/web/js/containers/sidebar/events.js
index 6c14f1982..9407356dc 100644
--- a/web/js/containers/sidebar/events.js
+++ b/web/js/containers/sidebar/events.js
@@ -8,8 +8,6 @@ import {
import Event from '../../components/sidebar/event';
import Scrollbars from '../../components/util/scrollbar';
import {
- requestEvents as requestEventsActionCreator,
- requestSources as requestSourcesActionCreator,
selectEvent as selectEventActionCreator,
deselectEvent as deselectEventActionCreator,
selectCategory as selectCategoryActionCreator,
@@ -25,10 +23,6 @@ import util from '../../util/util';
function Events(props) {
const {
- requestSources,
- requestEvents,
- apiURL,
- config,
eventsData,
eventCategories,
sources,
@@ -57,30 +51,6 @@ function Events(props) {
const scrollbarMaxHeight = height - dropdownHeight;
let showInactiveEventAlert = selected.id && !selected.date;
- // init requests
- useEffect(() => {
- if (!isLoading && !hasRequestError && !eventsData) {
- let eventsRequestURL = `${apiURL}/events`;
- let sourceRequestURL = `${apiURL}/sources`;
-
- const mockEvents = lodashGet(config, 'parameters.mockEvents');
- const mockSources = lodashGet(config, 'parameters.mockSources');
-
- if (mockEvents) {
- console.warn(`Using mock events data: ${mockEvents}`);
- eventsRequestURL = mockEvents === 'true'
- ? 'mock/events_data.json'
- : `mock/events_data.json-${mockEvents}`;
- }
- if (mockSources) {
- console.warn(`Using mock categories data: ${mockSources}`);
- sourceRequestURL = `mock/categories_data.json-${mockSources}`;
- }
- requestEvents(eventsRequestURL);
- requestSources(sourceRequestURL);
- }
- });
-
// Deselect event if it's not visible in the map extent
useEffect(() => {
if (selected.id && selected.date && !visibleWithinMapExtent[selected.id] && eventsData && eventsData.length) {
@@ -206,35 +176,21 @@ const mapDispatchToProps = (dispatch) => ({
selectCategory: (category) => {
dispatch(selectCategoryActionCreator(category));
},
- requestEvents: (url) => {
- dispatch(requestEventsActionCreator(url));
- },
- requestSources: (url) => {
- dispatch(requestSourcesActionCreator(url));
- },
});
-const mapStateToProps = (state) => {
+const mapStateToProps = (state, ownProps) => {
const {
animation,
- requestedEvents,
- requestedEventSources,
- config,
proj,
browser,
events,
} = state;
+ const { eventsData } = ownProps;
const {
selected, showAll, category,
} = events;
- const apiURL = lodashGet(state, 'config.features.naturalEvents.host');
- const isLoading = requestedEvents.isLoading
- || requestedEventSources.isLoading;
- const hasRequestError = requestedEvents.error
- || requestedEventSources.error;
let visibleEvents = {};
- const eventsData = lodashGet(requestedEvents, 'response');
- const sources = lodashGet(requestedEventSources, 'response');
+
const mapExtent = lodashGet(state, 'map.extent');
let visibleWithinMapExtent = {};
@@ -257,17 +213,11 @@ const mapStateToProps = (state) => {
}
return {
- eventsData,
eventCategories: getEventCategories(state),
- sources,
showAll,
- isLoading,
- hasRequestError,
selected,
visibleWithinMapExtent,
visibleEvents,
- apiURL,
- config,
isPlaying: animation.isPlaying,
isMobile: browser.lessThan.medium,
isAnimatingToEvent: events.isAnimatingToEvent,
@@ -281,9 +231,7 @@ export default connect(
)(Events);
Events.propTypes = {
- apiURL: PropTypes.string,
eventCategories: PropTypes.array,
- config: PropTypes.object,
deselectEvent: PropTypes.func,
eventsData: PropTypes.array,
hasRequestError: PropTypes.bool,
@@ -292,8 +240,6 @@ Events.propTypes = {
isLoading: PropTypes.bool,
isMobile: PropTypes.bool,
isAnimatingToEvent: PropTypes.bool,
- requestEvents: PropTypes.func,
- requestSources: PropTypes.func,
selected: PropTypes.object,
selectedDate: PropTypes.string,
selectEvent: PropTypes.func,
diff --git a/web/js/containers/sidebar/sidebar.js b/web/js/containers/sidebar/sidebar.js
index 3ab065f5a..5e1892ca9 100644
--- a/web/js/containers/sidebar/sidebar.js
+++ b/web/js/containers/sidebar/sidebar.js
@@ -15,13 +15,16 @@ import {
loadCustom as loadCustomPalette,
} from '../../modules/palettes/util';
import { loadedCustomPalettes } from '../../modules/palettes/actions';
+import {
+ requestEvents as requestEventsActionCreator,
+ requestSources as requestSourcesActionCreator,
+} from '../../modules/natural-events/actions';
import { getAllActiveLayers } from '../../modules/layers/selectors';
import ErrorBoundary from '../error-boundary';
import util from '../../util/util';
import {
changeTab as changeTabAction,
toggleSidebarCollapse as toggleSidebarCollapseAction,
- collapseSidebar as collapseSidebarAction,
expandSidebar as expandSidebarAction,
} from '../../modules/sidebar/actions';
import safeLocalStorage from '../../util/local-storage';
@@ -64,6 +67,7 @@ class Sidebar extends React.Component {
loadedCustomPalettes(customs);
});
this.updateDimensions();
+ this.loadEvents();
// prevent browser zooming in safari
if (util.browser.safari) {
const onGestureCallback = (e) => {
@@ -79,6 +83,39 @@ class Sidebar extends React.Component {
this.updateDimensions();
}
+ loadEvents() {
+ const {
+ isLoadingEvents,
+ hasEventRequestError,
+ eventsData,
+ eventRequestUrl,
+ config,
+ requestEvents,
+ requestSources,
+ } = this.props;
+
+ if (!isLoadingEvents && !hasEventRequestError && !eventsData) {
+ let eventsRequestURL = `${eventRequestUrl}/events`;
+ let sourceRequestURL = `${eventRequestUrl}/sources`;
+
+ const mockEvents = lodashGet(config, 'parameters.mockEvents');
+ const mockSources = lodashGet(config, 'parameters.mockSources');
+
+ if (mockEvents) {
+ console.warn(`Using mock events data: ${mockEvents}`);
+ eventsRequestURL = mockEvents === 'true'
+ ? 'mock/events_data.json'
+ : `mock/events_data.json-${mockEvents}`;
+ }
+ if (mockSources) {
+ console.warn(`Using mock categories data: ${mockSources}`);
+ sourceRequestURL = `mock/categories_data.json-${mockSources}`;
+ }
+ requestEvents(eventsRequestURL);
+ requestSources(sourceRequestURL);
+ }
+ }
+
updateDimensions() {
const { subComponentHeight } = this.state;
const footerHeight = lodashGet(this, 'footerElement.clientHeight') || 20;
@@ -109,15 +146,6 @@ class Sidebar extends React.Component {
}
}
- selectEvent(id, date) {
- const { selectEvent } = this.state;
- const { isMobile, collapseSidebar } = this.props;
- selectEvent(id, date);
- if (isMobile) {
- collapseSidebar();
- }
- }
-
toggleSidebar() {
const {
isCollapsed,
@@ -172,11 +200,16 @@ class Sidebar extends React.Component {
isMobile,
changeTab,
isDataDisabled,
+ isLoadingEvents,
+ hasEventRequestError,
+ eventsData,
+ eventsSources,
} = this.props;
if (isMobile && activeTab === 'download') changeTab('layers');
const wheelCallBack = util.browser.chrome ? util.preventPinch : null;
const { naturalEvents } = config.features;
const { smartHandoffs } = config.features;
+
return (
<ErrorBoundary>
<section id="wv-sidebar">
@@ -228,6 +261,10 @@ class Sidebar extends React.Component {
{naturalEvents && activeTab === 'events' && (
<Events
height={subComponentHeight}
+ isLoading={isLoadingEvents}
+ hasRequestError={hasEventRequestError}
+ eventsData={eventsData}
+ sources={eventsSources}
/>
)}
</TabPane>
@@ -263,8 +300,19 @@ function mapStateToProps(state) {
measure,
animation,
events,
+ requestedEvents,
+ requestedEventSources,
ui,
} = state;
+
+ const eventRequestUrl = lodashGet(state, 'config.features.naturalEvents.host');
+ const isLoadingEvents = requestedEvents.isLoading
+ || requestedEventSources.isLoading;
+ const hasEventRequestError = requestedEvents.error
+ || requestedEventSources.error;
+ const eventsData = lodashGet(requestedEvents, 'response');
+ const eventsSources = lodashGet(requestedEventSources, 'response');
+
const { screenHeight } = browser;
const { isDistractionFreeModeActive } = ui;
const { activeTab, isCollapsed, mobileCollapsed } = sidebar;
@@ -277,16 +325,21 @@ function mapStateToProps(state) {
const shouldBeCollapsed = snapshotModalOpen || measure.isActive || animation.gifActive;
return {
activeTab,
- isMobile,
- screenHeight,
- isCompareMode: compare.active,
activeString,
+ config,
+ eventRequestUrl,
+ eventsData,
+ eventsSources,
numberOfLayers,
- isDataDisabled: events.isAnimatingToEvent,
+ hasEventRequestError,
isCollapsed: isMobile ? mobileCollapsed : isCollapsed || shouldBeCollapsed,
- tabTypes,
- config,
+ isCompareMode: compare.active,
+ isDataDisabled: events.isAnimatingToEvent,
isDistractionFreeModeActive,
+ isLoadingEvents,
+ isMobile,
+ screenHeight,
+ tabTypes,
};
}
const mapDispatchToProps = (dispatch) => ({
@@ -303,15 +356,18 @@ const mapDispatchToProps = (dispatch) => ({
collapseExpandToggle: () => {
dispatch(toggleSidebarCollapseAction());
},
- collapseSidebar: () => {
- dispatch(collapseSidebarAction());
- },
expandSidebar: () => {
dispatch(expandSidebarAction());
},
loadedCustomPalettes: (customs) => {
dispatch(loadedCustomPalettes(customs));
},
+ requestEvents: (url) => {
+ dispatch(requestEventsActionCreator(url));
+ },
+ requestSources: (url) => {
+ dispatch(requestSourcesActionCreator(url));
+ },
});
export default connect(
@@ -325,16 +381,22 @@ Sidebar.propTypes = {
activeTab: PropTypes.string,
changeTab: PropTypes.func,
collapseExpandToggle: PropTypes.func,
- collapseSidebar: PropTypes.func,
config: PropTypes.object,
+ eventsData: PropTypes.array,
+ eventsSources: PropTypes.array,
+ eventRequestUrl: PropTypes.string,
+ hasEventRequestError: PropTypes.bool,
isCollapsed: PropTypes.bool,
isCompareMode: PropTypes.bool,
isDataDisabled: PropTypes.bool,
isDistractionFreeModeActive: PropTypes.bool,
+ isLoadingEvents: PropTypes.bool,
isMobile: PropTypes.bool,
loadedCustomPalettes: PropTypes.func,
numberOfLayers: PropTypes.number,
onTabClick: PropTypes.func,
screenHeight: PropTypes.number,
tabTypes: PropTypes.object,
+ requestEvents: PropTypes.func,
+ requestSources: PropTypes.func,
};