Interactive interface for browsing global, full-resolution satellite imagery
apply Error boundary to containers #1623
Benjamin King63958f8bee49
diff --git a/web/js/app.js b/web/js/app.jsindex c50d9861d..3388e691a 100644--- a/web/js/app.js+++ b/web/js/app.js@@ -23,6 +23,8 @@ import { updateLegacyInitComplete } from './modules/migration/actions';import { calculateResponsiveState } from 'redux-responsive';import Tour from './containers/tour';import AnimationWidget from './containers/animation-widget';+import ErrorBoundary from './containers/error-boundary';+import Debug from './components/util/debug';// Dependency CSSimport '../../node_modules/bootstrap/dist/css/bootstrap.css';@@ -193,6 +195,9 @@ class App extends React.Component {</section><OlCoordinates mouseEvents={this.props.mapMouseEvents} /><Modal />+ <ErrorBoundary>+ <Debug parameters={this.props.parameters} />+ </ErrorBoundary></div>);}diff --git a/web/js/combine-ui.js b/web/js/combine-ui.jsindex a8a254a84..22a1a93d8 100644--- a/web/js/combine-ui.js+++ b/web/js/combine-ui.js@@ -3,7 +3,6 @@ import { dateLabel } from './date/label';// compare// import { compareUi } from './compare/ui';-import { alertUi } from './alert/ui';// Timelineimport dateWheels from './date/wheels';import { timeline } from './date/timeline';@@ -15,15 +14,9 @@ import { timelinePick } from './date/timeline-pick';import { timelinePan } from './date/timeline-pan';import { timelineInput } from './date/timeline-input';import { timelineCompare } from './date/compare-picks';-// Tour-// import { tourUi } from './tour/ui';import { layersActive } from './layers/active';import { mapui } from './map/ui';import { mapAnimate } from './map/animate';-// import { animationUi } from './animation/ui';-// import { animationWidget } from './animation/widget';-// import { animationRangeSelect } from './animation/range-select';-// import { animationGif } from './animation/gif';import { debugLayers } from './debug';import { dataUi } from './map/data/ui';import naturalEventsUI from './map/natural-events/ui';@@ -42,7 +35,7 @@ export function combineUi(models, config, MapMouseEvents, store) {// ui.alert = alertUi(ui, config);// ui.tour = tourUi(models, ui, config);}- ui.activeLayers = layersActive(models, ui, config);+ // ui.activeLayers = layersActive(models, ui, config);// ui.addModal = layersModal(models, ui, config);// ui.layerSettingsModal = layersOptions(models, ui, config);// Test via a getter in the options object to see if the passive property is accesseddiff --git a/web/js/components/util/debug.js b/web/js/components/util/debug.jsnew file mode 100644index 000000000..18f56ed1e--- /dev/null+++ b/web/js/components/util/debug.js@@ -0,0 +1,22 @@+import React from 'react';+import PropTypes from 'prop-types';++/*+ * A react component, Builds a rather specific+ * interactive widget+ *+ * @class AnimationWidget+ * @extends React.Component+ */+export default class debug extends React.Component {+ render() {+ if (this.props.parameters.showError) {+ throw new Error('this is a test error');+ }+ return '';+ }+}++debug.propTypes = {+ parameters: PropTypes.object+};diff --git a/web/js/containers/animation-widget.js b/web/js/containers/animation-widget.jsindex 6c5ce454c..76b19178a 100644--- a/web/js/containers/animation-widget.js+++ b/web/js/containers/animation-widget.js@@ -1,6 +1,7 @@import React from 'react';import { connect } from 'react-redux';import { without as lodashWithout } from 'lodash';+import ErrorBoundary from './error-boundary';import PropTypes from 'prop-types';import Slider, { Handle } from 'rc-slider';import TimeSelector from '../components/date-selector/date-selector';@@ -118,76 +119,82 @@ class AnimationWidget extends React.Component {onPushPause} = this.props;return (- <div- id="wv-animation-widget"- className={- 'wv-animation-widget' + (hasSubdailyLayers ? ' subdaily' : '')- }- >- <AnimWidgetHeader- text={increment}- toolTipTextArray={incrementArray}- onClick={onZoomSelect}- />-- <PlayButton playing={isPlaying} play={onPushPlay} pause={onPushPause} />- <LoopButton looping={looping} onLoop={this.onLoop.bind(this)} />- <div className="wv-slider-case">- <Slider- className="input-range"- step={0.5}- max={10}- min={0.5}- value={this.state.speed}- onChange={num => this.setState({ speed: num })}- handle={RangeHandle}- onBeforeChange={() => this.setState({ isSliding: true })}- onAfterChange={() => {- this.setState({ isSliding: false });- this.props.onSlide(this.state.speed);- }}- />- <span className="wv-slider-label">{sliderLabel}</span>- </div>-- <a- href="javascript:void(null)"- title="Create Animated GIF"- className="wv-icon-case"- onClick={this.props.onPushGIF}+ <ErrorBoundary>+ <div+ id="wv-animation-widget"+ className={+ 'wv-animation-widget' + (hasSubdailyLayers ? ' subdaily' : '')+ }>- <i- id="wv-animation-widget-file-video-icon"- className="fas fa-file-video wv-animation-widget-icon"+ <AnimWidgetHeader+ text={increment}+ toolTipTextArray={incrementArray}+ onClick={onZoomSelect}/>- </a>- <div className="wv-anim-dates-case">- <TimeSelector- width="120"- height="30"- date={startDate}- id="start"- idSuffix="animation-widget-start"- onDateChange={this.onDateChange.bind(this)}- maxDate={endDate}- minDate={minDate}- hasSubdailyLayers={hasSubdailyLayers}- />- <div className="thru-label">To</div>- <TimeSelector- width="120"- height="30"- date={endDate}- id="end"- idSuffix="animation-widget-end"- onDateChange={this.onDateChange.bind(this)}- maxDate={maxDate}- minDate={startDate}- hasSubdailyLayers={hasSubdailyLayers}++ <PlayButton+ playing={isPlaying}+ play={onPushPlay}+ pause={onPushPause}/>+ <LoopButton looping={looping} onLoop={this.onLoop.bind(this)} />+ <div className="wv-slider-case">+ <Slider+ className="input-range"+ step={0.5}+ max={10}+ min={0.5}+ value={this.state.speed}+ onChange={num => this.setState({ speed: num })}+ handle={RangeHandle}+ onBeforeChange={() => this.setState({ isSliding: true })}+ onAfterChange={() => {+ this.setState({ isSliding: false });+ this.props.onSlide(this.state.speed);+ }}+ />+ <span className="wv-slider-label">{sliderLabel}</span>+ </div>++ <a+ href="javascript:void(null)"+ title="Create Animated GIF"+ className="wv-icon-case"+ onClick={this.props.onPushGIF}+ >+ <i+ id="wv-animation-widget-file-video-icon"+ className="fas fa-file-video wv-animation-widget-icon"+ />+ </a>+ <div className="wv-anim-dates-case">+ <TimeSelector+ width="120"+ height="30"+ date={startDate}+ id="start"+ idSuffix="animation-widget-start"+ onDateChange={this.onDateChange.bind(this)}+ maxDate={endDate}+ minDate={minDate}+ hasSubdailyLayers={hasSubdailyLayers}+ />+ <div className="thru-label">To</div>+ <TimeSelector+ width="120"+ height="30"+ date={endDate}+ id="end"+ idSuffix="animation-widget-end"+ onDateChange={this.onDateChange.bind(this)}+ maxDate={maxDate}+ minDate={startDate}+ hasSubdailyLayers={hasSubdailyLayers}+ />+ </div>+ <i className="fa fa-times wv-close" onClick={this.props.onClose} /></div>- <i className="fa fa-times wv-close" onClick={this.props.onClose} />- </div>+ </ErrorBoundary>);}}diff --git a/web/js/containers/error-boundary.js b/web/js/containers/error-boundary.jsnew file mode 100644index 000000000..e46a30a37--- /dev/null+++ b/web/js/containers/error-boundary.js@@ -0,0 +1,57 @@+import React from 'react';+import { connect } from 'react-redux';+import PropTypes from 'prop-types';+import { openCustomContent } from '../modules/modal/actions';+const HEADER_TEXT = 'Error!';+const BODY_COMPONENT = () => (+ <React.Fragment>+ <div className="error-header">+ <i className="error-icon fas fa-exclamation-triangle fa-3x" />+ An unexpected error has occurred!+ </div>+ <div className="error-body">+ Please reload the page and try again. If you continue to have problems,+ contact us at+ <a href="mailto:@MAIL@"> @MAIL@ </a>+ </div>+ </React.Fragment>+);+class ErrorBoundary extends React.Component {+ constructor(props) {+ super(props);+ this.state = { error: false };+ }+ componentDidCatch(error, info) {+ this.setState({ error: true });+ // Display fallback UI+ this.props.errorAlert();+ // log the error+ console.warn(error, info);+ }++ render() {+ if (this.state.error) {+ return '';+ }+ return this.props.children;+ }+}+const mapDispatchToProps = dispatch => ({+ errorAlert: () => {+ dispatch(+ openCustomContent('ERROR_MODAL', {+ headerText: HEADER_TEXT,+ bodyComponent: BODY_COMPONENT+ })+ );+ }+});++export default connect(+ null,+ mapDispatchToProps+)(ErrorBoundary);+ErrorBoundary.propTypes = {+ children: PropTypes.array,+ errorAlert: PropTypes.func+};diff --git a/web/js/containers/image-download.js b/web/js/containers/image-download.jsindex 4cf96dfbe..f5baa8b57 100644--- a/web/js/containers/image-download.js+++ b/web/js/containers/image-download.js@@ -5,6 +5,7 @@ import Panel from '../components/image-download/panel';import Crop from '../components/util/image-crop';import { onToggle } from '../modules/modal/actions';import { debounce } from 'lodash';+import ErrorBoundary from './error-boundary';import * as olProj from 'ol/proj';import {@@ -82,7 +83,7 @@ class ImageDownloadContainer extends Component {proj.selected.resolutions);return (- <React.Fragment>+ <ErrorBoundary><Panelprojection={proj}fileTypes={fileTypes}@@ -118,7 +119,7 @@ class ImageDownloadContainer extends Component {}}showCoordinates={true}/>- </React.Fragment>+ </ErrorBoundary>);}}diff --git a/web/js/containers/modal.js b/web/js/containers/modal.jsindex c22a713c3..79567169a 100644--- a/web/js/containers/modal.js+++ b/web/js/containers/modal.js@@ -5,6 +5,7 @@ import update from 'immutability-helper';import { toLower as lodashToLower } from 'lodash';import { Modal, ModalBody, ModalHeader } from 'reactstrap';import { onToggle } from '../modules/modal/actions';+import ErrorBoundary from './error-boundary';import DetectOuterClick from '../components/util/detect-outer-click';class ModalContainer extends Component {@@ -59,46 +60,50 @@ class ModalContainer extends Component {}};return (- <Modal- isOpen={isOpen}- toggle={toggleWithClose}- backdrop={backdrop && type !== 'selection'}- id={lowerCaseId}- className={- isTemplateModal ? 'template-modal' : modalClassName || 'default-modal'- }- autoFocus={autoFocus || false}- style={style}- wrapClassName={wrapClassName + ' ' + lowerCaseId}- modalTransition={{ timeout: timeout || 100 }}- >- {CompletelyCustomModal ? (- <CompletelyCustomModal />- ) : (- <DetectOuterClick- onClick={toggleWithClose}- disabled={!isOpen || type === 'selection' || clickableBehindModal}- >- {headerComponent || headerText ? (- <ModalHeader toggle={toggleWithClose}>- {headerComponent ? <headerComponent /> : headerText || ''}- </ModalHeader>- ) : (- ''- )}- <ModalBody>- {bodyHeader ? <h3>{bodyHeader}</h3> : ''}- {BodyComponent ? (- <BodyComponent {...bodyComponentProps} />- ) : isTemplateModal ? (- this.getTemplateBody()+ <ErrorBoundary>+ <Modal+ isOpen={isOpen}+ toggle={toggleWithClose}+ backdrop={backdrop && type !== 'selection'}+ id={lowerCaseId}+ className={+ isTemplateModal+ ? 'template-modal'+ : modalClassName || 'default-modal'+ }+ autoFocus={autoFocus || false}+ style={style}+ wrapClassName={wrapClassName + ' ' + lowerCaseId}+ modalTransition={{ timeout: timeout || 100 }}+ >+ {CompletelyCustomModal ? (+ <CompletelyCustomModal />+ ) : (+ <DetectOuterClick+ onClick={toggleWithClose}+ disabled={!isOpen || type === 'selection' || clickableBehindModal}+ >+ {headerComponent || headerText ? (+ <ModalHeader toggle={toggleWithClose}>+ {headerComponent ? <headerComponent /> : headerText || ''}+ </ModalHeader>) : (- bodyText || ''+ '')}- </ModalBody>- </DetectOuterClick>- )}- </Modal>+ <ModalBody>+ {bodyHeader ? <h3>{bodyHeader}</h3> : ''}+ {BodyComponent ? (+ <BodyComponent {...bodyComponentProps} />+ ) : isTemplateModal ? (+ this.getTemplateBody()+ ) : (+ bodyText || ''+ )}+ </ModalBody>+ </DetectOuterClick>+ )}+ </Modal>+ </ErrorBoundary>);}}diff --git a/web/js/containers/sidebar/sidebar.js b/web/js/containers/sidebar/sidebar.jsindex d308ebddf..539fdaadb 100644--- a/web/js/containers/sidebar/sidebar.js+++ b/web/js/containers/sidebar/sidebar.js@@ -13,7 +13,7 @@ import googleTagManager from 'googleTagManager';import { getCheckerboard, loadCustom } from '../../modules/palettes/util';import { loadedCustomPalettes } from '../../modules/palettes/actions';import { getLayers } from '../../modules/layers/selectors';-+import ErrorBoundary from '../error-boundary';import util from '../../util/util';import {changeTab,@@ -140,61 +140,65 @@ class Sidebar extends React.Component {} = this.props;const wheelCallBack = util.browser.chrome ? util.preventPinch : null;return (- <section id="wv-sidebar">- <a- href="/"- title="Click to Reset Worldview to Defaults"- id="wv-logo"- ref={iconElement => (this.iconElement = iconElement)}- onWheel={wheelCallBack}- />- <CollapsedButton- isCollapsed={isCollapsed}- onclick={this.toggleSidebar.bind(this)}- numberOfLayers={numberOfLayers}- />- <div- id="productsHolder"- className="products-holder-case"- ref={el => {- this.sideBarCase = el;- }}- style={- isCollapsed- ? { maxHeight: '0' }- : { maxHeight: screenHeight + 'px' }- }- onWheel={wheelCallBack}- >- <NavCase- activeTab={activeTab}- onTabClick={onTabClick}- tabTypes={tabTypes}- toggleSidebar={this.toggleSidebar.bind(this)}+ <ErrorBoundary>+ <section id="wv-sidebar">+ <a+ href="/"+ title="Click to Reset Worldview to Defaults"+ id="wv-logo"+ ref={iconElement => (this.iconElement = iconElement)}+ onWheel={wheelCallBack}+ />+ <CollapsedButton+ isCollapsed={isCollapsed}+ onclick={this.toggleSidebar.bind(this)}+ numberOfLayers={numberOfLayers}/>- <TabContent activeTab={activeTab}>- <TabPane tabId="layers">- {this.getProductsToRender(activeTab, isCompareMode)}- </TabPane>- <TabPane tabId="events">- <Events- isActive={activeTab === 'events'}- height={subComponentHeight}- />- </TabPane>- <TabPane tabId="download">- <Data- isActive={activeTab === 'download'}- height={subComponentHeight}- tabTypes={tabTypes}- />- </TabPane>- <footer ref={footerElement => (this.footerElement = footerElement)}>- <FooterContent tabTypes={tabTypes} activeTab={activeTab} />- </footer>- </TabContent>- </div>- </section>+ <div+ id="productsHolder"+ className="products-holder-case"+ ref={el => {+ this.sideBarCase = el;+ }}+ style={+ isCollapsed+ ? { maxHeight: '0' }+ : { maxHeight: screenHeight + 'px' }+ }+ onWheel={wheelCallBack}+ >+ <NavCase+ activeTab={activeTab}+ onTabClick={onTabClick}+ tabTypes={tabTypes}+ toggleSidebar={this.toggleSidebar.bind(this)}+ />+ <TabContent activeTab={activeTab}>+ <TabPane tabId="layers">+ {this.getProductsToRender(activeTab, isCompareMode)}+ </TabPane>+ <TabPane tabId="events">+ <Events+ isActive={activeTab === 'events'}+ height={subComponentHeight}+ />+ </TabPane>+ <TabPane tabId="download">+ <Data+ isActive={activeTab === 'download'}+ height={subComponentHeight}+ tabTypes={tabTypes}+ />+ </TabPane>+ <footer+ ref={footerElement => (this.footerElement = footerElement)}+ >+ <FooterContent tabTypes={tabTypes} activeTab={activeTab} />+ </footer>+ </TabContent>+ </div>+ </section>+ </ErrorBoundary>);}}diff --git a/web/js/containers/toolbar.js b/web/js/containers/toolbar.jsindex 58ce76c14..d6e6d62af 100644--- a/web/js/containers/toolbar.js+++ b/web/js/containers/toolbar.js@@ -7,6 +7,7 @@ import ImageDownload from './image-download';import Projection from './projection';import InfoList from './info';import ShareLinks from './share';+import ErrorBoundary from './error-boundary';import {requestNotifications,setNotifications@@ -89,62 +90,64 @@ class toolbarContainer extends Component {? ' wv-status-' + notificationType: ' wv-status-hide';return (- <ButtonToolbar id="wv-toolbar" className={'wv-toolbar'}>- <Button- id="wv-link-button"- className="wv-toolbar-button"- title="Share this map"- onClick={() =>- openModal(- 'TOOLBAR_SHARE_LINK',- CUSTOM_MODAL_PROPS['TOOLBAR_SHARE_LINK']- )- }- >- <i className="fas fa-share-square fa-2x" />- </Button>- {config.ui && config.ui.projections ? (+ <ErrorBoundary>+ <ButtonToolbar id="wv-toolbar" className={'wv-toolbar'}><Button- id="wv-proj-button"+ id="wv-link-button"className="wv-toolbar-button"- title="Switch projection"+ title="Share this map"onClick={() =>openModal(- 'TOOLBAR_PROJECTION',- CUSTOM_MODAL_PROPS['TOOLBAR_PROJECTION']+ 'TOOLBAR_SHARE_LINK',+ CUSTOM_MODAL_PROPS['TOOLBAR_SHARE_LINK'])}>- <i className="fas fa-globe-asia fa-2x" />{' '}+ <i className="fas fa-share-square fa-2x" /></Button>- ) : (- ''- )}- <Button- id="wv-image-button"- className="wv-toolbar-button"- title="Take a snapshot"- onClick={() =>- openModal(- 'TOOLBAR_SNAPSHOT',- CUSTOM_MODAL_PROPS['TOOLBAR_SNAPSHOT']- )- }- >- <i className="fa fa-camera fa-2x" />{' '}- </Button>- <Button- id="wv-info-button"- title="Information"- className={'wv-toolbar-button' + notificationClass}- onClick={() =>- openModal('TOOLBAR_INFO', CUSTOM_MODAL_PROPS['TOOLBAR_INFO'])- }- data-content={notificationContentNumber}- >- <i className="fa fa-info-circle fa-2x" />{' '}- </Button>- </ButtonToolbar>+ {config.ui && config.ui.projections ? (+ <Button+ id="wv-proj-button"+ className="wv-toolbar-button"+ title="Switch projection"+ onClick={() =>+ openModal(+ 'TOOLBAR_PROJECTION',+ CUSTOM_MODAL_PROPS['TOOLBAR_PROJECTION']+ )+ }+ >+ <i className="fas fa-globe-asia fa-2x" />{' '}+ </Button>+ ) : (+ ''+ )}+ <Button+ id="wv-image-button"+ className="wv-toolbar-button"+ title="Take a snapshot"+ onClick={() =>+ openModal(+ 'TOOLBAR_SNAPSHOT',+ CUSTOM_MODAL_PROPS['TOOLBAR_SNAPSHOT']+ )+ }+ >+ <i className="fa fa-camera fa-2x" />{' '}+ </Button>+ <Button+ id="wv-info-button"+ title="Information"+ className={'wv-toolbar-button' + notificationClass}+ onClick={() =>+ openModal('TOOLBAR_INFO', CUSTOM_MODAL_PROPS['TOOLBAR_INFO'])+ }+ data-content={notificationContentNumber}+ >+ <i className="fa fa-info-circle fa-2x" />{' '}+ </Button>+ </ButtonToolbar>+ </ErrorBoundary>);}}diff --git a/web/js/containers/tour.js b/web/js/containers/tour.jsindex 41c978cf9..c0e14c9d1 100644--- a/web/js/containers/tour.js+++ b/web/js/containers/tour.js@@ -7,6 +7,7 @@ import { connect } from 'react-redux';import googleTagManager from 'googleTagManager';import { endTour, selectStory, startTour } from '../modules/tour/actions';import { findIndex as lodashFindIndex, get as lodashGet } from 'lodash';+import ErrorBoundary from './error-boundary';import update from 'immutability-helper';import { history } from '../main';import util from '../util/util';@@ -222,56 +223,58 @@ class Tour extends React.Component {this.setState({ modalStart: true });}return (- <div>- {modalStart ? (- <TourStart- stories={stories}- storyOrder={storyOrder}- modalStart={modalStart}- toggleModalStart={this.toggleModalStart}- toggleModalInProgress={this.toggleModalInProgress}- toggleModalComplete={this.toggleModalComplete}- selectTour={this.selectTour.bind(this)}- showTourAlert={showTourAlert}- hideTour={hideTour}- showTour={showTour}- endTour={this.endTour.bind(this)}- />- ) : modalInProgress ? (- <TourInProgress- config={config}- models={models}- endTour={this.endTour.bind(this)}- modalInProgress={modalInProgress}- toggleModalStart={this.toggleModalStart}- toggleModalInProgress={this.toggleModalInProgress}- toggleModalComplete={this.toggleModalComplete}- currentStep={currentStep}- totalSteps={totalSteps}- currentStoryIndex={currentStoryIndex}- incrementStep={this.incrementStep}- decreaseStep={this.decreaseStep}- stories={stories}- currentStoryId={currentStoryId}- currentStory={currentStory}- showTourAlert={showTourAlert}- metaLoaded={metaLoaded}- isLoadingMeta={isLoadingMeta}- description={description}- processStepLink={processStepLink}- />- ) : (- <TourComplete- currentStory={currentStory}- modalComplete={modalComplete}- toggleModalStart={this.toggleModalStart}- toggleModalInProgress={this.toggleModalInProgress}- toggleModalComplete={this.toggleModalComplete}- resetTour={this.resetTour.bind(this)}- endTour={this.endTour.bind(this)}- />- )}- </div>+ <ErrorBoundary>+ <div>+ {modalStart ? (+ <TourStart+ stories={stories}+ storyOrder={storyOrder}+ modalStart={modalStart}+ toggleModalStart={this.toggleModalStart}+ toggleModalInProgress={this.toggleModalInProgress}+ toggleModalComplete={this.toggleModalComplete}+ selectTour={this.selectTour.bind(this)}+ showTourAlert={showTourAlert}+ hideTour={hideTour}+ showTour={showTour}+ endTour={this.endTour.bind(this)}+ />+ ) : modalInProgress ? (+ <TourInProgress+ config={config}+ models={models}+ endTour={this.endTour.bind(this)}+ modalInProgress={modalInProgress}+ toggleModalStart={this.toggleModalStart}+ toggleModalInProgress={this.toggleModalInProgress}+ toggleModalComplete={this.toggleModalComplete}+ currentStep={currentStep}+ totalSteps={totalSteps}+ currentStoryIndex={currentStoryIndex}+ incrementStep={this.incrementStep}+ decreaseStep={this.decreaseStep}+ stories={stories}+ currentStoryId={currentStoryId}+ currentStory={currentStory}+ showTourAlert={showTourAlert}+ metaLoaded={metaLoaded}+ isLoadingMeta={isLoadingMeta}+ description={description}+ processStepLink={processStepLink}+ />+ ) : (+ <TourComplete+ currentStory={currentStory}+ modalComplete={modalComplete}+ toggleModalStart={this.toggleModalStart}+ toggleModalInProgress={this.toggleModalInProgress}+ toggleModalComplete={this.toggleModalComplete}+ resetTour={this.resetTour.bind(this)}+ endTour={this.endTour.bind(this)}+ />+ )}+ </div>+ </ErrorBoundary>);} else {return null;