Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

React v19 bug fixes

ZachTRice4b8d14ad0b99
diff --git a/config/default/common/config/wv.json/stories/default/worldview_intro.json b/config/default/common/config/wv.json/stories/default/worldview_intro.json
index fd0345ea8..8b79d7038 100644
--- a/config/default/common/config/wv.json/stories/default/worldview_intro.json
+++ b/config/default/common/config/wv.json/stories/default/worldview_intro.json
@@ -21,7 +21,7 @@
{
"id": "001",
"description": "step001.html",
- "stepLink": "v=-108.00920361862684,-63.57842410029712,116.2759949373298,68.07713930391033",
+ "stepLink": "v=-108.00920361862684,-63.57842410029712,116.2759949373298,68.07713930391033&lg=true",
"joyride": {
"continuous": true,
"spotlightClicks": true,
@@ -148,4 +148,4 @@
]
}
}
-}
\ No newline at end of file
+}
diff --git a/web/js/components/layer/product-picker/search/search-layer-row.js b/web/js/components/layer/product-picker/search/search-layer-row.js
index 884a3306f..2a98d7e57 100644
--- a/web/js/components/layer/product-picker/search/search-layer-row.js
+++ b/web/js/components/layer/product-picker/search/search-layer-row.js
@@ -139,12 +139,24 @@ class SearchLayerRow extends React.Component {
onChange={this.toggleEnabled}
/>
{isEnabled && (
- <FontAwesomeIcon
- icon="check-circle"
+ <svg
+ stroke="currentColor"
+ fill="currentColor"
+ xmlns="http://www.w3.org/2000/svg"
+ strokeWidth="0"
+ width="15px"
+ height="15px"
+ viewBox="0 0 20 20"
+ role="img"
className="check"
- style={{ fontSize: '15px' }}
- widthAuto
- />
+ >
+ <path
+ fill="currentColor"
+ fillRule="evenodd"
+ d="M17.707 5.707 8 15.414 2.293 9.707l1.414-1.414L8 12.586l8.293-8.293z"
+ clipRule="evenodd"
+ />
+ </svg>
)}
</div>
{(chartableLayer || layerNotices) && (
diff --git a/web/js/components/tour/joyride-wrapper.js b/web/js/components/tour/joyride-wrapper.js
index 76b84446a..782d2bb9c 100644
--- a/web/js/components/tour/joyride-wrapper.js
+++ b/web/js/components/tour/joyride-wrapper.js
@@ -1,6 +1,12 @@
import { useEffect, useState } from 'react';
+import { createPortal } from 'react-dom';
import PropTypes from 'prop-types';
-import Joyride, { STATUS, ACTIONS, EVENTS } from 'react-joyride';
+import Joyride, {
+ STATUS,
+ ACTIONS,
+ EVENTS,
+ LIFECYCLE,
+} from 'react-joyride';
import util from '../../util/util';
import { JOYRIDE_INCREMENT } from '../../util/constants';
@@ -33,7 +39,14 @@ export default function JoyrideWrapper ({
lineHeight: '16px',
textColor: '#333',
width: undefined,
- zIndex: 1050,
+ // Keep Joyride above Bootstrap modals so the tour modal stays dimmed during tooltip steps.
+ zIndex: 2000,
+ },
+ overlay: {
+ transition: 'none',
+ },
+ spotlight: {
+ transition: 'none',
},
};
@@ -48,16 +61,32 @@ export default function JoyrideWrapper ({
eventTriggersIncrement,
} = (currentStepObj || {}).joyride || {};
- const [elementPositionKey, setElementPositionKey] = useState(key);
+ const hasTargetCoordinates = !!(steps || []).find((s) => s?.targetCoordinates);
+
+ const [, setElementPositionKey] = useState(key);
const [stepIndex, setStepIndex] = useState();
const [run, setRun] = useState(false);
const [isInitializing, setIsInitializing] = useState(true);
+ const [hasJoyrideOverlay, setHasJoyrideOverlay] = useState(false);
+ const [overlayStarted, setOverlayStarted] = useState(false);
const incrementKey = () => {
key += 1;
setElementPositionKey(key);
};
+ function updatePlaceholderLocations() {
+ (steps || []).forEach((step) => {
+ const { target, targetCoordinates } = step || {};
+ if (target && targetCoordinates) {
+ const placeholderEl = document.querySelector(target);
+ if (placeholderEl) {
+ setPlaceholderLocation(placeholderEl, targetCoordinates);
+ }
+ }
+ });
+ }
+
const currentJoyrideStep = steps && steps[stepIndex];
if (currentJoyrideStep) {
@@ -75,7 +104,7 @@ export default function JoyrideWrapper ({
return () => {
events.off(JOYRIDE_INCREMENT, incrementStep);
};
- });
+ }, [run, eventTriggersIncrement, stepIndex]);
// For the tutorial tour, we need to reset the product picker to initial state
useEffect(() => {
@@ -139,13 +168,8 @@ export default function JoyrideWrapper ({
) {
return;
}
- (steps || []).forEach((step) => {
- const { target, targetCoordinates } = step || {};
- if (target && targetCoordinates) {
- const placeholderEl = document.querySelector(target);
- setPlaceholderLocation(placeholderEl, targetCoordinates);
- }
- });
+ if (!hasTargetCoordinates) return;
+ updatePlaceholderLocations();
setIsInitializing(false);
// Force a re-render so that Joyride updates the beacon location,
// otherwise it doesn't know the DOM element position was updated
@@ -158,16 +182,25 @@ export default function JoyrideWrapper ({
action, index, type, status,
} = data;
+ if (data.lifecycle === LIFECYCLE.TOOLTIP) setOverlayStarted(true);
+
if ([EVENTS.STEP_AFTER, EVENTS.TARGET_NOT_FOUND].includes(type)) {
const newIndex = index + (action === ACTIONS.PREV ? -1 : 1);
setStepIndex(newIndex);
- if (newIndex >= 0 && newIndex < steps.length && steps[newIndex].targetCoordinates) {
- updateTargetsOnResize();
+ if (
+ hasTargetCoordinates &&
+ newIndex >= 0 &&
+ newIndex < steps.length &&
+ steps[newIndex].targetCoordinates
+ ) {
+ // Let Joyride update its internal state first, then reposition placeholders.
+ requestAnimationFrame(() => updateTargetsOnResize());
}
}
if ([STATUS.FINISHED, STATUS.SKIPPED].includes(status)) {
setStepIndex(0);
setRun(false);
+ setOverlayStarted(false);
}
};
@@ -190,16 +223,16 @@ export default function JoyrideWrapper ({
// Handle effects related to changing the tour step
useEffect(() => {
addPlaceholderElements();
- map.getView().changed();
- incrementKey();
- setRun(false);
- setStepIndex(undefined);
- setTimeout(() => {
- if (steps && steps.length) {
- setStepIndex(0);
- setRun(true);
- }
- });
+ updatePlaceholderLocations();
+ setIsInitializing(false);
+ setOverlayStarted(false);
+ if (steps && steps.length) {
+ setStepIndex(0);
+ setRun(true);
+ } else {
+ setStepIndex(undefined);
+ setRun(false);
+ }
}, [currentTourStep]);
// Force re-render on projection change to reset Joyride
@@ -207,9 +240,35 @@ export default function JoyrideWrapper ({
// Register/de-register evnt listeners for map changes
useEffect(() => {
+ if (!hasTargetCoordinates) return undefined;
map.getView().on('change', updateTargetsOnResize);
return () => map.getView().un('change', updateTargetsOnResize);
- });
+ }, [map, hasTargetCoordinates]);
+
+ // Joyride's overlay can briefly unmount between steps; keep a fallback overlay
+ // visible during those gaps to prevent a distracting flash.
+ useEffect(() => {
+ if (!run || !projMatches || isInitializing) {
+ setHasJoyrideOverlay(false);
+ setOverlayStarted(false);
+ return undefined;
+ }
+
+ const getOverlayPresent = () => !!document.querySelector('.react-joyride__overlay');
+ const updateOverlayState = () => setHasJoyrideOverlay(getOverlayPresent());
+
+ updateOverlayState();
+
+ const observer = new MutationObserver(updateOverlayState);
+ observer.observe(document.body, {
+ subtree: true,
+ childList: true,
+ attributes: true,
+ attributeFilter: ['class', 'style'],
+ });
+
+ return () => observer.disconnect();
+ }, [run, projMatches, isInitializing]);
// When tour is complete, remove all placeholder elements
useEffect(() => {
@@ -221,20 +280,31 @@ export default function JoyrideWrapper ({
return !projMatches || isInitializing
? null
: (
- <Joyride
- run={run}
- stepIndex={stepIndex}
- key={elementPositionKey}
- steps={steps || []}
- continuous={checkContinuous()}
- callback={joyrideStateCallback}
- spotlightClicks={spotlightClicks}
- disableOverlayClose={disableOverlayClose}
- hideCloseButton={hideCloseButton}
- styles={styles}
- disableScrolling
- disableScrollParentFix
- />
+ <>
+ {run && overlayStarted && !hasJoyrideOverlay && typeof document !== 'undefined' && (
+ createPortal(
+ <div className="react-joyride__overlay-fallback" />,
+ document.body,
+ )
+ )}
+ <Joyride
+ run={run}
+ stepIndex={stepIndex}
+ steps={steps || []}
+ continuous={checkContinuous()}
+ callback={joyrideStateCallback}
+ spotlightClicks={spotlightClicks}
+ disableOverlay={!overlayStarted}
+ disableOverlayClose={disableOverlayClose}
+ hideCloseButton={hideCloseButton}
+ styles={styles}
+ floaterProps={{
+ disableAnimation: true,
+ }}
+ disableScrolling
+ disableScrollParentFix
+ />
+ </>
);
}
diff --git a/web/js/components/util/image-crop.js b/web/js/components/util/image-crop.js
index 4fcb447b1..73a07b9e6 100644
--- a/web/js/components/util/image-crop.js
+++ b/web/js/components/util/image-crop.js
@@ -7,6 +7,9 @@ import { pick, some } from 'lodash';
// https://stackoverflow.com/a/13139830
const TRANSPARENT_GIF = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
+const DEFAULT_MAX_HEIGHT = typeof window === 'undefined' ? 0 : window.innerWidth;
+const DEFAULT_MAX_WIDTH = typeof window === 'undefined' ? 0 : window.innerHeight;
+
function RenderCoordinates(props) {
const { coordinates, topRightStyle, bottomLeftStyle } = props;
if (bottomLeftStyle.width < 50) {
@@ -32,25 +35,23 @@ function RenderCoordinates(props) {
);
}
-function Crop(props) {
- const {
- onClose,
- onChange,
- onDragStop,
- maxWidth,
- maxHeight,
- showCoordinates,
- keepSelection,
- zIndex,
- coordinates,
- topRightStyle,
- bottomLeftStyle,
- x,
- y,
- width,
- height,
- } = props;
-
+function Crop({
+ onClose = () => {},
+ onChange,
+ onDragStop = () => {},
+ maxWidth = DEFAULT_MAX_WIDTH,
+ maxHeight = DEFAULT_MAX_HEIGHT,
+ showCoordinates = false,
+ keepSelection = false,
+ zIndex = 3,
+ coordinates,
+ topRightStyle,
+ bottomLeftStyle,
+ x = 20,
+ y = 10,
+ width = 30,
+ height = 10,
+}) {
const [crop, setCrop] = useState({
x,
y,
@@ -122,18 +123,6 @@ function Crop(props) {
}
export default Crop;
-Crop.defaultProps = {
- height: 10,
- maxHeight: window.innerWidth,
- maxWidth: window.innerHeight,
- onDragStop: () => {},
- keepSelection: false,
- width: 30,
- x: 20,
- y: 10,
- zIndex: 3,
-};
-
RenderCoordinates.propTypes = {
coordinates: PropTypes.oneOfType([PropTypes.object, PropTypes.oneOf(['null'])]),
topRightStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.oneOf(['null'])]),
diff --git a/web/js/containers/tour.js b/web/js/containers/tour.js
index 04d316ba4..a516f0d31 100644
--- a/web/js/containers/tour.js
+++ b/web/js/containers/tour.js
@@ -39,6 +39,7 @@ import {
} from '../modules/tour/actions';
import { resetProductPickerState as resetProductPickerStateAction } from '../modules/product-picker/actions';
import { changeTab as changeTabAction } from '../modules/sidebar/actions';
+import { toggleOverlayGroups as toggleOverlayGroupsAction } from '../modules/layers/actions';
import ErrorBoundary from './error-boundary';
import history from '../main';
import util from '../util/util';
@@ -101,9 +102,15 @@ class Tour extends React.Component {
this.hideTour = this.hideTour.bind(this);
this.selectTour = this.selectTour.bind(this);
this.resetTour = this.resetTour.bind(this);
+
+ this.groupOverlaysBeforeTour = null;
}
componentDidMount() {
+ if (this.props.isActive && this.groupOverlaysBeforeTour === null) {
+ this.groupOverlaysBeforeTour = safeLocalStorage.getItem(safeLocalStorage.keys.GROUP_OVERLAYS) !== 'disabled';
+ }
+
const {
currentStory, currentStoryIndex, currentStoryId, modalStart, modalInProgress, modalComplete,
} = this.state;
@@ -117,6 +124,37 @@ class Tour extends React.Component {
}
}
+ componentDidUpdate(prevProps) {
+ const { isActive } = this.props;
+
+ if (!prevProps.isActive && isActive) {
+ // Snapshot the user's preference at tour start so we can restore it later.
+ // Use local storage so deep-linked tours (with `lg=true`) still restore correctly.
+ this.groupOverlaysBeforeTour = safeLocalStorage.getItem(safeLocalStorage.keys.GROUP_OVERLAYS) !== 'disabled';
+ }
+
+ if (prevProps.isActive && !isActive) {
+ this.restoreGroupOverlaysPreference();
+ }
+ }
+
+ componentWillUnmount() {
+ if (this.props.isActive) {
+ this.restoreGroupOverlaysPreference();
+ }
+ }
+
+ restoreGroupOverlaysPreference() {
+ const { groupOverlays, toggleOverlayGroups } = this.props;
+ const previousPreference = this.groupOverlaysBeforeTour;
+ this.groupOverlaysBeforeTour = null;
+
+ if (previousPreference === null || previousPreference === undefined) return;
+ if (previousPreference !== groupOverlays) {
+ toggleOverlayGroups();
+ }
+ }
+
hideTour() {
const shouldHideTour = safeLocalStorage.getItem(HIDE_TOUR);
googleTagManager.pushEvent({
@@ -596,6 +634,9 @@ const mapDispatchToProps = (dispatch) => ({
changeTab: (str) => {
dispatch(changeTabAction(str));
},
+ toggleOverlayGroups: () => {
+ dispatch(toggleOverlayGroupsAction());
+ },
});
const mapStateToProps = (state) => {
@@ -620,6 +661,7 @@ const mapStateToProps = (state) => {
screenHeight,
renderedPalettes: palettes.rendered,
activeTab: sidebar.activeTab,
+ groupOverlays: state.layers?.[compare.activeString]?.groupOverlays,
promiseImageryForTour: (
layers,
dateString,
@@ -653,4 +695,6 @@ Tour.propTypes = {
resetProductPicker: PropTypes.func,
screenHeight: PropTypes.number,
startTour: PropTypes.func,
+ groupOverlays: PropTypes.bool,
+ toggleOverlayGroups: PropTypes.func,
};
diff --git a/web/js/font-awesome-library.js b/web/js/font-awesome-library.js
index e06c2e62a..13f938dda 100644
--- a/web/js/font-awesome-library.js
+++ b/web/js/font-awesome-library.js
@@ -30,6 +30,7 @@ import {
faCaretRight,
faCaretLeft,
faCaretUp,
+ faCheck,
faCheckCircle,
faChevronCircleDown,
faChevronCircleRight,
@@ -100,6 +101,7 @@ library.add(
faCaretLeft,
faCaretRight,
faCaretUp,
+ faCheck,
faCheckCircle,
faChevronCircleDown,
faChevronCircleRight,
diff --git a/web/js/modules/vector-styles/util.js b/web/js/modules/vector-styles/util.js
index 10c3d43bf..9944d51bd 100644
--- a/web/js/modules/vector-styles/util.js
+++ b/web/js/modules/vector-styles/util.js
@@ -248,14 +248,21 @@ function getModalContentsAtPixel(mapProps, config, compareState, isMobile) {
if (!selected[layerId]) selected[layerId] = [];
const features = feature.getProperties();
const vectorDataId = def.vectorData.id;
- const data = config.vectorData[vectorDataId];
- const properties = data.mvt_properties;
- const uniqueIdentifierKey = lodashFind(properties, { Function: 'Identify' }).Identifier;
+ const data = lodashGet(config, ['vectorData', vectorDataId]);
+ const properties = Array.isArray(data?.mvt_properties) ? data.mvt_properties : [];
+
+ const identifyProp = lodashFind(properties, { Function: 'Identify' }) || lodashFind(properties, { function: 'Identify' });
+ const uniqueIdentifierKey = identifyProp?.Identifier;
+
const titleObj = lodashFind(properties, 'IsLabel');
- const titleKey = titleObj.Identifier;
+ const titleKey = titleObj?.Identifier;
+
+ const featureId = feature.getId();
+ const uniqueIdentifierRaw = uniqueIdentifierKey ? features?.[uniqueIdentifierKey] : featureId;
+ const uniqueIdentifier = uniqueIdentifierRaw == null ? `${layerId}:${metaArray.length}` : String(uniqueIdentifierRaw);
- const uniqueIdentifier = features[uniqueIdentifierKey];
- const title = titleKey ? features[titleKey] : 'Unknown title';
+ const titleRaw = titleKey ? features?.[titleKey] : null;
+ const title = titleRaw == null ? (def.title || 'Unknown title') : String(titleRaw);
if (selected[layerId].includes(uniqueIdentifier)) return true;
if (def.modalShouldFollowClicks) modalShouldFollowClicks = true;
const obj = {
diff --git a/web/scss/features/timeline.scss b/web/scss/features/timeline.scss
index b80d88f85..4d766b15c 100644
--- a/web/scss/features/timeline.scss
+++ b/web/scss/features/timeline.scss
@@ -820,6 +820,7 @@ button:focus {
user-select: none;
box-sizing: content-box;
-webkit-font-smoothing: antialiased;
+ font-size: 15px;
}
.datepicker-modal .datepicker-header {
diff --git a/web/scss/overrides/react-joyride.scss b/web/scss/overrides/react-joyride.scss
index 7f911dc5f..d01b61f1c 100644
--- a/web/scss/overrides/react-joyride.scss
+++ b/web/scss/overrides/react-joyride.scss
@@ -1,6 +1,26 @@
.react-joyride__beacon span:first-of-type {
box-shadow: 0 0 24px 24px rgba(0, 0, 0, 0.3);
}
+
+// React Joyride sometimes animates/toggles overlay opacity between steps.
+// Pin the overlay rendering to avoid a visible flash.
+.react-joyride__overlay {
+ animation: none !important;
+ opacity: 1 !important;
+ transition: none !important;
+}
+
+.react-joyride__overlay-fallback {
+ background: rgba(0, 0, 0, 0.5);
+ height: 100vh;
+ left: 0;
+ position: fixed;
+ top: 0;
+ width: 100vw;
+ // Match Joyride's `styles.options.zIndex`.
+ z-index: 2000;
+}
+
.react-joyride__tooltip div {
line-height: 16px;
max-width: 360px;