Interactive interface for browsing global, full-resolution satellite imagery
WV-3844: Charting Mode Responsive Window (#6414)
christof-wittreicheadc28bb16f1
diff --git a/e2e/features/charting/charting-test.spec.js b/e2e/features/charting/charting-test.spec.jsindex 8e23aee44..d676502b6 100644--- a/e2e/features/charting/charting-test.spec.js+++ b/e2e/features/charting/charting-test.spec.js@@ -88,7 +88,7 @@ test('Date selector opens datepicker modal', async () => {if (isChartingEnabled) {await page.locator('#chart-toggle-button').click()await page.locator('#charting-date-button').click()- const chartingDateModal = page.locator('#charting-date-modal > div > div > div.modal-header > h5')+ const chartingDateModal = page.locator('#charting-date-modal > div > div > div > div.modal-header > h5')await expect(chartingDateModal).toHaveText('Charting Mode Date Selection')}})@@ -98,9 +98,9 @@ test('Info modal opens on mode start & on icon click', async () => {const isChartingEnabled = await page.$('#chart-toggle-button')if (isChartingEnabled) {await page.locator('#chart-toggle-button').click()- const infoModal = page.locator('#charting_info_modal > div > div > div.modal-header > h5')+ const infoModal = page.locator('#charting_info_modal > div > div > div > div.modal-header > h5')await expect(infoModal).toHaveText('Charting Tool - BETA')- await page.locator('#charting_info_modal > div > div > div.modal-header > button').click()+ await page.locator('#charting_info_modal > div > div > div > div.modal-header > button').click()await expect(infoModal).toHaveCount(0)await page.locator('#charting-info-container svg').click()await expect(infoModal).toHaveText('Charting Tool - BETA')diff --git a/web/js/components/charting/chart-component.js b/web/js/components/charting/chart-component.jsindex 50a30f77b..1d9f3ef14 100644--- a/web/js/components/charting/chart-component.js+++ b/web/js/components/charting/chart-component.js@@ -142,6 +142,7 @@ function ChartComponent(props) {createLayer,overviewMapLayerDef,layers,+ toggleErrorDaysExpanded,} = props;const [errorCollapsed, setErrorCollapsed] = useState(true);@@ -163,6 +164,11 @@ function ChartComponent(props) {layerId,} = liveData;+ function toggleErrorCollapsed(val) {+ setErrorCollapsed(val);+ toggleErrorDaysExpanded(!val);+ }+// Build display string "YYYY-MM-DD, YYYY-MM-DD, ..." with non-breaking spacesconst errorDatesDisplay = useMemo(() => errors?.error_days.map((item) => {@@ -550,7 +556,7 @@ function ChartComponent(props) {</div>)}<div className="error-expand-button">- <span className="error-expand-button-inner" onClick={() => setErrorCollapsed(!errorCollapsed)}>+ <span className="error-expand-button-inner" onClick={() => toggleErrorCollapsed(!errorCollapsed)}>{errorCollapsed ? 'more' : 'less'}<FontAwesomeIconclassName="layer-group-collapse"@@ -593,6 +599,7 @@ ChartComponent.propTypes = {createLayer: PropTypes.func,overviewMapLayerDef: PropTypes.oneOfType([PropTypes.object, PropTypes.oneOf(['null'])]),layers: PropTypes.shape,+ toggleErrorDaysExpanded: PropTypes.func,};CustomXAxisTick.propTypes = {diff --git a/web/js/components/sidebar/charting-mode-options.js b/web/js/components/sidebar/charting-mode-options.jsindex c14633ce2..509b942ec 100644--- a/web/js/components/sidebar/charting-mode-options.js+++ b/web/js/components/sidebar/charting-mode-options.js@@ -25,7 +25,7 @@ import {changeChartingStartDate,changeChartingEndDate,} from '../../modules/charting/actions';-import { openCustomContent } from '../../modules/modal/actions';+import { openCustomContent, onClose } from '../../modules/modal/actions';import { CRS } from '../../modules/map/constants';import ChartingInfo from '../charting/charting-info';import ChartingError from '../charting/charting-error';@@ -54,6 +54,7 @@ function ChartingModeOptions(props) {crs,displayChart,displaySimpleStats,+ closeModal,isChartingActive,isMobile,onChartDateButtonClick,@@ -88,6 +89,8 @@ function ChartingModeOptions(props) {if (!olMap) return null;const isMounted = useRef(false);+ const chartData = useRef({});+ const isErrordaysExpanded = useRef(false);const [isPostRender, setIsPostRender] = useState(false);const [doRenderChart, setDoRenderChart] = useState(false);const [mapViewChecked, setMapViewChecked] = useState(false);@@ -103,6 +106,7 @@ function ChartingModeOptions(props) {} = boundaries;const debouncedUpdateAOICoordinates = lodashDebounce(updateAOICoordinates, 50);+ const debouncedModalClose = lodashDebounce(closeModal, 0);/*** Processes the start & end times & aligns them with the timeline if values are undefined@@ -149,6 +153,45 @@ function ChartingModeOptions(props) {return null;}+ function toggleErrorDaysExpanded(val) {+ isErrordaysExpanded.current = val;+ displayChart(chartData.current, screenWidth, toggleErrorDaysExpanded, isErrordaysExpanded);+ }++ /**+ * Update latitude longitude values on+ * crop change+ * @param {Object} boundaries+ *+ * @returns {null}+ */+ const onBoundaryUpdate = (boundaryObj) => {+ const {+ xBoundary = boundaryObj.x,+ yBoundary = boundaryObj.y,+ width,+ height,+ } = boundaryObj;+ const newBoundaries = {+ x: xBoundary,+ y: yBoundary,+ x2: xBoundary + width,+ y2: yBoundary + height,+ };+ setBoundaries(newBoundaries);+ const bottomLeft = getLatLongFromPixelValue(newBoundaries.x, newBoundaries.y2);+ const topRight = getLatLongFromPixelValue(newBoundaries.x2, newBoundaries.y);+ setBottomLeftLatLong(bottomLeft);+ setTopRightLatLong(topRight);+ debouncedUpdateAOICoordinates([...bottomLeft, ...topRight]);+ setMapViewChecked(false);+ if (maxExtent) {+ const inLeftWing = bottomLeft[0] < maxExtent[0] && topRight[0] < maxExtent[0];+ const inRightWing = bottomLeft[0] > maxExtent[2] && topRight[0] > maxExtent[2];+ setIsWithinWings(inLeftWing || inRightWing);+ }+ };+const { initialStartDate, initialEndDate } = initializeDates(timeSpanStartDate, timeSpanEndDate);const primaryDate = formatDateString(initialStartDate);const secondaryDate = formatDateString(initialEndDate);@@ -186,6 +229,17 @@ function ChartingModeOptions(props) {}}, [projections]);+ useEffect(() => {+ if (!isMounted.current) return;+ const boundariesObj = {+ x,+ y,+ width: x2 - x,+ height: y2 - y,+ };+ onBoundaryUpdate(boundariesObj);+ }, [screenWidth, screenHeight]);+useEffect(() => {isMounted.current = true;onUpdateStartDate(initialStartDate);@@ -237,6 +291,15 @@ function ChartingModeOptions(props) {}}, [isModalOpen, modalId]);+ useEffect(() => {+ if (!chartData.current || Object.keys(chartData.current).length === 0 || !isModalOpen || timeSpanSelection !== 'range') return;+ if (screenWidth < 768) {+ debouncedModalClose();+ updateModalOpen(false);+ }+ displayChart(chartData.current, screenWidth, toggleErrorDaysExpanded, isErrordaysExpanded);+ }, [screenWidth]);+/*** Provides a default AOI of the entire map if unspecified,* and modifies the Openlayers coordinates for use with imageStat API@@ -530,7 +593,7 @@ function ChartingModeOptions(props) {const numPoints = STEP_NUM - (data?.body?.errors?.error_count > 0 ? data.body.errors.error_count : 0);- displayChart({+ chartData.current = {title: dataToRender.title,subtitle: dataToRender.subtitle,unit: dataToRender.unit,@@ -545,7 +608,8 @@ function ChartingModeOptions(props) {numPoints,coordinates: [...bottomLeftLatLong, ...topRightLatLong],layerId: layerInfo.id,- });+ };+ displayChart(chartData.current, screenWidth, toggleErrorDaysExpanded, isErrordaysExpanded);updateChartRequestStatus(false);} else {displaySimpleStats(dataToRender);@@ -638,40 +702,6 @@ function ChartingModeOptions(props) {}});- /**- * Update latitude longitude values on- * crop change- * @param {Object} boundaries- *- * @returns {null}- */- const onBoundaryUpdate = (boundaryObj) => {- const {- xBoundary = boundaryObj.x,- yBoundary = boundaryObj.y,- width,- height,- } = boundaryObj;- const newBoundaries = {- x: xBoundary,- y: yBoundary,- x2: xBoundary + width,- y2: yBoundary + height,- };- setBoundaries(newBoundaries);- const bottomLeft = getLatLongFromPixelValue(newBoundaries.x, newBoundaries.y2);- const topRight = getLatLongFromPixelValue(newBoundaries.x2, newBoundaries.y);- setBottomLeftLatLong(bottomLeft);- setTopRightLatLong(topRight);- debouncedUpdateAOICoordinates([...bottomLeft, ...topRight]);- setMapViewChecked(false);- if (maxExtent) {- const inLeftWing = bottomLeft[0] < maxExtent[0] && topRight[0] < maxExtent[0];- const inRightWing = bottomLeft[0] > maxExtent[2] && topRight[0] > maxExtent[2];- setIsWithinWings(inLeftWing || inRightWing);- }- };-const onLatLongChange = (coordsArray) => {const bottomLeft = [coordsArray[0], coordsArray[1]];const topRight = [coordsArray[2], coordsArray[3]];@@ -979,7 +1009,11 @@ const mapDispatchToProps = (dispatch) => ({}),);},- displayChart: (liveData) => {+ displayChart: (liveData, screenWidth, toggleErrorDaysExpanded, isErrordaysExpanded) => {+ const isWideModal = screenWidth >= 1150;+ const width = isWideModal ? 1150 : 650;+ const height = isWideModal ? 475 + (isErrordaysExpanded.current ? 35 : 0) : 855;+ const offsetTop = isWideModal ? 50 : 25;dispatch(openCustomContent('CHARTING-CHART', {headerText: (@@ -1002,14 +1036,16 @@ const mapDispatchToProps = (dispatch) => ({modalClassName: 'chart-dialog',isDraggable: true,dragHandle: '.modal-header',- offsetLeft: 'calc(50% - 575px)',- offsetTop: 50,- width: 1150,- height: 420,+ offsetLeft: `calc(50% - ${width / 2}px)`,+ offsetTop,+ width,+ height,stayOnscreen: true,+ autoSetHeight: true,type: 'selection', // This forces the user to specifically close the modalbodyComponentProps: {liveData,+ toggleErrorDaysExpanded,},}),);@@ -1034,6 +1070,9 @@ const mapDispatchToProps = (dispatch) => ({onUpdateEndDate(date) {dispatch(changeChartingEndDate(date));},+ closeModal() {+ dispatch(onClose());+ },});export default connect(@@ -1060,6 +1099,7 @@ ChartingModeOptions.propTypes = {displaySimpleStats: PropTypes.func,displayChart: PropTypes.func,openChartingErrorModal: PropTypes.func,+ closeModal: PropTypes.func,olMap: PropTypes.oneOfType([PropTypes.object, PropTypes.oneOf(['null'])]),crs: PropTypes.string,renderedPalettes: PropTypes.oneOfType([PropTypes.object, PropTypes.oneOf(['null'])]),diff --git a/web/js/containers/modal.js b/web/js/containers/modal.jsindex f49398006..4839844b1 100644--- a/web/js/containers/modal.js+++ b/web/js/containers/modal.js@@ -1,4 +1,4 @@-import React, { Component } from 'react';+import React, { useState, useEffect, useCallback } from 'react';import PropTypes from 'prop-types';import { connect } from 'react-redux';import update from 'immutability-helper';@@ -11,6 +11,7 @@ import { Resizable } from 'react-resizable';import { onToggle as onToggleAction } from '../modules/modal/actions';import ErrorBoundary from './error-boundary';import DetectOuterClick from '../components/util/detect-outer-click';+import usePrevious from '../util/customHooks';const InteractionWrap = ({condition,@@ -26,44 +27,101 @@ const toggleWithClose = (onToggle, onClose, isOpen) => {return onToggle;};-class ModalContainer extends Component {- constructor(props) {- super(props);- this.state = {- width: props.customProps.width,- height: props.customProps.height,- offsetLeft: props.customProps.offsetLeft,- offsetTop: props.customProps.offsetTop,- offsetRight: props.customProps.offsetRight,- };- this.onResize = this.onResize.bind(this);- }+function ModalContainer(props) {+ const {+ isCustom,+ id,+ isOpen,+ customProps,+ isMobile,+ screenHeight,+ screenWidth,+ isEmbedModeActive,+ isTemplateModal,+ } = props;- componentDidUpdate(prevProps) {- const {- isCustom,- id,- isOpen,- customProps,- isMobile,- screenHeight,- screenWidth,- } = this.props;- const newProps = isCustom && id ? update(this.props, { $merge: customProps }) : this.props;+ const {+ width: propsWidth,+ height: propsHeight,+ offsetLeft: propsOffsetLeft,+ offsetTop: propsOffsetTop,+ offsetRight: propsOffsetRight,+ mobileFullScreen,+ autoSetWidth,+ autoSetHeight,+ } = customProps;++ const [width, setWidth] = useState(propsWidth);+ const [height, setHeight] = useState(propsHeight);+ const [offsetLeft, setOffsetLeft] = useState(propsOffsetLeft);+ const [offsetTop, setOffsetTop] = useState(propsOffsetTop);+ const [offsetRight, setOffsetRight] = useState(propsOffsetRight);+ const [measuredElement, setMeasuredElement] = useState();+ const prevScreenHeight = usePrevious(screenHeight);+ const prevScreenWidth = usePrevious(screenWidth);+ const prevWidth = usePrevious(width);+ const prevHeight = usePrevious(height);+ const prevMeasuredElement = usePrevious(measuredElement);+ const prevMeasuredWidth = usePrevious(measuredElement?.getBoundingClientRect().width);+ const prevMeasuredHeight = usePrevious(measuredElement?.getBoundingClientRect().height);++ const handleElement = useCallback((node) => {+ if (node !== null) {+ setMeasuredElement(node);+ }+ }, []);++ const onParamChange = (e, { size }) => {+ if (e) {+ e.stopPropagation();+ }+ const elWidth = autoSetWidth && measuredElement+ ? measuredElement.getBoundingClientRect().width : size.width;+ const elHeight = autoSetHeight && measuredElement+ ? measuredElement.getBoundingClientRect().height : size.height;+ setWidth(elWidth);+ setHeight(elHeight);+ setOffsetLeft(size.offsetLeft);+ setOffsetTop(size.offsetTop);+ setOffsetRight(size.offsetRight);+ };++ const onResize = (e, { size }) => {+ if (e) {+ e.stopPropagation();+ }+ setWidth(size.width);+ setHeight(size.height);+ };++ useEffect(() => {+ const newProps = isCustom && id ? update(props, { $merge: customProps }) : props;const {onToggle,onClose,desktopOnly,} = newProps;- const screenHeightChanged = screenHeight !== prevProps.screenHeight;- const screenWidthChanged = screenWidth !== prevProps.screenWidth;+ const screenHeightChanged = screenHeight !== prevScreenHeight;+ const screenWidthChanged = screenWidth !== prevScreenWidth;+ const modalWidthChanged = propsWidth !== prevWidth;+ const modalHeightChanged = propsHeight !== prevHeight;+ const measuredElementChanged = (autoSetWidth || autoSetHeight)+ && measuredElement !== prevMeasuredElement;+ const measuredWidthChanged = autoSetWidth+ && measuredElement?.getBoundingClientRect().width !== prevMeasuredWidth;+ const measuredHeightChanged = autoSetHeight+ && measuredElement?.getBoundingClientRect().height !== prevMeasuredHeight;+ const measureChange = measuredElementChanged || measuredWidthChanged || measuredHeightChanged;const toggleFunction = toggleWithClose(onToggle, onClose, isOpen);+ if ((modalWidthChanged || modalHeightChanged || measureChange) && isOpen) {+ onParamChange(null, { size: customProps });+ }if (isMobile && isOpen) {if (desktopOnly) {toggleFunction();}- if (customProps.mobileFullScreen && (screenHeightChanged || screenWidthChanged)) {+ if (mobileFullScreen && (screenHeightChanged || screenWidthChanged)) {const isPortrait = screenHeight > screenWidth;// Values below match the request made in ol-vector-interactions@@ -72,19 +130,12 @@ class ModalContainer extends Component {height: isPortrait ? screenHeight - 106 : 300,};- this.onResize(null, { size: sizeObj });+ onResize(null, { size: sizeObj });}}- }+ });- getStyle() {- const {- isMobile, customProps,- } = this.props;- const {- offsetLeft, offsetRight, offsetTop, width, height,- } = this.state;- const { mobileFullScreen } = customProps;+ function getStyle() {const mobileTopOffset = 106;const top = isMobile && mobileFullScreen ? mobileTopOffset : offsetTop;const margin = isMobile ? 0 : '0.5rem auto';@@ -99,17 +150,8 @@ class ModalContainer extends Component {};}- onResize(e, { size }) {- if (e) {- e.stopPropagation();- }- this.setState({- width: size.width, height: size.height,- });- }-- getTemplateBody() {- const { bodyTemplate } = this.props;+ function getTemplateBody() {+ const { bodyTemplate } = props;return bodyTemplate.isLoading ? (<span> Loading </span>) : (@@ -120,17 +162,9 @@ class ModalContainer extends Component {);}- handleCreateChildren = (children) => {- const {- customProps,- id,- isCustom,- screenHeight,- screenWidth,- } = this.props;- const { width, height } = this.state;- const style = this.getStyle();- const newProps = isCustom && id ? update(this.props, { $merge: customProps }) : this.props;+ const handleCreateChildren = (children) => {+ const style = getStyle();+ const newProps = isCustom && id ? update(props, { $merge: customProps }) : props;const {dragHandle,isDraggable,@@ -159,7 +193,7 @@ class ModalContainer extends Component {minConstraints={[250, 250]}maxConstraints={[495, screenHeight]}handleSize={[8, 8]}- onResize={this.onResize}+ onResize={onResize}draggableOpts={{ disabled: !isResizable }}>{children}@@ -170,82 +204,70 @@ class ModalContainer extends Component {);};- render() {- const {- customProps,- id,- isCustom,- isEmbedModeActive,- isMobile,- isOpen,- isTemplateModal,- screenHeight,- } = this.props;- const { width, height } = this.state;-- const newProps = isCustom && id ? update(this.props, { $merge: customProps }) : this.props;- const {- autoFocus,- backdrop,- bodyComponent,- bodyComponentProps,- bodyHeader,- bodyText,- footer,- clickableBehindModal,- CompletelyCustomModal,- desktopOnly,- headerComponent,- headerText,- isDraggable,- isResizable,- mobileOnly,- modalClassName,- onClose,- onToggle,- size,- timeout,- type,- wrapClassName,- } = newProps;+ const newProps = isCustom && id ? update(props, { $merge: customProps }) : props;+ const {+ autoFocus,+ backdrop,+ bodyComponent,+ bodyComponentProps,+ bodyHeader,+ bodyText,+ footer,+ clickableBehindModal,+ CompletelyCustomModal,+ desktopOnly,+ headerComponent,+ headerText,+ isDraggable,+ isResizable,+ mobileOnly,+ modalClassName,+ onClose,+ onToggle,+ size,+ timeout,+ type,+ wrapClassName,+ } = newProps;- const isRestrictedDisplay = (isMobile && desktopOnly)- || (!isMobile && mobileOnly)- || (isEmbedModeActive && size === 'lg' && !id.includes('LAYER_INFO_MODAL'));- if (isRestrictedDisplay) {- return null;- }- const style = this.getStyle();- const lowerCaseId = lodashToLower(id);- const BodyComponent = bodyComponent || '';- const allowOuterClick = !isOpen || type === 'selection' || clickableBehindModal;- const modalWrapClass = clickableBehindModal ? `clickable-behind-modal ${wrapClassName}` : wrapClassName;- const toggleFunction = toggleWithClose(onToggle, onClose, isOpen);- const closeBtn = (- <button className="modal-close-btn" onClick={toggleFunction} type="button">- ×- </button>- );+ const isRestrictedDisplay = (isMobile && desktopOnly)+ || (!isMobile && mobileOnly)+ || (isEmbedModeActive && size === 'lg' && !id.includes('LAYER_INFO_MODAL'));+ if (isRestrictedDisplay) {+ return null;+ }+ const style = getStyle();+ const lowerCaseId = lodashToLower(id);+ const BodyComponent = bodyComponent || '';+ const allowOuterClick = !isOpen || type === 'selection' || clickableBehindModal;+ const modalWrapClass = clickableBehindModal ? `clickable-behind-modal ${wrapClassName}` : wrapClassName;+ const toggleFunction = toggleWithClose(onToggle, onClose, isOpen);+ const closeBtn = (+ <button className="modal-close-btn" onClick={toggleFunction} type="button">+ ×+ </button>+ );- return (- <ErrorBoundary>- <InteractionWrap- condition={isDraggable || isResizable}- wrapper={this.handleCreateChildren}+ return (+ <ErrorBoundary>+ <InteractionWrap+ condition={isDraggable || isResizable}+ wrapper={handleCreateChildren}+ >+ <Modal+ isOpen={isOpen}+ toggle={toggleFunction}+ backdrop={backdrop}+ id={lowerCaseId}+ size={size}+ className={isTemplateModal ? 'template-modal' : modalClassName || 'default-modal'}+ autoFocus={autoFocus || false}+ style={style}+ wrapClassName={`${modalWrapClass} ${lowerCaseId}`}+ modalTransition={{ timeout: isDraggable ? 0 : timeout || 100 }}+ fade={!isDraggable}>- <Modal- isOpen={isOpen}- toggle={toggleFunction}- backdrop={backdrop}- id={lowerCaseId}- size={size}- className={isTemplateModal ? 'template-modal' : modalClassName || 'default-modal'}- autoFocus={autoFocus || false}- style={style}- wrapClassName={`${modalWrapClass} ${lowerCaseId}`}- modalTransition={{ timeout: isDraggable ? 0 : timeout || 100 }}- fade={!isDraggable}- >+ <div ref={handleElement}>{CompletelyCustomModal? (<CompletelyCustomModal@@ -278,16 +300,16 @@ class ModalContainer extends Component {closeModal={toggleFunction}/>)- : isTemplateModal ? this.getTemplateBody() : (<p>{bodyText}</p>) || ''}+ : isTemplateModal ? getTemplateBody() : (<p>{bodyText}</p>) || ''}</ModalBody>{footer && (<ModalFooter />)}</DetectOuterClick>)}- </Modal>- </InteractionWrap>- </ErrorBoundary>- );- }+ </div>+ </Modal>+ </InteractionWrap>+ </ErrorBoundary>+ );}function mapStateToProps(state) {diff --git a/web/scss/features/sidebar.scss b/web/scss/features/sidebar.scssindex 4d5e6db57..9af5ba280 100644--- a/web/scss/features/sidebar.scss+++ b/web/scss/features/sidebar.scss@@ -672,7 +672,7 @@ div#group-overlays-checkbox-case {.charting-chart-text {display: inline-block;vertical-align: top;- width: 55%;+ width: 600px;}.charting-chart-container .charting-disclaimer {@@ -867,6 +867,7 @@ div#group-overlays-checkbox-case {margin: 0 !important;.modal-header {+ max-height: 5vh;cursor: move;.charting-chart-subheader {@@ -876,6 +877,42 @@ div#group-overlays-checkbox-case {color: #c7c7c7;}}++ .modal-body {+ max-height: 89.5vh;+ overflow-y: auto;+ }+}++@media (max-width: 1149px) {+ #charting-chart {+ max-width: 650px;++ .charting-chart-inner {+ display:flex;+ flex-flow: column;++ .charting-chart-text {+ order: 1;+ }++ .charting-stat-text {+ order: 3;+ width: 600px;++ #charting-minimap-container {+ width: 61%;+ margin-right: 0;+ }+ }++ .charting-disclaimer {+ order: 2;+ width: 600px;+ margin-top: 0;+ }+ }+ }}button#charting-simple-stats-button {@@ -898,7 +935,7 @@ button#charting-simple-stats-button {.charting-stat-text {display: inline-block;- width: 45%;+ width: 512px;}.charting-stat-text > div {