Interactive interface for browsing global, full-resolution satellite imagery
WV-3589: Charting Mode Cancel Request Button (#6419)
christof-wittreich582cde0ee9d6
diff --git a/web/js/components/sidebar/charting-mode-options.js b/web/js/components/sidebar/charting-mode-options.jsindex 509b942ec..20cb2b5e7 100644--- a/web/js/components/sidebar/charting-mode-options.js+++ b/web/js/components/sidebar/charting-mode-options.js@@ -34,6 +34,7 @@ import ChartingDateSelector from '../charting/charting-date-selector';import ChartComponent from '../charting/chart-component';import LatLongSelect from '../image-download/lat-long-inputs';import Checkbox from '../util/checkbox';+import WaitOverlay from '../util/wait';const AOIFeatureObj = {};const vectorLayers = {};@@ -91,6 +92,7 @@ function ChartingModeOptions(props) {const isMounted = useRef(false);const chartData = useRef({});const isErrordaysExpanded = useRef(false);+ const cancelChartRef = useRef(false);const [isPostRender, setIsPostRender] = useState(false);const [doRenderChart, setDoRenderChart] = useState(false);const [mapViewChecked, setMapViewChecked] = useState(false);@@ -300,6 +302,12 @@ function ChartingModeOptions(props) {displayChart(chartData.current, screenWidth, toggleErrorDaysExpanded, isErrordaysExpanded);}, [screenWidth]);+ function onCancelChart() {+ updateModalOpen(false);+ updateChartRequestStatus(false);+ cancelChartRef.current = true;+ }+/*** Provides a default AOI of the entire map if unspecified,* and modifies the Openlayers coordinates for use with imageStat API@@ -370,6 +378,11 @@ function ChartingModeOptions(props) {try {const response = await fetch(simpleStatsURI, requestOptions);const data = await response.text();++ await new Promise((r) => {+ setTimeout(r, 5000);+ }); // Mock loading time+// This is the response when the imageStat server failsif (!data || data === 'null') {return {@@ -520,6 +533,7 @@ function ChartingModeOptions(props) {async function onRequestChartClick() {if (chartRequestInProgress) return;updateChartRequestStatus(true);+ cancelChartRef.current = false;const layerInfo = getActiveChartingLayer();if (layerInfo == null) {updateChartRequestStatus(false);@@ -561,6 +575,10 @@ function ChartingModeOptions(props) {const dataArr = await Promise.all(promises);const data = combineData(dataArr);+ if (cancelChartRef.current) {+ return;+ }+if (!isMounted.current) {updateChartRequestStatus(false);return;@@ -855,6 +873,12 @@ function ChartingModeOptions(props) {text={requestBtnText}/></div>+ {chartRequestInProgress && (+ <WaitOverlay+ statusText="Creating chart..."+ onCancel={() => onCancelChart()}+ />+ )}{aoiActive && isPostRender && (<Cropx={x}@@ -870,11 +894,13 @@ function ChartingModeOptions(props) {left: x,top: y2 + 5,width: x2 - x,+ zIndex: 2,}}topRightStyle={{left: x,top: y - 20,width: x2 - x,+ zIndex: 2,}}coordinates={{bottomLeft: util.formatCoordinate(bottomLeftLatLong),diff --git a/web/js/components/util/wait.js b/web/js/components/util/wait.jsnew file mode 100644index 000000000..bc229e957--- /dev/null+++ b/web/js/components/util/wait.js@@ -0,0 +1,51 @@+import React from 'react';+import { createPortal } from 'react-dom';+import PropTypes from 'prop-types';+import Button from './button';++/*+ * @class Wait+ * @extends React.Component+ */+export default function Wait(props) {+ const {+ complete, statusText, onCancel,+ } = props;++ const root = document.querySelector('.wv-content') || document.body;++ return createPortal(+ <div className="wv-wait-progress-overlay">+ <dialog className="wv-wait-progress-dialog" open>+ <div className="wv-wait-progress">+ <div className="wv-wait-progress-message">+ <span>{statusText}</span>+ </div>+ <div className="wv-wait-progress-actions">+ {!complete && (+ <Button+ autoFocus+ text="Cancel"+ onClick={onCancel}+ className="wv-button gray"+ id="wv-wait-cancel-button"+ />+ )}+ </div>+ </div>+ </dialog>+ </div>,+ root,+ );+}++Wait.defaultProps = {+ complete: false,+ statusText: '',+ onCancel: null,+};+Wait.propTypes = {+ complete: PropTypes.bool,+ statusText: PropTypes.string,+ onCancel: PropTypes.func,+};diff --git a/web/scss/components/wait.scss b/web/scss/components/wait.scssnew file mode 100644index 000000000..ca52360b4--- /dev/null+++ b/web/scss/components/wait.scss@@ -0,0 +1,75 @@+/*+ * WV Wait Widget+ */++.wv-wait-progress {+ display: flex;+ align-items: center;+ justify-content: space-between;+ padding: 10px;+ margin: 10px 0;+ background-color: #222;+ color: white;+ border: none;+ flex-direction: column;+ border-radius: 6px;+ opacity: 1;+}++.wv-wait-progress-message {+ display: flex;+ align-items: center;+ font-weight: 500;+ color: white;+}++.wv-wait-progress-message::before {+ content: '';+ display: inline-block;+ width: 16px;+ height: 16px;+ margin-right: 10px;+ border: 2px solid white;+ border-top: 2px solid transparent;+ border-radius: 50%;+ animation: wv-wait-spin 1s linear infinite;+}++.wv-wait-progress-actions {+ flex-shrink: 0;+ padding: 1rem;+}++@keyframes wv-wait-spin {+ 0% { transform: rotate(0deg); }+ 100% { transform: rotate(360deg); }+}++.wv-wait-progress-dialog {+ position: absolute;+ background-color: #222;+ color: white;+ left: 0;+ top: 40%;+ z-index: 9999999999;+ box-sizing: unset;+ opacity: 1;+ border: 1px solid #555;+ border-radius: 6px;++ button {+ cursor: pointer;+ }+}++.wv-wait-progress-overlay {+ position: absolute;+ top: 0;+ left: 0;+ background-color: rgb(0 0 0 / 95%);+ opacity: 1;+ cursor: wait;+ width: 100%;+ height: 100%;+ z-index: 2;+}diff --git a/web/scss/index.scss b/web/scss/index.scssindex 244b8fa87..501330d83 100644--- a/web/scss/index.scss+++ b/web/scss/index.scss@@ -18,6 +18,7 @@@use 'components/switch';@use 'components/tooltip';@use 'components/range';+@use 'components/wait';/* Features */@use 'features/about';