Interactive interface for browsing global, full-resolution satellite imagery
store conceptid, layer id for handoff in permalink
Jason Kent987e0e095827
diff --git a/web/js/containers/sidebar/smart-handoff.js b/web/js/containers/sidebar/smart-handoff.jsindex 65157c3c3..74962e5ce 100644--- a/web/js/containers/sidebar/smart-handoff.js+++ b/web/js/containers/sidebar/smart-handoff.js@@ -1,3 +1,4 @@+/* eslint-disable react/no-did-update-set-state */import React, { Component } from 'react';import PropTypes from 'prop-types';import { connect } from 'react-redux';@@ -20,6 +21,7 @@ import { getActiveLayers } from '../../modules/layers/selectors';import getSelectedDate from '../../modules/date/selectors';import safeLocalStorage from '../../util/local-storage';import openEarthDataSearch from '../../components/smart-handoffs/util';+import selectCollection from '../../modules/smart-handoff/actions';const STD_NRT_MAP = {STD: 'Standard',@@ -53,8 +55,6 @@ class SmartHandoff extends Component {x2: screenWidth / 2 + 100,y2: screenHeight / 2 + 100,},- selectedLayer: undefined,- selectedCollection: undefined,showBoundingBox: false,isSearchingForGranules: false,selectedGranules: 0,@@ -71,6 +71,14 @@ class SmartHandoff extends Component {this.debouncedUpdateExtent = lodashDebounce(this.updateExtent, 250);}+ componentDidMount() {+ const { currentExtent } = this.state;+ const { selectedCollection, selectedLayer } = this.props;+ if (selectedCollection && selectedLayer) {+ this.updateGranuleCount(currentExtent);+ }+ }+/*** When fired, compare prevProps to determine if previously selected layer is still active* and whether or not to update granule data base don data changes.@@ -81,28 +89,25 @@ class SmartHandoff extends Component {availableLayers,displayDate,proj,+ selectedLayer,+ selectedCollection,} = this.props;const {currentExtent,- selectedLayer,- selectedCollection,} = this.state;// Determine if existing selected layer is active still and visibility toggle is 'ON'const isLayerStillActive = availableLayers.find(({ id }) => selectedLayer && selectedLayer.id);if (selectedCollection && !isLayerStillActive) {- // eslint-disable-next-line react/no-did-update-set-statethis.setState(this.baseState);}if (displayDate !== prevProps.displayDate) {- // eslint-disable-next-line react/no-did-update-set-statethis.setState({ totalGranules: undefined }, () => {this.updateGranuleCount(currentExtent);});}if (proj.id !== prevProps.proj.id) {- // eslint-disable-next-line react/no-did-update-set-statethis.setState({ showBoundingBox: false });}}@@ -111,7 +116,8 @@ class SmartHandoff extends Component {* Fires when the bounding box / crop toggle is activated and changed*/updateExtent() {- const { currentExtent, selectedLayer } = this.state;+ const { selectedLayer } = this.props;+ const { currentExtent } = this.state;if (selectedLayer && currentExtent) {this.updateGranuleCount(currentExtent);}@@ -122,8 +128,7 @@ class SmartHandoff extends Component {* @param {*} boundaries - the focal point to which layer data should be contained within*/onBoundaryChange(boundaries) {- const { proj, map } = this.props;- const { selectedCollection } = this.state;+ const { proj, map, selectedCollection } = this.props;if (!selectedCollection) return;@@ -213,12 +218,12 @@ class SmartHandoff extends Component {displayDate,proj,selectedDate,+ selectedLayer,+ selectedCollection,showWarningModal,} = this.props;const {currentExtent,- selectedLayer,- selectedCollection,showBoundingBox,} = this.state;@@ -246,9 +251,9 @@ class SmartHandoff extends Component {*/onLayerChange(layer, collection) {const { currentExtent } = this.state;+ const { selectCollection } = this.props;+ selectCollection(collection.value, layer.id);this.setState({- selectedLayer: layer,- selectedCollection: collection,totalGranules: undefined,}, () => this.updateGranuleCount(currentExtent));}@@ -260,10 +265,12 @@ class SmartHandoff extends Component {* @param {*} currentExtent*/async updateGranuleCount({ southWest, northEast }) {- const { selectedDate } = this.props;const {+ selectedDate,selectedLayer,selectedCollection,+ } = this.props;+ const {showBoundingBox,totalGranules,} = this.state;@@ -330,8 +337,7 @@ class SmartHandoff extends Component {* Render radio buttons for layer selection*/renderLayerChoices() {- const { availableLayers } = this.props;- const { selectedCollection, selectedLayer } = this.state;+ const { availableLayers, selectedCollection, selectedLayer } = this.props;return (<div className="smart-handoff-layer-list">@@ -387,12 +393,12 @@ class SmartHandoff extends Component {proj,screenHeight,screenWidth,+ selectedLayer,} = this.props;const {boundaries,coordinates,- selectedLayer,showBoundingBox,} = this.state;@@ -453,10 +459,10 @@ class SmartHandoff extends Component {const {displayDate,showGranuleHelpModal,+ selectedCollection,} = this.props;const {- selectedCollection,isSearchingForGranules,selectedGranules,showBoundingBox,@@ -518,10 +524,8 @@ class SmartHandoff extends Component {availableLayers,isActive,showNotAvailableModal,- } = this.props;- const {selectedLayer,- } = this.state;+ } = this.props;// Determine if download 'smart-handoff' tab is activated by userif (!isActive) return null;@@ -572,7 +576,10 @@ SmartHandoff.propTypes = {proj: PropTypes.object,screenHeight: PropTypes.number,screenWidth: PropTypes.number,+ selectCollection: PropTypes.func,selectedDate: PropTypes.string,+ selectedLayer: PropTypes.object,+ selectedCollection: PropTypes.object,showWarningModal: PropTypes.func,showGranuleHelpModal: PropTypes.func,showNotAvailableModal: PropTypes.func,@@ -589,8 +596,11 @@ const mapStateToProps = (state) => {browser,map,proj,+ smartHandoffs,} = state;+ const { conceptId, layerId } = smartHandoffs;+const {screenWidth,screenHeight,@@ -604,15 +614,21 @@ const mapStateToProps = (state) => {const filteredConceptIds = (conceptIds || []).filter(({ type, value, version }) => type && value && version);return projections[proj.id] && !disableSmartHandoff && !!filteredConceptIds.length;};+ const availableLayers = getActiveLayers(state).filter(filterForSmartHandoff);++ const selectedLayer = availableLayers.find(({ id }) => id === layerId);+ const selectedCollection = selectedLayer && (selectedLayer.conceptIds || []).find(({ value }) => value === conceptId);return {- availableLayers: getActiveLayers(state).filter(filterForSmartHandoff),+ availableLayers,displayDate,map,proj: proj.selected,screenHeight,screenWidth,selectedDate: selectedDateFormatted,+ selectedLayer,+ selectedCollection,};};@@ -621,6 +637,9 @@ const mapStateToProps = (state) => {* @param {*} dispatch | A function of the Redux store that is triggered upon a change of state.*/const mapDispatchToProps = (dispatch) => ({+ selectCollection: (conceptId, layerId) => {+ dispatch(selectCollection(conceptId, layerId));+ },showWarningModal: (displayDate, selectedLayer, selectedCollection, continueToEDS) => {googleTagManager.pushEvent({event: 'smart_handoffs_open_warning_modal',diff --git a/web/js/location.js b/web/js/location.jsindex bb40c7b21..df25080a5 100644--- a/web/js/location.js+++ b/web/js/location.js@@ -33,6 +33,10 @@ import { mapLocationToAnimationState } from './modules/animation/util';import { areCoordinatesWithinExtent, mapLocationToLocationSearchState } from './modules/location-search/util';import mapLocationToSidebarState from './modules/sidebar/util';import util from './util/util';+import {+ serializeSmartHandoff,+ parseSmartHandoff,+} from './modules/smart-handoff/util';/*** Override state with information from location.search when "REDUX-LOCATION-POP-ACTION"@@ -406,26 +410,17 @@ const getParameters = function(config, parameters) {parse: (str) => str === 'on',},},- // download: {- // stateKey: 'data.selectedProduct',- // initialState: '',- // type: 'string',- // options: {- // delimiter: ',',- // serializeNeedsGlobalState: true,- // parse: (id) => {- // if (!config.products[id]) {- // console.warn(`No such product: ${id}`);- // return '';- // }- // return id;- // },- // serialize: (currentItemState, state) => {- // if (state.sidebar.activeTab !== 'download') return undefined;- // return encode(currentItemState);- // },- // },- // },+ sh: {+ stateKey: 'smartHandoffs',+ initialState: '',+ type: 'string',+ options: {+ setAsEmptyItem: true,+ serializeNeedsGlobalState: true,+ serialize: serializeSmartHandoff,+ parse: parseSmartHandoff,+ },+ },s: {stateKey: 'locationSearch.coordinates',initialState: [],diff --git a/web/js/modules/combine-reducers.js b/web/js/modules/combine-reducers.jsindex 0ec06fd12..1e644c46e 100644--- a/web/js/modules/combine-reducers.js+++ b/web/js/modules/combine-reducers.js@@ -45,6 +45,7 @@ import { LOCATION_POP_ACTION } from '../redux-location-state-customs';import uiReducers from './ui/reducers';import { alertReducer } from './alerts/reducer';+import { smartHandoffReducer } from './smart-handoff/reducer';function lastAction(state = null, action) {return action;@@ -123,6 +124,7 @@ const reducers = {requestedEventSources,modalAboutPage,shortLink,+ smartHandoffs: smartHandoffReducer,notificationsRequest,lastAction,location: locationReducer,diff --git a/web/js/modules/sidebar/util.js b/web/js/modules/sidebar/util.jsindex 93424f4c9..7245b4a5c 100644--- a/web/js/modules/sidebar/util.js+++ b/web/js/modules/sidebar/util.js@@ -1,5 +1,4 @@import update from 'immutability-helper';-import { assign as lodashAssign } from 'lodash';/*** Update sidebar state when location-pop action occurs@@ -15,21 +14,21 @@ export default function mapLocationToSidebarState(state,config,) {+ let activeTab;if (parameters.e) {- const sidebarState = lodashAssign({}, state.sidebar, {- activeTab: 'events',- });- stateFromLocation = update(stateFromLocation, {- sidebar: { $set: sidebarState },- });- // TODO need to handle smart-handoffs param here?+ activeTab = 'events';+ } else if (parameters.sh) {+ activeTab = 'download';} else {- const sidebarState = lodashAssign({}, state.sidebar, {- activeTab: 'layers',- });- stateFromLocation = update(stateFromLocation, {- sidebar: { $set: sidebarState },- });+ activeTab = 'layers';}+ stateFromLocation = update(stateFromLocation, {+ sidebar: {+ $set: {+ ...state.sidebar,+ activeTab,+ },+ },+ });return stateFromLocation;}diff --git a/web/js/modules/smart-handoff/actions.js b/web/js/modules/smart-handoff/actions.jsnew file mode 100644index 000000000..88675ad2b--- /dev/null+++ b/web/js/modules/smart-handoff/actions.js@@ -0,0 +1,11 @@+import {+ SELECT_COLLECTION,+} from './constants';++export default function selectCollection(conceptId, layerId) {+ return {+ type: SELECT_COLLECTION,+ conceptId,+ layerId,+ };+}diff --git a/web/js/modules/smart-handoff/constants.js b/web/js/modules/smart-handoff/constants.jsnew file mode 100644index 000000000..52899da9b--- /dev/null+++ b/web/js/modules/smart-handoff/constants.js@@ -0,0 +1,2 @@+// eslint-disable-next-line import/prefer-default-export+export const SELECT_COLLECTION = 'SMART_HANDOFF/SELECT_COLLECTION';diff --git a/web/js/modules/smart-handoff/reducer.js b/web/js/modules/smart-handoff/reducer.jsnew file mode 100644index 000000000..fcb6195c5--- /dev/null+++ b/web/js/modules/smart-handoff/reducer.js@@ -0,0 +1,21 @@+import {+ SELECT_COLLECTION,+} from './constants';++export const smartHadoffState = {+ conceptId: null,+ layerId: null,+};++export function smartHandoffReducer(state = smartHadoffState, action) {+ switch (action.type) {+ case SELECT_COLLECTION:+ return {+ ...state,+ conceptId: action.conceptId,+ layerId: action.layerId,+ };+ default:+ return state;+ }+}diff --git a/web/js/modules/smart-handoff/util.js b/web/js/modules/smart-handoff/util.jsnew file mode 100644index 000000000..b79e40e6f--- /dev/null+++ b/web/js/modules/smart-handoff/util.js@@ -0,0 +1,16 @@++import { get } from 'lodash';++export function parseSmartHandoff(state) {+ const [layerId, conceptId] = state.split(',');+ return {+ layerId,+ conceptId,+ };+}+export function serializeSmartHandoff(currentItemState, state) {+ const activeTab = get(state, 'sidebar.activeTab');+ const { layerId, conceptId } = currentItemState;+ const isActive = activeTab === 'download' && layerId && conceptId;+ return isActive ? [layerId, conceptId].join(',') : undefined;+}