Interactive interface for browsing global, full-resolution satellite imagery
set and restore faceted search state
Jason Kent56fe79df07a2
diff --git a/web/js/components/layer/product-picker/browse/measurement-metadata-detail.js b/web/js/components/layer/product-picker/browse/measurement-metadata-detail.jsindex ce3995a13..f282b7a75 100644--- a/web/js/components/layer/product-picker/browse/measurement-metadata-detail.js+++ b/web/js/components/layer/product-picker/browse/measurement-metadata-detail.js@@ -125,7 +125,7 @@ MeasurementMetadataDetail.propTypes = {const mapStateToProps = (state) => {const { category } = state.productPicker;return {- categoryTitle: category.title,+ categoryTitle: category && category.title,source: getMeasurementSource(state),};};diff --git a/web/js/components/layer/product-picker/header.js b/web/js/components/layer/product-picker/header.jsindex 104cf778d..85e6c4d29 100644--- a/web/js/components/layer/product-picker/header.js+++ b/web/js/components/layer/product-picker/header.js@@ -28,6 +28,7 @@ class ProductPickerHeader extends React.Component {super(props);this.revertToInitialScreen = this.revertToInitialScreen.bind(this);this.handleChange = this.handleChange.bind(this);+ this.onSearchInputFocus = this.onSearchInputFocus.bind(this);}/**@@ -81,6 +82,17 @@ class ProductPickerHeader extends React.Component {);}+ onSearchInputFocus (e) {+ const { mode, toggleSearchMode } = this.props;++ // TODO also need to actually focus the input so user can start typing here+ // e.target.focus();++ if (mode !== 'search') {+ toggleSearchMode();+ }+ }+render() {const {isMobile,@@ -119,7 +131,10 @@ class ProductPickerHeader extends React.Component {{(mode !== 'search' && !selectedLayer)&& (- <Button className="filter-button" onClick={toggleSearchMode}>+ <Button+ className="filter-button"+ onClick={toggleSearchMode}+ ><FontAwesomeIcon icon={faFilter} /></Button>)}@@ -130,7 +145,7 @@ class ProductPickerHeader extends React.Component {value={searchTerm}placeholder="Search"type="search"- onFocus={toggleSearchMode}+ onFocus={(e) => this.onSearchInputFocus(e)}/></InputGroup>{(mode === 'search' && !isMobile) && (diff --git a/web/js/components/layer/product-picker/product-picker.js b/web/js/components/layer/product-picker/product-picker.jsindex c13e1a705..580688f1c 100644--- a/web/js/components/layer/product-picker/product-picker.js+++ b/web/js/components/layer/product-picker/product-picker.js@@ -1,21 +1,25 @@import React from 'react';import { connect } from 'react-redux';import PropTypes from 'prop-types';-import lodashDebounce from 'lodash/debounce';+import {+ WithSearch,+ SearchProvider,+} from '@elastic/react-search-ui';import {ModalBody,ModalHeader,} from 'reactstrap';-import {- SearchProvider,- // WithSearch,-} from '@elastic/react-search-ui';+import ProductPickerHeader from './header';-import FilterUnavailable from './filterUnavailable';-import { onToggle as onToggleAction } from '../../../modules/modal/actions';+import {+ onToggle as onToggleAction,+} from '../../../modules/modal/actions';import BrowseLayers from './browse/browse-layers';import SearchLayers from './search/search-layers';-import { getSearchConfig } from '../../../modules/product-picker/selectors';+import {+ initSearchState as initStateAction,+ saveSearchState as saveSearchStateAction,+} from '../../../modules/product-picker/actions';/** A scrollable list of layers@@ -25,15 +29,14 @@ import { getSearchConfig } from '../../../modules/product-picker/selectors';class ProductPicker extends React.Component {constructor(props) {super(props);-this.state = {modalElement: undefined,};-- // this.toggleFilterByAvailable = this.toggleFilterByAvailable.bind(this);}componentDidMount() {+ const { initState } = this.props;+ initState();const modalElement = document.getElementById('layer_picker_component');modalElement.classList.add('category-width');this.setState({ modalElement });@@ -138,31 +141,37 @@ class ProductPicker extends React.Component {render() {const {+ closeModal,mode,searchConfig,width,- onToggle,} = this.props;return !searchConfig ? null : (<SearchProvider config={searchConfig}>- <ModalHeader toggle={onToggle}>- <ProductPickerHeader- width={width}- toggleFilterByAvailable={this.toggleFilterByAvailable}- />- </ModalHeader>- <ModalBody>- <div id="layer-modal-content" className="layer-modal-content">- {mode !== 'search'- ? (- <BrowseLayers componentHeights={this.getComponentHeights()} width={width} />- )- : (- <SearchLayers componentHeights={this.getComponentHeights()} width={width} />- )}- </div>- </ModalBody>+ <WithSearch mapContextToProps={({ filters, searchTerm }) => ({ filters, searchTerm })}>+ {({ filters, searchTerm }) => (+ <>+ <ModalHeader toggle={() => closeModal(filters, searchTerm)}>+ <ProductPickerHeader+ width={width}+ toggleFilterByAvailable={this.toggleFilterByAvailable}+ />+ </ModalHeader>+ <ModalBody>+ <div id="layer-modal-content" className="layer-modal-content">+ {mode !== 'search'+ ? (+ <BrowseLayers componentHeights={this.getComponentHeights()} width={width} />+ )+ : (+ <SearchLayers componentHeights={this.getComponentHeights()} width={width} />+ )}+ </div>+ </ModalBody>+ </>+ )}+ </WithSearch></SearchProvider>);}@@ -170,9 +179,10 @@ class ProductPicker extends React.Component {ProductPicker.propTypes = {category: PropTypes.object,+ closeModal: PropTypes.func,+ initState: PropTypes.func,isMobile: PropTypes.bool,mode: PropTypes.string,- onToggle: PropTypes.func,screenHeight: PropTypes.number,searchConfig: PropTypes.object,selectedLayer: PropTypes.object,@@ -180,12 +190,16 @@ ProductPicker.propTypes = {};const mapDispatchToProps = (dispatch) => ({- onToggle: () => {+ closeModal: (filters, searchTerm) => {+ dispatch(saveSearchStateAction(filters, searchTerm));dispatch(onToggleAction());},+ initState: () => {+ dispatch(initStateAction());+ },});-const mapStateToProps = (state, ownProps) => {+const mapStateToProps = (state) => {const {browser,productPicker,@@ -193,8 +207,7 @@ const mapStateToProps = (state, ownProps) => {const { screenWidth, screenHeight } = browser;const isMobile = browser.lessThan.medium;const width = getModalWidth(screenWidth);- const searchConfig = getSearchConfig(state);- const { mode, category } = productPicker;+ const { mode, category, searchConfig } = productPicker;return {category,@@ -205,6 +218,7 @@ const mapStateToProps = (state, ownProps) => {width,};};+export default connect(mapStateToProps,mapDispatchToProps,diff --git a/web/js/components/layer/product-picker/search/search-layers-list.js b/web/js/components/layer/product-picker/search/search-layers-list.jsindex ac9c1f4c9..24e1ae115 100644--- a/web/js/components/layer/product-picker/search/search-layers-list.js+++ b/web/js/components/layer/product-picker/search/search-layers-list.js@@ -127,9 +127,7 @@ class SearchLayerList extends React.Component {render() {const { visibleItems, hasMoreItems } = this.state;- const {- componentHeights, isMobile,- } = this.props;+ const { componentHeights, isMobile } = this.props;const { listHeight, listMinHeight } = componentHeights;const listContainerClass = isMobile? 'layer-list-container search mobile'@@ -139,7 +137,7 @@ class SearchLayerList extends React.Component {maxHeight: `${listHeight}px`,minHeight: `${listMinHeight}px`,};- const scrollParentSelector = '.layer-list-container .simplebar-content-wrapper';+ const scrollParentSelector = '.layer-list-container.search .simplebar-content-wrapper';const debouncedOnScroll = lodashDebounce(({ scrollTop }) => {// updateScrollPosition(scrollTop);}, 500);@@ -152,14 +150,14 @@ class SearchLayerList extends React.Component {// scrollBarVerticalTop={listScrollTop}onScroll={debouncedOnScroll}>- <div className="product-outter-list-case layers-all">- <InfiniteScroll- pageStart={0}- loadMore={this.loadMoreItems}- hasMore={hasMoreItems}- useWindow={false}- getScrollParent={() => this.scrollParent}- >+ <InfiniteScroll+ pageStart={0}+ loadMore={this.loadMoreItems}+ hasMore={hasMoreItems}+ useWindow={false}+ getScrollParent={() => this.scrollParent}+ >+ <div className="product-outter-list-case layers-all">{visibleItems.map((layer) => (<SearchLayerRowkey={layer.id}@@ -167,8 +165,8 @@ class SearchLayerList extends React.Component {showLayerMetadata={(id) => this.showLayerMetadata(id)}/>))}- </InfiniteScroll>- </div>+ </div>+ </InfiniteScroll></Scrollbars></div>);diff --git a/web/js/components/layer/product-picker/search/search-layers.js b/web/js/components/layer/product-picker/search/search-layers.jsindex a15172f66..c4a8f7584 100644--- a/web/js/components/layer/product-picker/search/search-layers.js+++ b/web/js/components/layer/product-picker/search/search-layers.js@@ -71,11 +71,17 @@ class SearchLayers extends React.Component {isFilterableshow={5}/>+ <Facet+ field="sources"+ label="Source"+ filterType="any"+ isFilterable+ /><Facetfield="facetPeriod"label="Period"filterType="any"- show={10}+ show={15}/><Facetfield="active"@@ -92,17 +98,11 @@ class SearchLayers extends React.Component {label="Track Day/Night"filterType="any"/>- <Facet- field="sources"- label="Source"- filterType="any"- isFilterable- /><Facetfield="processingLevelId"label="Processing Level"filterType="any"- show={3}+ show={15}/></div></Scrollbars>diff --git a/web/js/modules/product-picker/actions.js b/web/js/modules/product-picker/actions.jsindex a22950075..143f09e95 100644--- a/web/js/modules/product-picker/actions.js+++ b/web/js/modules/product-picker/actions.js@@ -1,5 +1,7 @@+import { getSearchConfig } from './selectors';import {- UPDATE_PRODUCT_PICKER,+ SAVE_SEARCH_STATE,+ INIT_SEARCH_STATE,SELECT_CATEGORY,SELECT_MEASUREMENT,SELECT_SOURCE,@@ -12,10 +14,19 @@ import {RESET_STATE,} from './constants';-export function updateProductPicker(value) {+export function initSearchState() {+ return (dispatch, getState) => {+ dispatch({+ type: INIT_SEARCH_STATE,+ searchConfig: getSearchConfig(getState()),+ });+ };+}+export function saveSearchState(filters, searchTerm) {return {- type: UPDATE_PRODUCT_PICKER,- value,+ type: SAVE_SEARCH_STATE,+ filters,+ searchTerm,};}export function selectCategory(value) {@@ -72,9 +83,9 @@ export function updateListScrollTop(value) {value,};}-export function resetProductPickerState(value) {+export function resetProductPickerState(projection) {return {type: RESET_STATE,- value,+ projection,};}diff --git a/web/js/modules/product-picker/constants.js b/web/js/modules/product-picker/constants.jsindex 54494bc5f..b9d7e2856 100644--- a/web/js/modules/product-picker/constants.js+++ b/web/js/modules/product-picker/constants.js@@ -1,4 +1,5 @@-export const UPDATE_PRODUCT_PICKER = 'PRODUCT_PICKER/UPDATE';+export const INIT_SEARCH_STATE = 'PRODUCT_PICKER/INIT_SEARCH_STATE';+export const SAVE_SEARCH_STATE = 'PRODUCT_PICKER/SAVE_SEARCH_STATE';export const SELECT_CATEGORY = 'PRODUCT_PICKER/SELECT_CATEGORY';export const SELECT_MEASUREMENT = 'PRODUCT_PICKER/SELECT_MEASUREMENT';export const SELECT_SOURCE = 'PRODUCT_PICKER/SELECT_SOURCE';diff --git a/web/js/modules/product-picker/reducers.js b/web/js/modules/product-picker/reducers.jsindex c33ae1802..40976d19b 100644--- a/web/js/modules/product-picker/reducers.js+++ b/web/js/modules/product-picker/reducers.js@@ -1,7 +1,7 @@// eslint-disable-next-line import/no-unresolvedimport googleTagManager from 'googleTagManager';+import {- UPDATE_PRODUCT_PICKER,SELECT_CATEGORY,SELECT_MEASUREMENT,SELECT_SOURCE,@@ -12,42 +12,51 @@ import {TOGGLE_CATEGORY_MODE,UPDATE_LIST_SCROLL_TOP,RESET_STATE,+ INIT_SEARCH_STATE,+ SAVE_SEARCH_STATE,} from './constants';-const projToListType = {- arctic: 'measurements',- antarctic: 'measurements',- geographic: 'category',-};-export const productPickerState = {mode: 'category',category: undefined,- results: [],- searchResultRows: undefined,- numRowsFilteredOut: undefined,- inputValue: '',- filterByAvailable: true,- listScrollTop: 0,+ categoryType: 'hazards and disasters',+ filters: [],+ searchTerm: '',selectedLayer: undefined,selectedMeasurement: undefined,selectedMeasurementSourceIndex: 0,+ searchConfig: undefined,+ results: [],+ // searchResultRows: undefined,+ // numRowsFilteredOut: undefined,+ // filterByAvailable: true,+ // listScrollTop: 0,};export function getInitialState(config) {- return {- ...productPickerState,- categoryType: Object.keys(config.categories)[1],- };+ return productPickerState;}export function productPickerReducer(state = productPickerState, action) {switch (action.type) {- case UPDATE_PRODUCT_PICKER:+ case INIT_SEARCH_STATE: {+ const { searchConfig } = action;return {...state,- ...action.value,+ searchConfig,};+ }++ case SAVE_SEARCH_STATE: {+ const { filters, searchTerm } = action;+ return {+ ...state,+ filters,+ searchTerm,+ searchConfig: null,+ };+ }+case SELECT_CATEGORY: {googleTagManager.pushEvent({event: 'layers_meta_category',@@ -62,6 +71,7 @@ export function productPickerReducer(state = productPickerState, action) {selectedMeasurement: null,};}+case SELECT_MEASUREMENT: {return {...state,@@ -69,16 +79,21 @@ export function productPickerReducer(state = productPickerState, action) {selectedMeasurementSourceIndex: 0,};}- case SELECT_SOURCE:++ case SELECT_SOURCE: {return {...state,selectedMeasurementSourceIndex: action.value,};- case SELECT_LAYER:+ }++ case SELECT_LAYER: {return {...state,selectedLayer: action.value,};+ }+case SHOW_MEASUREMENTS: {const { category, selectedMeasurement } = action.value;googleTagManager.pushEvent({@@ -94,12 +109,15 @@ export function productPickerReducer(state = productPickerState, action) {selectedMeasurement,};}- case TOGGLE_SEARCH_MODE:++ case TOGGLE_SEARCH_MODE: {return {...state,mode: 'search',selectedLayer: null,};+ }+case TOGGLE_FEATURED_TAB: {const { config } = action;const category = config.categories.featured.All;@@ -113,25 +131,38 @@ export function productPickerReducer(state = productPickerState, action) {selectedMeasurement: selectedMeasurementId,};}- case TOGGLE_CATEGORY_MODE:++ case TOGGLE_CATEGORY_MODE: {return {- ...state,+ ...productPickerState,mode: 'category',- selectedLayer: null,- selectedMeasurement: null,- selectedMeasurementSourceIndex: 0,- listScrollTop: 0,};- case UPDATE_LIST_SCROLL_TOP:+ }++ // TODO this one unused?+ case UPDATE_LIST_SCROLL_TOP: {return {...state,listScrollTop: action.value,};+ }+case RESET_STATE: {- const listType = projToListType[action.value];+ // When switching projections: if we were in 'search'+ // mode stay there. Otherwise if in a polar projection+ // show 'measurement' rather than 'category'+ const projToListMode = {+ arctic: 'measurements',+ antarctic: 'measurements',+ geographic: 'category',+ };+ const modeForProj = projToListMode[action.projection];+ const prevMode = state.mode;const newState = {- ...productPickerState,- listType,+ ...state,+ mode: prevMode === 'search' ? prevMode : modeForProj,+ filters: [],+ searchTerm: '',};return { ...state, ...newState };}diff --git a/web/js/modules/product-picker/searchConfig.js b/web/js/modules/product-picker/searchConfig.jsindex ae70844a0..6c78aaa98 100644--- a/web/js/modules/product-picker/searchConfig.js+++ b/web/js/modules/product-picker/searchConfig.js@@ -16,20 +16,19 @@ let projectionRef;const hideZeroCountFields = ['measurements',+ 'sources',+ 'facetPeriod',+ 'processingLevelId',];// TODO pull from a config?const facetFields = [- 'dataCenter','processingLevelId','facetPeriod','group',- 'collectionDataType',- 'projects','sources','categories','measurements',- 'platforms','active','track','daynight',@@ -51,7 +50,7 @@ function moveNoneOther(data) {}// Convert facet count obj into the format search-ui expects-function formatFacets(facetValues, firstFormat) {+function formatFacets(facetValues) {const formattedFacets = {};lodashForEach(facetValues, (facetObj, field) => {let data = Object.keys(facetObj)@@ -178,7 +177,7 @@ async function onSearch (requestState) {* @param {*} config - the entire WV config object* @param {*} projection - current map projection*/-export default function initSearch(layers, config, projection) {+export default function initSearch(layers, config, projection, filters, searchTerm) {initialLayersArray = layers;configRef = config;projectionRef = projection;@@ -193,7 +192,10 @@ export default function initSearch(layers, config, projection) {// debug: true,alwaysSearchOnInitialLoad: true,trackUrlState: false,- initialState: {},+ initialState: {+ filters,+ searchTerm,+ },onSearch,searchQuery: {},};diff --git a/web/js/modules/product-picker/selectors.js b/web/js/modules/product-picker/selectors.jsindex 39f1749da..716c39759 100644--- a/web/js/modules/product-picker/selectors.js+++ b/web/js/modules/product-picker/selectors.js@@ -16,6 +16,8 @@ const decodeHtml = (html) => {const getConfig = ({ config }) => config;const getProjection = ({ proj }) => proj && proj.id;const getProductPicker = ({ productPicker }) => productPicker;+const getFilters = ({ productPicker }) => productPicker.filters;+const getSearchTerm = ({ productPicker }) => productPicker.searchTerm;const getLayersForProjection = createSelector([getConfig, getProjection],@@ -43,7 +45,13 @@ const getLayersForProjection = createSelector(* https://github.com/elastic/search-ui/blob/master/ADVANCED.md#advanced-configuration*/export const getSearchConfig = createSelector(- [getLayersForProjection, getConfig, getProjection],+ [+ getLayersForProjection,+ getConfig,+ getProjection,+ getFilters,+ getSearchTerm,+ ],initSearch,);