Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Hide granules if not avail for proj #1847

Benjamin Kingc7cb8430c647
diff --git a/web/js/containers/sidebar/data.js b/web/js/containers/sidebar/data.js
index 9f35c9f99..4b2b1ad29 100644
--- a/web/js/containers/sidebar/data.js
+++ b/web/js/containers/sidebar/data.js
@@ -6,10 +6,12 @@ import { connect } from 'react-redux';
import {
getSelectionCounts,
getDataProductsFromActiveLayers,
- findAvailableProduct
+ findAvailableProduct,
+ doesSelectedExist
} from '../../modules/data/selectors';
import { selectProduct } from '../../modules/data/actions';
import { openCustomContent } from '../../modules/modal/actions';
+import { getLayers } from '../../modules/layers/selectors';
const CustomBodyModalContent = () => {
return (
@@ -64,7 +66,10 @@ class Data extends React.Component {
if (!tabTypes.download) return null;
const dataArray = Object.entries(products);
if (dataArray.length > 0 && !selectedProduct && isActive) {
- findProductToSelect(activeLayers);
+ findProductToSelect(activeLayers, selectedProduct);
+ }
+ if (selectedProduct && !doesSelectedExist(activeLayers, selectedProduct)) {
+ findProductToSelect(activeLayers, selectedProduct);
}
return (
<Scrollbars style={{ maxHeight: height + 'px' }}>
@@ -106,7 +111,7 @@ Data.propTypes = {
tabTypes: PropTypes.object
};
-const mapDispatchToProps = dispatch => ({
+const mapDispatchToProps = (dispatch, ownProps) => ({
showUnavailableReason: () => {
dispatch(
openCustomContent('data_download_no_data_notify', {
@@ -116,7 +121,7 @@ const mapDispatchToProps = dispatch => ({
})
);
},
- findProductToSelect: products => {
+ findProductToSelect: (products, selectedProduct) => {
const newSelection = findAvailableProduct(products);
if (newSelection) {
@@ -132,7 +137,7 @@ function mapStateToProps(state, ownProps) {
const { layers, proj, data, config, compare, sidebar } = state;
const { selectedProduct, selectedGranules } = data;
const activeString = compare.activeString;
- const activeLayers = layers[activeString];
+ const activeLayers = getLayers(layers[activeString], { proj: proj.id });
const counts = getSelectionCounts(activeLayers, selectedGranules);
const products = getDataProductsFromActiveLayers(
activeLayers,
diff --git a/web/js/map/data/ui.js b/web/js/map/data/ui.js
index f9b14e69b..8a7d0e90a 100644
--- a/web/js/map/data/ui.js
+++ b/web/js/map/data/ui.js
@@ -15,7 +15,7 @@ import { toggleGranule } from '../../modules/data/actions';
import { SELECT_DATE } from '../../modules/date/constants';
import { LOCATION_POP_ACTION } from '../../redux-location-state-customs';
import { getLayers } from '../../modules/layers/selectors';
-import { getDataProductsFromActiveLayers } from '../../modules/data/selectors';
+import { getDataProductsFromActiveLayers, doesSelectedExist } from '../../modules/data/selectors';
import * as LAYER_CONSTANTS from '../../modules/layers/constants';
import { CHANGE_PROJECTION } from '../../modules/projection/constants';
@@ -88,7 +88,7 @@ export function dataUi(store, ui, config) {
// everything changes to models.
var products = getDataProductsFromActiveLayers(activeLayers, config, proj.id);
lodashEach(data.selectedGranules, function(selected) {
- if (!products[selected.product] && !lodashFind(activeLayers, { product: selected.product })) {
+ if (!products[selected.product] && !lodashFind(layers[activeString], { product: selected.product })) {
store.dispatch(toggleGranule(selected));
}
});
@@ -96,10 +96,14 @@ export function dataUi(store, ui, config) {
var query = function() {
const state = store.getState();
const dataState = state.data;
+ const { compare, layers, proj } = state;
+ const activeLayers = getLayers(layers[compare.activeString], { proj: proj.id });
+
if (state.sidebar.activeTab !== 'download') {
return;
}
- if (!dataState.selectedProduct) {
+
+ if (!dataState.selectedProduct || (dataState.selectedProduct && !doesSelectedExist(activeLayers, dataState.selectedProduct))) {
self.events.trigger(self.EVENT_QUERY_RESULTS, {
meta: {},
granules: []
diff --git a/web/js/modules/data/selectors.js b/web/js/modules/data/selectors.js
index 4091df20e..6f2d8f00f 100644
--- a/web/js/modules/data/selectors.js
+++ b/web/js/modules/data/selectors.js
@@ -84,6 +84,13 @@ export function groupByProducts(config, dataProducts) {
}
return results;
}
+export function doesSelectedExist(activeLayers, selectedId) {
+ let exists = false;
+ lodashEach(activeLayers, function(layer) {
+ if (layer.product === selectedId) exists = true;
+ });
+ return exists;
+}
export function getDataProductsFromActiveLayers(layers, config, projId) {
let dataProducts = [];
lodashEach(layers, function(layer) {