Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

WV-2013: Use UMM-T record for EDSC smart handoffs (#3858)

Jason Kentcc3c55a6aae3
diff --git a/config/default/common/features.json b/config/default/common/features.json
index 3c6604212..c457c19ca 100644
--- a/config/default/common/features.json
+++ b/config/default/common/features.json
@@ -1,6 +1,5 @@
{
"features": {
- "smartHandoffs": true,
"animation": true,
"urlShortening": true,
"customPalettes": true,
@@ -8,6 +7,7 @@
"tour": true,
"feedback": true,
"previewSnapshots": true,
+ "googleTagManager": true,
"vismetadata": {
"url": "https://gibs.earthdata.nasa.gov/layer-metadata/v1.0/",
"daacMap": {
@@ -30,7 +30,15 @@
"MOPITT": "MOPITT SIPS"
}
},
- "googleTagManager": true,
+ "cmr": {
+ "url": "https://cmr.earthdata.nasa.gov/search/"
+ },
+ "smartHandoffs": [
+ {
+ "toolName": "EARTHDATA_SEARCH",
+ "conceptId": "TL2243339890-ESDIS"
+ }
+ ],
"notification": {
"url": "https://status.earthdata.nasa.gov/api/v1/notifications",
"releases": "https://github.com/nasa-gibs/worldview/releases"
diff --git a/e2e/features/smart-handoff/smart-handoff-test.js b/e2e/features/smart-handoff/smart-handoff-test.js
index c3fa58397..145348030 100644
--- a/e2e/features/smart-handoff/smart-handoff-test.js
+++ b/e2e/features/smart-handoff/smart-handoff-test.js
@@ -8,6 +8,7 @@ const {
const TIME_LIMIT = 10000;
+const smartHandoffContainer = '.smart-handoff-side-panel';
const layersTab = '#layers-sidebar-tab';
const dataTabButton = '#download-sidebar-tab';
const downloadButton = '.download-btn';
@@ -29,7 +30,7 @@ module.exports = {
// Click Data Download tab to switch to Data with 'No Data Selected'
c.click(dataTabButton);
-
+ c.waitForElementVisible(smartHandoffContainer, TIME_LIMIT);
c.expect
.element('.smart-handoff-side-panel > h1')
.to.have.text.equal('None of your current layers are available for download.');
@@ -75,9 +76,8 @@ module.exports = {
reuseables.loadAndSkipTour(c, TIME_LIMIT);
c.url(c.globals.url + permalinkParams);
c.expect.element(dataTabButton).to.be.visible;
- c.expect
- .element('.granule-count-info')
- .to.not.have.text.equal('NONE');
+ c.waitForElementVisible('.granule-count-info', TIME_LIMIT);
+ c.expect.element('.granule-count-info').to.not.have.text.equal('NONE');
},
'Changing collection updates URL': (c) => {
@@ -89,6 +89,7 @@ module.exports = {
'Layers outside of their coverage date range are hidden from layers available for download': (c) => {
c.url(c.globals.url + permalinkParams1980);
c.expect.element(dataTabButton).to.be.visible;
+ c.waitForElementVisible(smartHandoffContainer, TIME_LIMIT);
c.expect
.element('.smart-handoff-side-panel > h1')
.to.have.text.equal('None of your current layers are available for download.');
@@ -96,6 +97,7 @@ module.exports = {
'Map extent entirely across dateline disables download button and displays warning for user to zoom out to see available map': (c) => {
c.url(c.globals.url + extentCrossedDateline);
+ c.waitForElementVisible(smartHandoffContainer, TIME_LIMIT);
c.expect.element(downloadButton).to.be.visible;
c.useCss().assert.cssClassPresent(downloadButton, 'wv-disabled');
c.waitForElementVisible('#data-download-unavailable-dateline-alert', TIME_LIMIT, () => {
@@ -106,6 +108,7 @@ module.exports = {
'Download via Earthdata Search': (c) => {
c.url(c.globals.url + permalinkParams);
+ c.waitForElementVisible(smartHandoffContainer, TIME_LIMIT);
c.click(downloadButton);
c.expect
.element('#transferring-to-earthdata-search')
diff --git a/package-lock.json b/package-lock.json
index ffe4ef876..e671deca2 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -69,6 +69,7 @@
"shp-write": "^0.3.2",
"simplebar-react": "^2.1.0",
"supercluster": "7.0.0",
+ "url-template": "^3.0.0",
"what-input": "^5.2.7"
},
"devDependencies": {
@@ -26178,6 +26179,14 @@
"node": ">=0.10.0"
}
},
+ "node_modules/url-template": {
+ "version": "3.0.0",
+ "resolved": "https://registry.npmjs.org/url-template/-/url-template-3.0.0.tgz",
+ "integrity": "sha512-S6P5TcJ8GrGG+yzMZ8ojdtiGtQmQG+UOMelhE3X5uQrEEoq69aDQ05eASPQGj+CjsPVfumWKbH2HrjME46sk0g==",
+ "engines": {
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
+ }
+ },
"node_modules/url/node_modules/punycode": {
"version": "1.3.2",
"license": "MIT"
@@ -45553,6 +45562,11 @@
"prepend-http": "^1.0.1"
}
},
+ "url-template": {
+ "version": "3.0.0",
+ "resolved": "https://registry.npmjs.org/url-template/-/url-template-3.0.0.tgz",
+ "integrity": "sha512-S6P5TcJ8GrGG+yzMZ8ojdtiGtQmQG+UOMelhE3X5uQrEEoq69aDQ05eASPQGj+CjsPVfumWKbH2HrjME46sk0g=="
+ },
"use": {
"version": "3.1.1"
},
diff --git a/package.json b/package.json
index 677d4c890..2fe285ed4 100644
--- a/package.json
+++ b/package.json
@@ -222,6 +222,7 @@
"shp-write": "^0.3.2",
"simplebar-react": "^2.1.0",
"supercluster": "7.0.0",
+ "url-template": "^3.0.0",
"what-input": "^5.2.7"
},
"browserslist": [
diff --git a/web/js/components/sidebar/nav/nav-case.js b/web/js/components/sidebar/nav/nav-case.js
index 4865918d4..0de20aa3a 100644
--- a/web/js/components/sidebar/nav/nav-case.js
+++ b/web/js/components/sidebar/nav/nav-case.js
@@ -19,53 +19,53 @@ function NavCase (props) {
} = props;
const renderDataDownload = () => tabTypes.download && (
- <CustomNavItem
- isMobile={isMobile}
- shouldHideInMobile
- isDisabled={!!isCompareMode || isDataDisabled}
- onTabClick={onTabClick}
- text="Data"
- id="download"
- iconClassName="icon-download"
- disabled={!!isCompareMode}
- label={
- isCompareMode
- ? 'You must exit comparison mode to download data'
- : 'Data Download'
- }
- className={
- activeTab === 'download'
- ? `${tabClasses} third-tab active`
- : isCompareMode
- ? `${tabClasses} third-tab disabled`
- : `${tabClasses} third-tab`
- }
- />
+ <CustomNavItem
+ isMobile={isMobile}
+ shouldHideInMobile
+ isDisabled={!!isCompareMode || isDataDisabled}
+ onTabClick={onTabClick}
+ text="Data"
+ id="download"
+ iconClassName="icon-download"
+ disabled={!!isCompareMode}
+ label={
+ isCompareMode
+ ? 'You must exit comparison mode to download data'
+ : 'Data Download'
+ }
+ className={
+ activeTab === 'download'
+ ? `${tabClasses} third-tab active`
+ : isCompareMode
+ ? `${tabClasses} third-tab disabled`
+ : `${tabClasses} third-tab`
+ }
+ />
);
const renderEvents = () => tabTypes.events && (
- <CustomNavItem
- id="events"
- isMobile={isMobile}
- shouldHideInMobile={false}
- isDisabled={!!isCompareMode}
- onTabClick={onTabClick}
- text="Events"
- iconClassName="icon-events"
- disabled={!!isCompareMode}
- label={
- isCompareMode
- ? 'You must exit comparison mode to use the natural events feature'
- : 'Natural Events'
- }
- className={
- activeTab === 'events'
- ? `${tabClasses} second-tab active`
- : isCompareMode
- ? `${tabClasses} second-tab disabled`
- : `${tabClasses} second-tab`
- }
- />
+ <CustomNavItem
+ id="events"
+ isMobile={isMobile}
+ shouldHideInMobile={false}
+ isDisabled={!!isCompareMode}
+ onTabClick={onTabClick}
+ text="Events"
+ iconClassName="icon-events"
+ disabled={!!isCompareMode}
+ label={
+ isCompareMode
+ ? 'You must exit comparison mode to use the natural events feature'
+ : 'Natural Events'
+ }
+ className={
+ activeTab === 'events'
+ ? `${tabClasses} second-tab active`
+ : isCompareMode
+ ? `${tabClasses} second-tab disabled`
+ : `${tabClasses} second-tab`
+ }
+ />
);
return (
diff --git a/web/js/components/smart-handoffs/granule-count.js b/web/js/components/smart-handoffs/granule-count.js
index 7bdb7b82d..73e33642c 100644
--- a/web/js/components/smart-handoffs/granule-count.js
+++ b/web/js/components/smart-handoffs/granule-count.js
@@ -2,13 +2,11 @@ import React, { useEffect, useState } from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { get as lodashGet } from 'lodash';
import PropTypes from 'prop-types';
-import util from '../../util/util';
-
-const granulesBaseUrl = 'https://cmr.earthdata.nasa.gov/search/granules.json';
export default function GranuleCount (props) {
const {
currentExtent,
+ getGranulesUrl,
displayDate,
showGranuleHelpModal,
selectedLayer,
@@ -50,35 +48,42 @@ export default function GranuleCount (props) {
let newGranuleDownloadSize = 0;
const { dateRanges } = selectedLayer;
const params = {
- collection_concept_id: selectedCollection.value,
+ conceptId: selectedCollection.value,
pageSize: 500,
};
if (dateRanges) {
- const startDate = `${selectedDate}T00:00:00.000Z`;
- const endDate = `${selectedDate}T23:59:59.999Z`;
- params.temporal = `${startDate},${endDate}`;
- }
-
- const granulesRequestUrl = granulesBaseUrl + util.toQueryString(params);
-
- if (southWest && northEast) {
- const bboxRequestUrl = `${granulesRequestUrl}&bounding_box=${southWest},${northEast}`;
- const selectedEntries = await requestGranules(bboxRequestUrl);
- newSelectedGranules = selectedEntries.length;
- newGranuleDownloadSize = getDownloadSize(selectedEntries);
+ params.startDate = `${selectedDate}T00:00:00.000Z`;
+ params.endDate = `${selectedDate}T23:59:59.999Z`;
}
- const totalEntries = await requestGranules(granulesRequestUrl);
- newTotalGranules = totalEntries.length;
- if (newGranuleDownloadSize === 0) {
- newGranuleDownloadSize = getDownloadSize(totalEntries);
+ const granulesRequestUrl = getGranulesUrl(params);
+
+ try {
+ if (southWest && northEast) {
+ const updatedParams = {
+ ...params,
+ bbox: `${southWest},${northEast}`,
+ };
+ const bboxRequestUrl = getGranulesUrl(updatedParams);
+ const selectedEntries = await requestGranules(bboxRequestUrl);
+ newSelectedGranules = selectedEntries.length;
+ newGranuleDownloadSize = getDownloadSize(selectedEntries);
+ }
+ const totalEntries = await requestGranules(granulesRequestUrl);
+ newTotalGranules = totalEntries.length;
+ if (newGranuleDownloadSize === 0) {
+ newGranuleDownloadSize = getDownloadSize(totalEntries);
+ }
+ } catch (e) {
+ console.error(e);
+ } finally {
+ setState({
+ isLoading: false,
+ totalGranules: newTotalGranules,
+ selectedGranules: newSelectedGranules,
+ granuleDownloadSize: newGranuleDownloadSize,
+ });
}
- setState({
- isLoading: false,
- totalGranules: newTotalGranules,
- selectedGranules: newSelectedGranules,
- granuleDownloadSize: newGranuleDownloadSize,
- });
};
/** Trigger granule request when extent, collection, or date changes */
@@ -147,6 +152,7 @@ export default function GranuleCount (props) {
}
GranuleCount.propTypes = {
+ getGranulesUrl: PropTypes.func,
currentExtent: PropTypes.object,
displayDate: PropTypes.string,
selectedLayer: PropTypes.object,
diff --git a/web/js/components/smart-handoffs/smart-handoff-modal.js b/web/js/components/smart-handoffs/smart-handoff-modal.js
index 0b44bf5fe..e0deddb92 100644
--- a/web/js/components/smart-handoffs/smart-handoff-modal.js
+++ b/web/js/components/smart-handoffs/smart-handoff-modal.js
@@ -1,9 +1,11 @@
import React, { useState } from 'react';
+import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import googleTagManager from 'googleTagManager';
import Button from '../util/button';
import Checkbox from '../util/checkbox';
import safeLocalStorage from '../../util/local-storage';
+import { getConceptUrl } from '../../modules/smart-handoff/selectors';
const STD_NRT_MAP = {
STD: 'Standard',
@@ -17,17 +19,14 @@ const STD_NRT_MAP = {
* layer data and granule files that are available for download.
*/
function SmartHandoffModal({
- displayDate, selectedLayer, selectedCollection, continueToEDS,
+ displayDate, selectedLayer, selectedCollection, continueToEDS, cmrSearchDetailURL,
}) {
// Hides Earthdata Search information by default
const [showMoreInfo, toggleInfo] = useState(false);
const { HIDE_EDS_WARNING } = safeLocalStorage.keys;
const [hideModal, setHideModal] = useState(safeLocalStorage.getItem(HIDE_EDS_WARNING) || false);
- const {
- value, title, type, version,
- } = selectedCollection;
+ const { title, type, version } = selectedCollection;
const { dateRanges } = selectedLayer;
- const cmrSearchDetailURL = `https://cmr.earthdata.nasa.gov/search/concepts/${value}.html`;
const onCheck = () => {
if (!hideModal) {
@@ -155,15 +154,20 @@ function SmartHandoffModal({
);
}
+function mapStateToProps(state, ownProps) {
+ const { selectedCollection: { value } } = ownProps;
+ const url = value && getConceptUrl(state)(value);
+ return {
+ cmrSearchDetailURL: url,
+ };
+}
-/**
- * Handle type-checking of defined properties
- */
SmartHandoffModal.propTypes = {
continueToEDS: PropTypes.func,
displayDate: PropTypes.string,
+ cmrSearchDetailURL: PropTypes.string,
selectedCollection: PropTypes.object,
selectedLayer: PropTypes.object,
};
-export default SmartHandoffModal;
+export default connect(mapStateToProps)(SmartHandoffModal);
diff --git a/web/js/components/smart-handoffs/util.js b/web/js/components/smart-handoffs/util.js
deleted file mode 100644
index 44ff9be5c..000000000
--- a/web/js/components/smart-handoffs/util.js
+++ /dev/null
@@ -1,41 +0,0 @@
-import googleTagManager from 'googleTagManager';
-import util from '../../util/util';
-
-/**
- * Method call to direct the user to Earthdata Search with the necessary URL parameters that
- * encapsulate what the user is intending to try and download data / granules from
- * @param {*} proj
- * @param {*} includeDates
- * @param {*} selectedDate
- * @param {*} selectedCollection
- * @param {*} extentCoords
- * @param {*} showBoundingBox
- */
-export default function openEarthDataSearch(proj, includeDates, selectedDate, selectedCollection, extentCoords, showBoundingBox) {
- const { value } = selectedCollection;
- googleTagManager.pushEvent({
- event: 'smart_handoffs_open_eds_data_query',
- selected_collection: value,
- });
- const PROJ_CODES = {
- arctic: '90!0!0!0!0!0',
- geographic: '0.0!-180.0!0!1!0!0,2',
- antarctic: '-90!180!0!2!0!0',
- };
- const { southWest, northEast } = extentCoords;
- const params = {
- q: value,
- p: value,
- m: PROJ_CODES[proj],
- 'sb[0]': showBoundingBox ? `${southWest},${northEast}` : undefined,
- };
-
- if (includeDates) {
- const startDate = `${selectedDate}T00:00:00.000Z`;
- const endDate = `${selectedDate}T23:59:59.999Z`;
- params['[qt]'] = `${startDate},${endDate}`;
- }
-
- const earthDataSearchURL = `https://search.earthdata.nasa.gov/search/granules${util.toQueryString(params)}`;
- window.open(earthDataSearchURL, '_blank');
-}
diff --git a/web/js/containers/sidebar/sidebar.js b/web/js/containers/sidebar/sidebar.js
index 2c3203cb1..69e510c4d 100644
--- a/web/js/containers/sidebar/sidebar.js
+++ b/web/js/containers/sidebar/sidebar.js
@@ -280,25 +280,25 @@ class Sidebar extends React.Component {
<TabPane tabId="layers">
{this.getProductsToRender(activeTab, isCompareMode)}
</TabPane>
- <TabPane tabId="events">
- {naturalEvents && activeTab === 'events' && (
- <Events
- height={subComponentHeight}
- isLoading={isLoadingEvents}
- hasRequestError={hasEventRequestError}
- eventsData={eventsData}
- sources={eventsSources}
- />
- )}
- </TabPane>
- <TabPane tabId="download">
- {smartHandoffs && (
- <SmartHandoff
- isActive={activeTab === 'download'}
- tabTypes={tabTypes}
- />
- )}
- </TabPane>
+ {naturalEvents && activeTab === 'events' && (
+ <TabPane tabId="events">
+ <Events
+ height={subComponentHeight}
+ isLoading={isLoadingEvents}
+ hasRequestError={hasEventRequestError}
+ eventsData={eventsData}
+ sources={eventsSources}
+ />
+ </TabPane>
+ )}
+ {smartHandoffs && activeTab === 'download' && (
+ <TabPane tabId="download">
+ <SmartHandoff
+ isActive={activeTab === 'download'}
+ tabTypes={tabTypes}
+ />
+ </TabPane>
+ )}
<FooterContent
ref={(el) => { this.footerElement = el; }}
diff --git a/web/js/containers/sidebar/smart-handoff.js b/web/js/containers/sidebar/smart-handoff.js
index d45d9dbd4..7d94cdaf9 100644
--- a/web/js/containers/sidebar/smart-handoff.js
+++ b/web/js/containers/sidebar/smart-handoff.js
@@ -3,11 +3,11 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import * as olProj from 'ol/proj';
-import { get as lodashGet, isEqual as lodashEqual } from 'lodash';
+import { isEqual as lodashEqual } from 'lodash';
import googleTagManager from 'googleTagManager';
import moment from 'moment';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
-import { UncontrolledTooltip } from 'reactstrap';
+import { Spinner, UncontrolledTooltip } from 'reactstrap';
import Button from '../../components/util/button';
import Checkbox from '../../components/util/checkbox';
import Crop from '../../components/util/image-crop';
@@ -19,11 +19,20 @@ import GranuleAlertModalBody from '../../components/smart-handoffs/smart-handoff
import GranuleCount from '../../components/smart-handoffs/granule-count';
import { imageUtilGetCoordsFromPixelValues } from '../../modules/image-download/util';
import { onClose, openCustomContent } from '../../modules/modal/actions';
-import { memoizedAvailable as availableSelector, getActiveLayers } from '../../modules/layers/selectors';
+import {
+ getValidLayersForHandoffs,
+ getConceptUrl as getConceptUrlSelector,
+ getGranulesUrl as getGranulesUrlSelector,
+} from '../../modules/smart-handoff/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';
+import openEarthDataSearch from '../../modules/smart-handoff/util';
+import {
+ selectCollection as selectCollectionAction,
+ fetchAvailableTools as fetchAvailableToolsAction,
+ validateLayersConceptIds as validateLayersConceptIdsAction,
+} from '../../modules/smart-handoff/actions';
+
import { formatDisplayDate } from '../../modules/date/util';
const STD_NRT_MAP = {
@@ -52,13 +61,11 @@ class SmartHandoff extends Component {
x2: screenWidth / 2 + 100,
y2: screenHeight / 2 + 100,
},
+ currentExtent: {},
+ coordinates: {},
showBoundingBox: false,
showZoomedIntoDatelineAlert: false,
selectionOutsideExtents: false,
- currentExtent: {},
- coordinates: {},
- validatedLayers: [],
- validatedConceptIds: {},
};
this.baseState = this.state;
@@ -69,8 +76,11 @@ class SmartHandoff extends Component {
}
componentDidMount() {
- const { proj } = this.props;
- this.validateConceptIds();
+ const {
+ proj, availableLayers, validateLayersConceptIds, fetchAvailableTools,
+ } = this.props;
+ fetchAvailableTools();
+ validateLayersConceptIds(availableLayers);
if (proj.id === 'geographic') {
this.checkMapExtentValid();
}
@@ -78,19 +88,20 @@ class SmartHandoff extends Component {
componentDidUpdate(prevProps) {
const {
- isActive,
availableLayers,
proj,
map,
selectedLayer,
selectedCollection,
+ validateLayersConceptIds,
} = this.props;
// Determine if existing selected layer is active still and visibility toggle is 'ON'
const isLayerStillActive = availableLayers.find(({ id }) => selectedLayer && selectedLayer.id);
+ const layerChange = !lodashEqual(availableLayers, prevProps.availableLayers);
- if (!lodashEqual(availableLayers, prevProps.availableLayers)) {
- this.validateConceptIds();
+ if (layerChange) {
+ validateLayersConceptIds(availableLayers);
}
if (selectedCollection && !isLayerStillActive) {
this.setState(this.baseState);
@@ -104,47 +115,13 @@ class SmartHandoff extends Component {
}
if (proj.id === 'geographic') {
- const tabChange = isActive && !prevProps.isActive;
const extentChange = !lodashEqual(map.extent, prevProps.map.extent);
- if (tabChange || extentChange) {
+ if (extentChange) {
this.checkMapExtentValid();
}
}
}
- async validateConceptIds() {
- const { validatedConceptIds } = this.state;
- const { availableLayers } = this.props;
- const baseUrl = 'https://cmr.earthdata.nasa.gov/search/collections.json?concept_id=';
- const conceptIdRequest = async (url) => {
- const granulesResponse = await fetch(url, { timeout: 5000 });
- const result = await granulesResponse.json();
- return lodashGet(result, 'feed.entry', []);
- };
- const allConceptIds = availableLayers.reduce((prev, curr) => {
- (curr.conceptIds || []).forEach(({ value }) => {
- if (value) prev.push(value);
- });
- return prev;
- }, []);
-
- await Promise.all(allConceptIds.map(
- async (id) => {
- if (validatedConceptIds[id] !== undefined) return;
- const response = await conceptIdRequest(baseUrl + id);
- validatedConceptIds[id] = !!response.length;
- },
- ));
-
- const validatedLayers = availableLayers.reduce((prev, curr) => {
- const validIdsArray = (curr.conceptIds || []).filter(({ value }) => validatedConceptIds[value]);
- if (validIdsArray.length) prev.push(curr);
- return prev;
- }, []);
-
- this.setState({ validatedLayers, validatedConceptIds });
- }
-
/**
* Check if entire map extent is over dateline (within a wing)
*
@@ -274,6 +251,7 @@ class SmartHandoff extends Component {
*/
onClickDownload() {
const {
+ availableTools,
displayDate,
proj,
selectedDate,
@@ -292,9 +270,18 @@ class SmartHandoff extends Component {
const { dateRanges } = selectedLayer;
const includeDates = dateRanges && dateRanges.length;
- const continueToEDS = () => openEarthDataSearch(
- proj.id, includeDates, selectedDate, selectedCollection, currentExtent, showBoundingBox,
- );
+ const continueToEDS = () => {
+ const options = {
+ projection: proj.crs,
+ conceptId: selectedCollection.value,
+ currentExtent,
+ includeDates,
+ selectedDate,
+ selectedCollection,
+ showBoundingBox,
+ };
+ return openEarthDataSearch(availableTools, options);
+ };
if (!hideModal) {
showWarningModal(displayDate, selectedLayer, selectedCollection, continueToEDS);
@@ -345,8 +332,9 @@ class SmartHandoff extends Component {
}
renderCollectionTooltip = ({ value, title }, tooltipTarget) => {
- const cmrSearchDetailURL = `https://cmr.earthdata.nasa.gov/search/concepts/${value}.html`;
- return (
+ const { getConceptUrl } = this.props;
+ const url = value && `${getConceptUrl(value)}.html`;
+ return url && (
<UncontrolledTooltip
className="zot-tooltip"
boundariesElement="window"
@@ -358,7 +346,7 @@ class SmartHandoff extends Component {
>
<div>{title}</div>
<div>
- <a href={cmrSearchDetailURL} target="_blank" rel="noreferrer"> View Collection Details </a>
+ <a href={url} target="_blank" rel="noreferrer"> View Collection Details </a>
</div>
</UncontrolledTooltip>
);
@@ -372,8 +360,9 @@ class SmartHandoff extends Component {
selectCollection,
selectedCollection,
selectedLayer,
+ validatedConceptIds,
+ validatedLayers,
} = this.props;
- const { validatedLayers, validatedConceptIds } = this.state;
return (
<div className="smart-handoff-layer-list">
@@ -498,18 +487,47 @@ class SmartHandoff extends Component {
* Render "no layers to download" message
*/
renderNoLayersToDownload = () => {
- const { showNotAvailableModal } = this.props;
+ const { showNotAvailableModal, requestFailed } = this.props;
+
return (
- <div className="smart-handoff-side-panel">
- <h1>
- None of your current layers are available for download.
- </h1>
- <hr />
- <h2>
- <a className="help-link" onClick={showNotAvailableModal}>
- Why are my layers not available?
- </a>
- </h2>
+ <div className="smart-handoff-side-panel error">
+ {requestFailed
+ ? (
+ <>
+ <h1>Data records from the Common Metadata Repository (CMR) could not be reached. Data downloads are not possible at this time.</h1>
+ </>
+ )
+ : (
+ <>
+ <h1>
+ None of your current layers are available for download.
+ </h1>
+ <hr />
+ <h2>
+ <a className="help-link" onClick={showNotAvailableModal}>
+ Why are my layers not available?
+ </a>
+ </h2>
+ </>
+ )}
+ </div>
+ );
+ }
+
+ renderLoadingSpinner = () => {
+ const containerStyle = {
+ padding: '30px 107px',
+ };
+
+ const spinnerStyle = {
+ height: '5rem',
+ width: '5rem',
+ margin: '40px auto',
+ };
+
+ return (
+ <div style={containerStyle}>
+ <Spinner style={spinnerStyle} color="light" size="lg" />
</div>
);
}
@@ -520,27 +538,31 @@ class SmartHandoff extends Component {
render() {
const {
displayDate,
- isActive,
+ getGranulesUrl,
+ isLoading,
showNotAvailableModal,
selectedLayer,
selectedCollection,
selectedDate,
showGranuleHelpModal,
+ validatedLayers,
} = this.props;
const {
- showBoundingBox, selectionOutsideExtents, showZoomedIntoDatelineAlert, currentExtent, validatedLayers,
+ showBoundingBox, selectionOutsideExtents, showZoomedIntoDatelineAlert, currentExtent,
} = this.state;
- // Determine if download 'smart-handoff' tab is activated by user
- if (!isActive) return null;
-
// Determine if the download button is enabled
const validSelection = showBoundingBox ? !selectionOutsideExtents && !showZoomedIntoDatelineAlert : !showZoomedIntoDatelineAlert;
const isValidDownload = selectedLayer && selectedLayer.id && validSelection;
+ if (isLoading) {
+ return this.renderLoadingSpinner();
+ }
+
if (!validatedLayers.length) {
return this.renderNoLayersToDownload();
}
+
return (
<>
{this.renderSelectionWarning()}
@@ -567,6 +589,7 @@ class SmartHandoff extends Component {
selectedLayer={selectedLayer}
selectedCollection={selectedCollection}
showGranuleHelpModal={showGranuleHelpModal}
+ getGranulesUrl={getGranulesUrl}
/>
)}
<Button
@@ -581,73 +604,51 @@ class SmartHandoff extends Component {
}
}
-/**
- * Handle type-checking of defined properties
- */
-SmartHandoff.propTypes = {
- isActive: PropTypes.bool,
- availableLayers: PropTypes.array,
- displayDate: PropTypes.string,
- map: PropTypes.object.isRequired,
- 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,
-};
-
const mapStateToProps = (state) => {
const {
- browser,
- map,
- proj,
- smartHandoffs,
+ browser, map, proj, smartHandoffs,
} = state;
-
- const { conceptId, layerId } = smartHandoffs;
-
const {
- screenWidth,
- screenHeight,
- } = browser;
+ conceptId, layerId, availableTools, validatedConceptIds, validatedLayers, isLoadingTools, isValidatingCollections, requestFailed,
+ } = smartHandoffs;
+ const { screenWidth, screenHeight } = browser;
const selectedDate = getSelectedDate(state);
const selectedDateFormatted = moment.utc(selectedDate).format('YYYY-MM-DD'); // 2020-01-01
- const displayDate = formatDisplayDate(selectedDate); // 2020 JAN 01
- const filterForSmartHandoff = (layer) => {
- const {
- id, projections, disableSmartHandoff, conceptIds,
- } = layer;
- const isAvailable = availableSelector(state)(id);
- const filteredConceptIds = (conceptIds || []).filter(({ type, value, version }) => type && value && version);
- return isAvailable && projections[proj.id] && !disableSmartHandoff && !!filteredConceptIds.length;
- };
- const availableLayers = getActiveLayers(state).filter(filterForSmartHandoff);
-
+ const availableLayers = getValidLayersForHandoffs(state);
const selectedLayer = availableLayers.find(({ id }) => id === layerId);
const selectedCollection = selectedLayer && (selectedLayer.conceptIds || []).find(({ value }) => value === conceptId);
+ const isLoading = isLoadingTools || isValidatingCollections;
return {
availableLayers,
- displayDate,
+ displayDate: formatDisplayDate(selectedDate), // 2020 JAN 01
+ getConceptUrl: getConceptUrlSelector(state),
+ getGranulesUrl: getGranulesUrlSelector(state),
+ isLoading,
map,
proj: proj.selected,
+ requestFailed,
screenHeight,
screenWidth,
selectedDate: selectedDateFormatted,
selectedLayer,
selectedCollection,
+ availableTools,
+ validatedConceptIds,
+ validatedLayers,
};
};
const mapDispatchToProps = (dispatch) => ({
selectCollection: (conceptId, layerId) => {
- dispatch(selectCollection(conceptId, layerId));
+ dispatch(selectCollectionAction(conceptId, layerId));
+ },
+ fetchAvailableTools: () => {
+ dispatch(fetchAvailableToolsAction());
+ },
+ validateLayersConceptIds: (layers) => {
+ dispatch(validateLayersConceptIdsAction(layers));
},
showWarningModal: (displayDate, selectedLayer, selectedCollection, continueToEDS) => {
googleTagManager.pushEvent({
@@ -697,3 +698,28 @@ export default connect(
mapStateToProps,
mapDispatchToProps,
)(SmartHandoff);
+
+SmartHandoff.propTypes = {
+ availableLayers: PropTypes.array,
+ availableTools: PropTypes.array,
+ displayDate: PropTypes.string,
+ isLoading: PropTypes.bool,
+ getConceptUrl: PropTypes.func,
+ getGranulesUrl: PropTypes.func,
+ map: PropTypes.object.isRequired,
+ proj: PropTypes.object,
+ fetchAvailableTools: PropTypes.func,
+ requestFailed: PropTypes.bool,
+ 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,
+ validatedLayers: PropTypes.array,
+ validatedConceptIds: PropTypes.object,
+ validateLayersConceptIds: PropTypes.func,
+};
diff --git a/web/js/map/granule/granule-layer-builder.js b/web/js/map/granule/granule-layer-builder.js
index e54fdaf4a..f12da6779 100644
--- a/web/js/map/granule/granule-layer-builder.js
+++ b/web/js/map/granule/granule-layer-builder.js
@@ -12,29 +12,18 @@ import { getGranuleLayer } from '../../modules/layers/selectors';
import {
startLoading,
stopLoading,
+ LOADING_GRANULES,
} from '../../modules/loading/actions';
import { openBasicContent } from '../../modules/modal/actions';
-import {
- getCacheOptions,
-} from '../../modules/layers/util';
+import { getCacheOptions } from '../../modules/layers/util';
+import { getGranulesUrl as getGranulesUrlSelector } from '../../modules/smart-handoff/selectors';
import {
getCMRQueryDates,
getCMRQueryDateUpdateOptions,
isWithinDateRange,
getGranuleDateData,
} from './util';
-import util from '../../util/util';
-const CMR_BASE_GRANULE_URL = 'https://cmr.earthdata.nasa.gov/search/granules.json';
-const CMR_AJAX_OPTIONS = {
- url: CMR_BASE_GRANULE_URL,
- headers: {
- 'Client-Id': 'Worldview',
- },
- traditional: true,
- dataType: 'json',
- timeout: 30 * 1000,
-};
const dayNightFilter = 'DAY'; // 'DAY', 'NIGHT', 'BOTH'
export default function granuleLayerBuilder(cache, store, createLayerWMTS) {
@@ -44,6 +33,16 @@ export default function granuleLayerBuilder(cache, store, createLayerWMTS) {
};
const CMRDataStore = {};
+ const getGranuleUrl = getGranulesUrlSelector(store.getState());
+ const baseGranuleUrl = getGranuleUrl();
+ const CMR_AJAX_OPTIONS = {
+ url: baseGranuleUrl,
+ headers: { 'Client-Id': 'Worldview' },
+ traditional: true,
+ dataType: 'json',
+ timeout: 30 * 1000,
+ };
+
const throttleDispathCMRErrorDialog = lodashThrottle(
dispathCMRErrorDialog.bind(this),
CMR_AJAX_OPTIONS.timeout,
@@ -59,11 +58,11 @@ export default function granuleLayerBuilder(cache, store, createLayerWMTS) {
}
const showLoading = () => {
- store.dispatch(startLoading('granule-metadata'));
+ store.dispatch(startLoading(LOADING_GRANULES));
};
const hideLoading = () => {
- store.dispatch(stopLoading('granule-metadata'));
+ store.dispatch(stopLoading(LOADING_GRANULES));
};
/**
@@ -92,16 +91,16 @@ export default function granuleLayerBuilder(cache, store, createLayerWMTS) {
endDate, startDate, id, title, visible,
} = def;
const { startQueryDate, endQueryDate } = getCMRQueryDates(date);
+ const getGranulesUrl = getGranulesUrlSelector(store.getState());
const shortName = 'VJ102MOD'; // USE GRANULE LAYER ID
const params = {
shortName,
- temporal: `${startQueryDate.toISOString()},${endQueryDate.toISOString()}`,
+ startDate: startQueryDate.toISOString(),
+ endDate: endQueryDate.toISOString(),
pageSize: 2000,
};
- const query = `${CMR_BASE_GRANULE_URL + util.toQueryString(params)}`;
-
// update range/extend range checks and new dates (if applicable)
const CMRDateStoreForLayer = CMRDateRanges[activeString][id];
const {
@@ -128,7 +127,7 @@ export default function granuleLayerBuilder(cache, store, createLayerWMTS) {
showLoading();
let data;
try {
- const response = await fetch(query, CMR_AJAX_OPTIONS);
+ const response = await fetch(getGranulesUrl(params), CMR_AJAX_OPTIONS);
data = await response.json();
data = data.feed.entry;
diff --git a/web/js/map/layerbuilder.js b/web/js/map/layerbuilder.js
index 001616810..eaa65f052 100644
--- a/web/js/map/layerbuilder.js
+++ b/web/js/map/layerbuilder.js
@@ -38,7 +38,7 @@ import {
import {
nearestInterval,
} from '../modules/layers/util';
-import { startLoading, stopLoading } from '../modules/loading/actions';
+import { startLoading, stopLoading, LOADING_TILES } from '../modules/loading/actions';
let loadingCounter = 0;
@@ -46,14 +46,14 @@ export default function mapLayerBuilder(config, cache, store) {
const { getGranuleLayer } = granuleLayerBuilder(cache, store, createLayerWMTS);
const tileLoadStart = () => {
if (loadingCounter === 0) {
- store.dispatch(startLoading('layer-tiles'));
+ store.dispatch(startLoading(LOADING_TILES));
}
loadingCounter += 1;
};
const tileLoadEnd = () => {
loadingCounter -= 1;
if (loadingCounter === 0) {
- store.dispatch(stopLoading('layer-tiles'));
+ store.dispatch(stopLoading(LOADING_TILES));
}
};
diff --git a/web/js/map/ui.js b/web/js/map/ui.js
index eaa9bb108..ee7293bab 100644
--- a/web/js/map/ui.js
+++ b/web/js/map/ui.js
@@ -71,7 +71,7 @@ import { updateVectorSelection } from '../modules/vector-styles/util';
import { hasVectorLayers } from '../modules/layers/util';
import { animateCoordinates, getCoordinatesMarker, areCoordinatesWithinExtent } from '../modules/location-search/util';
import { reverseGeocode } from '../modules/location-search/util-api';
-import { startLoading, stopLoading } from '../modules/loading/actions';
+import { startLoading, stopLoading, PRELOAD_TILES } from '../modules/loading/actions';
const { events } = util;
@@ -102,7 +102,7 @@ export default function mapui(models, config, store) {
};
layerQueue.on('idle', () => {
- store.dispatch(stopLoading('tile-preload'));
+ store.dispatch(stopLoading(PRELOAD_TILES));
});
/**
@@ -960,7 +960,7 @@ export default function mapui(models, config, store) {
const prevDate = getNextDateTime(state, -1, useDate);
const subsequentDate = lastArrowDirection === 'right' ? nextDate : prevDate;
- store.dispatch(startLoading('tile-preload'));
+ store.dispatch(startLoading(PRELOAD_TILES));
// If we've preloaded N dates out, we need to use the latest
// preloaded date the next time we call this function or the buffer
diff --git a/web/js/modules/combine-reducers.js b/web/js/modules/combine-reducers.js
index a4b7847fc..3bfdd15c5 100644
--- a/web/js/modules/combine-reducers.js
+++ b/web/js/modules/combine-reducers.js
@@ -47,7 +47,7 @@ import { LOCATION_POP_ACTION } from '../redux-location-state-customs';
import embedReducers from './embed/reducers';
import uiReducers from './ui/reducers';
import { alertReducer } from './alerts/reducer';
-import { smartHandoffReducer } from './smart-handoff/reducer';
+import { smartHandoffReducer, getInitialState as getSmartHandoffInitialState } from './smart-handoff/reducer';
import { getInitialState as getInitialSettingsState, settingsReducer } from './settings/reducer';
import { loadingReducer } from './loading/reducers';
@@ -88,6 +88,7 @@ export function getInitialState(models, config, parameters) {
settings: getInitialSettingsState(),
requestedEvents: eventRequestResponse(),
requestedEventSources: eventRequestResponse(),
+ smartHandoffs: getSmartHandoffInitialState(config),
palettes: getInitialPaletteState(config),
productPicker: getProductPickerInitialState(config),
vectorStyles: getInitialVectorStyleState(config),
diff --git a/web/js/modules/loading/actions.js b/web/js/modules/loading/actions.js
index c771a75f9..e7ff20df3 100644
--- a/web/js/modules/loading/actions.js
+++ b/web/js/modules/loading/actions.js
@@ -1,5 +1,9 @@
import { LOADING_START, LOADING_STOP } from './constants';
+export const LOADING_GRANULES = 'LOADING/GRANULES';
+export const PRELOAD_TILES = 'LOADING/TILE_PRELOAD';
+export const LOADING_TILES = 'LOADING/LAYER_TILES';
+
export function startLoading(key, msg) {
return (dispatch, getState) => {
const { animation } = getState();
diff --git a/web/js/modules/smart-handoff/actions.js b/web/js/modules/smart-handoff/actions.js
index 88675ad2b..3c8b15e62 100644
--- a/web/js/modules/smart-handoff/actions.js
+++ b/web/js/modules/smart-handoff/actions.js
@@ -1,11 +1,94 @@
+import { get as lodashGet } from 'lodash';
import {
SELECT_COLLECTION,
+ SET_AVAILABLE_TOOLS,
+ SET_VALID_LAYERS_CONCEPTIDS,
} from './constants';
+import { getCollectionsUrl, getConceptUrl } from './selectors';
-export default function selectCollection(conceptId, layerId) {
+// eslint-disable-next-line import/prefer-default-export
+export function selectCollection(conceptId, layerId) {
return {
type: SELECT_COLLECTION,
conceptId,
layerId,
};
}
+
+export function fetchAvailableTools() {
+ return async (dispatch, getState) => {
+ let availableTools = [];
+ let requestFailed = false;
+ try {
+ const state = getState();
+ const { smartHandoffs } = state.config.features;
+ availableTools = await Promise.all(smartHandoffs.map(async (tool) => {
+ const url = getConceptUrl(state)(tool.conceptId);
+ const response = await fetch(url, { timeout: 5000 });
+ const result = await response.json();
+ return {
+ name: tool.toolName,
+ action: result.PotentialAction,
+ };
+ }));
+ } catch (e) {
+ console.error(e);
+ requestFailed = true;
+ } finally {
+ dispatch({
+ type: SET_AVAILABLE_TOOLS,
+ availableTools,
+ requestFailed,
+ });
+ }
+ };
+}
+
+export function validateLayersConceptIds (layers) {
+ return async (dispatch, getState) => {
+ const state = getState();
+ const { smartHandoffs: { validatedConceptIds } } = state;
+ let validatedLayers = [];
+ let requestFailed = false;
+
+ try {
+ const conceptIdRequest = async (url) => {
+ const granulesResponse = await fetch(url, { timeout: 5000 });
+ const result = await granulesResponse.json();
+ return lodashGet(result, 'feed.entry', []);
+ };
+ const allConceptIds = layers.reduce((prev, curr) => {
+ (curr.conceptIds || []).forEach(({ value }) => {
+ if (value) prev.push(value);
+ });
+ return prev;
+ }, []);
+
+ await Promise.all(allConceptIds.map(
+ async (id) => {
+ if (validatedConceptIds[id] !== undefined) return;
+ const requestUrl = getCollectionsUrl(state)(id);
+ const response = await conceptIdRequest(requestUrl);
+ validatedConceptIds[id] = !!response.length;
+ },
+ ));
+
+ validatedLayers = layers.reduce((prev, curr) => {
+ const validIdsArray = (curr.conceptIds || []).filter(({ value }) => validatedConceptIds[value]);
+ if (validIdsArray.length) prev.push(curr);
+ return prev;
+ }, []);
+ } catch (e) {
+ console.error(e);
+ requestFailed = true;
+ } finally {
+ dispatch({
+ type: SET_VALID_LAYERS_CONCEPTIDS,
+ validatedLayers,
+ validatedConceptIds,
+ requestFailed,
+ });
+ }
+ };
+}
+
diff --git a/web/js/modules/smart-handoff/constants.js b/web/js/modules/smart-handoff/constants.js
index 52899da9b..702e16087 100644
--- a/web/js/modules/smart-handoff/constants.js
+++ b/web/js/modules/smart-handoff/constants.js
@@ -1,2 +1,6 @@
// eslint-disable-next-line import/prefer-default-export
export const SELECT_COLLECTION = 'SMART_HANDOFF/SELECT_COLLECTION';
+export const SET_AVAILABLE_TOOLS = 'SMART_HANDOFF/SET_AVAILABLE_TOOLS';
+export const SET_VALID_LAYERS_CONCEPTIDS = 'SMART_HANDOFF/SET_VALID_LAYERS_CONCEPTIDS';
+
+export const TOOLS_EARTHDATA_SEARCH = 'EARTHDATA_SEARCH';
diff --git a/web/js/modules/smart-handoff/reducer.js b/web/js/modules/smart-handoff/reducer.js
index fcb6195c5..c1efeba64 100644
--- a/web/js/modules/smart-handoff/reducer.js
+++ b/web/js/modules/smart-handoff/reducer.js
@@ -1,13 +1,28 @@
import {
SELECT_COLLECTION,
+ SET_AVAILABLE_TOOLS,
+ SET_VALID_LAYERS_CONCEPTIDS,
} from './constants';
-export const smartHadoffState = {
+export const initialState = {
conceptId: null,
layerId: null,
+ availableTools: [],
+ validatedLayers: [],
+ validatedConceptIds: {},
+ isLoadingTools: true,
+ isValidatingCollections: true,
+ requestFailed: false,
};
-export function smartHandoffReducer(state = smartHadoffState, action) {
+export function getInitialState(config) {
+ return {
+ ...initialState,
+ configuredTools: config.features.smartHandoffs,
+ };
+}
+
+export function smartHandoffReducer(state = initialState, action) {
switch (action.type) {
case SELECT_COLLECTION:
return {
@@ -15,6 +30,21 @@ export function smartHandoffReducer(state = smartHadoffState, action) {
conceptId: action.conceptId,
layerId: action.layerId,
};
+ case SET_AVAILABLE_TOOLS:
+ return {
+ ...state,
+ availableTools: action.availableTools,
+ isLoadingTools: false,
+ requestFailed: action.requestFailed,
+ };
+ case SET_VALID_LAYERS_CONCEPTIDS:
+ return {
+ ...state,
+ validatedLayers: action.validatedLayers,
+ validatedConceptIds: action.validatedConceptIds,
+ isValidatingCollections: false,
+ requestFailed: action.requestFailed,
+ };
default:
return state;
}
diff --git a/web/js/modules/smart-handoff/selectors.js b/web/js/modules/smart-handoff/selectors.js
new file mode 100644
index 000000000..92592f1d2
--- /dev/null
+++ b/web/js/modules/smart-handoff/selectors.js
@@ -0,0 +1,59 @@
+
+import { getActiveLayers, memoizedAvailable } from '../layers/selectors';
+import util from '../../util/util';
+
+const getBaseCmrUrl = ({ config: { features: { cmr } } }) => cmr.url;
+
+// e.g. https://cmr.earthdata.nasa.gov/search/granules.json?collection_concept_id=C2185522599-LANCEMODIS&pageSize=500&temporal=2022-03-28T00%3A00%3A00.000Z%2C2022-03-28T23%3A59%3A59.999Z
+export const getGranulesUrl = (state) => {
+ const baseUrl = getBaseCmrUrl(state);
+ return (params = {}) => {
+ const getTemporal = () => {
+ if (params.startDate && params.endDate) {
+ return `${params.startDate},${params.endDate}`;
+ }
+ };
+ const newParams = {
+ bounding_box: params.bbox,
+ collection_concept_id: params.conceptId,
+ shortName: params.shortName,
+ temporal: getTemporal(),
+ pageSize: params.pageSize,
+ };
+ const queryString = util.toQueryString(newParams);
+ return `${baseUrl}granules.json${queryString}`;
+ };
+};
+
+// e.g. https://cmr.earthdata.nasa.gov/search/collections.json?concept_id=C2208779826-LANCEMODIS
+export const getCollectionsUrl = (state) => {
+ const baseUrl = getBaseCmrUrl(state);
+ return (id) => {
+ const params = { concept_id: id };
+ return `${baseUrl}collections.json${util.toQueryString(params)}`;
+ };
+};
+
+// e.g. https://cmr.earthdata.nasa.gov/search/concepts/C2208779826-LANCEMODIS.html
+export const getConceptUrl = (state) => {
+ const baseUrl = getBaseCmrUrl(state);
+ return (id) => `${baseUrl}concepts/${id}`;
+};
+
+/**
+ * Get array of layers from state that are available and have the necessary metadata for a handoff
+ * @param {*} state
+ * @returns
+ */
+export const getValidLayersForHandoffs = (state) => {
+ const { proj } = state;
+ const filterForSmartHandoff = (layer) => {
+ const {
+ id, projections, disableSmartHandoff, conceptIds,
+ } = layer;
+ const isAvailable = memoizedAvailable(state)(id);
+ const filteredConceptIds = (conceptIds || []).filter(({ type, value, version }) => type && value && version);
+ return isAvailable && projections[proj.id] && !disableSmartHandoff && !!filteredConceptIds.length;
+ };
+ return getActiveLayers(state).filter(filterForSmartHandoff);
+};
diff --git a/web/js/modules/smart-handoff/util.js b/web/js/modules/smart-handoff/util.js
index b79e40e6f..66e1a32eb 100644
--- a/web/js/modules/smart-handoff/util.js
+++ b/web/js/modules/smart-handoff/util.js
@@ -1,5 +1,52 @@
import { get } from 'lodash';
+import googleTagManager from 'googleTagManager';
+import { parseTemplate } from 'url-template';
+import { TOOLS_EARTHDATA_SEARCH } from './constants';
+
+function getHandoffParams (queryInput, options) {
+ const {
+ projection, conceptId, includeDates, selectedDate, currentExtent, showBoundingBox,
+ } = options;
+
+ const getParam = ({ ValueType, ValueName }) => {
+ if (ValueType === 'temporalRange') {
+ if (includeDates) {
+ const startDate = `${selectedDate}T00:00:00.000Z`;
+ const endDate = `${selectedDate}T23:59:59.999Z`;
+ return {
+ [ValueName]: `${startDate},${endDate}`,
+ };
+ }
+ }
+ if (ValueType === 'https://schema.org/box') {
+ const { southWest, northEast } = currentExtent;
+ return {
+ [ValueName]: showBoundingBox ? `${southWest},${northEast}` : undefined,
+ };
+ }
+ if (ValueType === 'https://spatialreference.org/ref/epsg/') {
+ return {
+ [ValueName]: projection,
+ };
+ }
+ if (ValueType === 'conceptId') {
+ return {
+ [ValueName]: conceptId,
+ };
+ }
+ if (ValueType === 'edscTextQuery') {
+ return {
+ [ValueName]: conceptId,
+ };
+ }
+ };
+
+ return queryInput.reduce((params, input) => ({
+ ...params,
+ ...getParam(input),
+ }), {});
+}
export function parseSmartHandoff(state) {
const [layerId, conceptId] = state.split(',');
@@ -14,3 +61,29 @@ export function serializeSmartHandoff(currentItemState, state) {
const isActive = activeTab === 'download' && layerId && conceptId;
return isActive ? [layerId, conceptId].join(',') : undefined;
}
+
+/**
+ * Method call to direct the user to Earthdata Search with the necessary URL parameters that
+ * encapsulate what the user is intending to try and download data / granules from
+ * @param {*} proj
+ * @param {*} includeDates
+ * @param {*} selectedDate
+ * @param {*} selectedCollection
+ * @param {*} extentCoords
+ * @param {*} showBoundingBox
+ */
+export default function openEarthDataSearch(tools, options) {
+ const { action } = tools.find(({ name }) => name === TOOLS_EARTHDATA_SEARCH) || {};
+ if (!action) return;
+
+ const { Target, QueryInput } = action;
+ const urlTemplate = parseTemplate(Target.UrlTemplate);
+ const params = getHandoffParams(QueryInput, options);
+
+ window.open(urlTemplate.expand(params), '_blank');
+
+ googleTagManager.pushEvent({
+ event: 'smart_handoffs_open_eds_data_query',
+ selected_collection: options.conceptId,
+ });
+}
diff --git a/web/scss/features/smart-handoff.scss b/web/scss/features/smart-handoff.scss
index 925cfdba9..a358766b2 100644
--- a/web/scss/features/smart-handoff.scss
+++ b/web/scss/features/smart-handoff.scss
@@ -2,28 +2,33 @@
.smart-handoff-side-panel {
margin: 5px;
color: #bbb;
-}
+ min-height: 300px;
-.smart-handoff-side-panel h1 {
- margin: 15px 5px;
- font-size: 13px;
- line-height: 18px;
- text-align: center;
-}
+ &.error {
+ margin: 40px 5px 20px;
+ }
-.smart-handoff-side-panel hr {
- margin-top: 10px;
- border-bottom: 1px solid #555;
-}
+ h1 {
+ margin: 15px 5px;
+ font-size: 13px;
+ line-height: 18px;
+ text-align: center;
+ }
-.smart-handoff-side-panel h2 {
- margin-top: 18px;
- color: #eee;
- text-align: center;
-}
+ hr {
+ margin-top: 10px;
+ border-bottom: 1px solid #555;
+ }
-.smart-handoff-side-panel p {
- margin-top: 10px;
+ h2 {
+ margin-top: 18px;
+ color: #eee;
+ text-align: center;
+ }
+
+ p {
+ margin-top: 10px;
+ }
}
.smart-handoff-product-list {