Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

New image export approach (#1199)

Giuseppe Macrì7eace482ca55
diff --git a/src/actions/ui-state-actions.d.ts b/src/actions/ui-state-actions.d.ts
index c3ae8e02a..ee21bc7e4 100644
--- a/src/actions/ui-state-actions.d.ts
+++ b/src/actions/ui-state-actions.d.ts
@@ -91,16 +91,27 @@ export function removeNotification(
/** SET_EXPORT_IMAGE_SETTING */
export type SetExportImageSettingUpdaterAction = {
- payload: {ratio?: string; resolution?: string; legend?: string};
+ payload: {
+ ratio?: string;
+ resolution?: string;
+ legend?: string;
+ center?: boolean;
+ exporting?: boolean;
+ processing?: boolean;
+ };
};
-export function setExportImageSetting(newSetting: {
+export function setExportImageSetting(newSetting:
+ SetExportImageSettingUpdaterAction['payload']
+): Merge<SetExportImageSettingUpdaterAction, {type: ActionTypes.SET_EXPORT_IMAGE_SETTING}>;
+
+/** START_EXPORTING_IMAGE */
+export function startExportingImage(options?: {
ratio?: string;
resolution?: string;
- legend?: string;
-}): Merge<SetExportImageSettingUpdaterAction, {type: ActionTypes.SET_EXPORT_IMAGE_SETTING}>;
+ legend?: string,
+ center?: boolean
+}): Merge<SetExportImageSettingUpdaterAction, {type: ActionTypes.START_EXPORT_IMAGE}>;
-/** START_EXPORTING_IMAGE */
-export function startExportingImage(): {type: ActionTypes.START_EXPORTING_IMAGE};
/** SET_EXPORT_IMAGE_DATA_URI */
export type SetExportImageDataUriUpdaterAction = {
@@ -174,6 +185,14 @@ export function setExportHTMLMapMode(
mode: string
): Merge<SetExportHTMLMapModeUpdaterAction, {type: ActionTypes.SET_EXPORT_MAP_HTML_MODE}>;
+/** START_SAVE_STORAGE */
+export type StartSaveStorageUpdaterAction = {
+ payload: boolean;
+}
+export function startSaveStorage(
+ mapSaved: string
+): Merge<StartSaveStorageUpdaterAction, {type: ActionTypes.START_SAVE_STORAGE}>
+
/** SET_LOCALE */
export type SetLocaleUpdaterAction = {
payload: {locale: string};
diff --git a/src/actions/ui-state-actions.js b/src/actions/ui-state-actions.js
index 5eef1fdb2..cc4a3de43 100644
--- a/src/actions/ui-state-actions.js
+++ b/src/actions/ui-state-actions.js
@@ -117,7 +117,7 @@ export const setExportImageSetting = createAction(
);
/**
- * Set `exportImage.exporting` to true
+ * Start exporting image flow
* @memberof uiStateActions
* @type {typeof import('./ui-state-actions').startExportingImage}
* @public
@@ -152,6 +152,13 @@ export const setExportImageError = createAction(ActionTypes.SET_EXPORT_IMAGE_ERR
*/
export const cleanupExportImage = createAction(ActionTypes.CLEANUP_EXPORT_IMAGE);
+/**
+ * Start saving storage flow
+ * @memberof uiStateActions
+ * @type {typeof import('./ui-state-actions').startSaveStorage}
+ */
+export const startSaveStorage = createAction(ActionTypes.START_SAVE_STORAGE);
+
/**
* Set selected dataset for export
* @memberof uiStateActions
diff --git a/src/components/common/image-preview.js b/src/components/common/image-preview.js
index 1745aa1a5..d02c7f03f 100644
--- a/src/components/common/image-preview.js
+++ b/src/components/common/image-preview.js
@@ -76,7 +76,7 @@ const StyledImagePreview = styled.div.attrs({
* @param {boolean} [props.showDimension]
*/
const ImagePreview = ({exportImage, width = 400, showDimension = false}) => {
- const {error, imageDataUri, exporting, imageSize: {imageW = 0, imageH = 0} = {}} =
+ const {error, imageDataUri, processing, imageSize: {imageW = 0, imageH = 0} = {}} =
exportImage || {};
const imageStyle = {
@@ -92,7 +92,7 @@ const ImagePreview = ({exportImage, width = 400, showDimension = false}) => {
</div>
) : null}
<div className="preview-image" style={imageStyle}>
- {exporting ? (
+ {processing ? (
<div className="preview-image-spinner">
<LoadingSpinner />
</div>
diff --git a/src/components/kepler-gl.js b/src/components/kepler-gl.js
index 2c3d777ab..01d42e14b 100644
--- a/src/components/kepler-gl.js
+++ b/src/components/kepler-gl.js
@@ -35,15 +35,11 @@ import * as UIStateActions from 'actions/ui-state-actions';
import * as ProviderActions from 'actions/provider-actions';
import {
- EXPORT_IMAGE_ID,
DIMENSIONS,
KEPLER_GL_NAME,
KEPLER_GL_VERSION,
THEME,
- DEFAULT_MAPBOX_API_URL,
- SAVE_MAP_ID,
- SHARE_MAP_ID,
- OVERWRITE_MAP_ID
+ DEFAULT_MAPBOX_API_URL
} from 'constants/default-settings';
import {MISSING_MAPBOX_TOKEN} from 'constants/user-feedbacks';
@@ -334,11 +330,7 @@ function KeplerGlFactory(
/>
));
- const isExporting =
- uiState.currentModal === EXPORT_IMAGE_ID ||
- uiState.currentModal === SAVE_MAP_ID ||
- uiState.currentModal === SHARE_MAP_ID ||
- uiState.currentModal === OVERWRITE_MAP_ID;
+ const isExportingImage = uiState.exportImage.exporting;
const theme = this.availableThemeSelector(this.props);
@@ -358,16 +350,17 @@ function KeplerGlFactory(
<div className="maps" style={{display: 'flex'}}>
{mapContainers}
</div>
- {isExporting && (
+ {isExportingImage && (
<PlotContainer
width={width}
height={height}
exportImageSetting={uiState.exportImage}
mapFields={mapFields}
addNotification={uiStateActions.addNotification}
- startExportingImage={uiStateActions.startExportingImage}
+ setExportImageSetting={uiStateActions.setExportImageSetting}
setExportImageDataUri={uiStateActions.setExportImageDataUri}
setExportImageError={uiStateActions.setExportImageError}
+ splitMaps={splitMaps}
/>
)}
{!uiState.readOnly && interactionConfig.geocoder.enabled && (
diff --git a/src/components/modal-container.js b/src/components/modal-container.js
index ef934805d..1217bfd2d 100644
--- a/src/components/modal-container.js
+++ b/src/components/modal-container.js
@@ -179,7 +179,7 @@ export default function ModalContainerFactory(
};
_onExportImage = () => {
- if (!this.props.uiState.exportImage.exporting) {
+ if (!this.props.uiState.exportImage.processing) {
exportImage(this.props);
this.props.uiStateActions.cleanupExportImage();
this._closeModal();
@@ -356,7 +356,7 @@ export default function ModalContainerFactory(
exportImage={uiState.exportImage}
mapW={containerW}
mapH={containerH}
- onUpdateSetting={uiStateActions.setExportImageSetting}
+ onUpdateImageSetting={uiStateActions.setExportImageSetting}
/>
);
modalProps = {
@@ -367,7 +367,7 @@ export default function ModalContainerFactory(
onConfirm: this._onExportImage,
confirmButton: {
large: true,
- disabled: uiState.exportImage.exporting,
+ disabled: uiState.exportImage.processing,
children: 'modal.button.download'
}
};
@@ -455,7 +455,6 @@ export default function ModalContainerFactory(
exportImage={uiState.exportImage}
mapInfo={visState.mapInfo}
onSetMapInfo={visStateActions.setMapInfo}
- onUpdateImageSetting={uiStateActions.setExportImageSetting}
cloudProviders={this.providerWithStorage(this.props)}
onSetCloudProvider={this.props.providerActions.setCloudProvider}
/>
diff --git a/src/components/modals/export-image-modal.js b/src/components/modals/export-image-modal.js
index 254eb4e8d..030c0e5e3 100644
--- a/src/components/modals/export-image-modal.js
+++ b/src/components/modals/export-image-modal.js
@@ -23,11 +23,7 @@ import PropTypes from 'prop-types';
import styled from 'styled-components';
import ImagePreview from 'components/common/image-preview';
-import {
- EXPORT_IMG_RATIO_OPTIONS,
- EXPORT_IMG_RESOLUTION_OPTIONS,
- EXPORT_IMG_RATIOS
-} from 'constants/default-settings';
+import {EXPORT_IMG_RATIO_OPTIONS, EXPORT_IMG_RESOLUTION_OPTIONS} from 'constants/default-settings';
import {StyledModalContent, SelectionButton} from 'components/common/styled-components';
import Switch from 'components/common/switch';
@@ -64,31 +60,30 @@ const ExportImageModalFactory = () => {
mapH: PropTypes.number.isRequired,
exportImage: PropTypes.object.isRequired,
// callbacks
- onUpdateSetting: PropTypes.func.isRequired
+ onUpdateImageSetting: PropTypes.func.isRequired
};
- componentDidMount() {
+ componentDidUpdate() {
this._updateMapDim();
}
- componentDidUpdate() {
- this._updateMapDim();
+ componentWillUnmount() {
+ this.props.onUpdateImageSetting({exporting: false});
}
_updateMapDim() {
const {exportImage, mapH, mapW} = this.props;
if (mapH !== exportImage.mapH || mapW !== exportImage.mapW) {
- this.props.onUpdateSetting({
+ this.props.onUpdateImageSetting({
mapH,
mapW,
- ratio: EXPORT_IMG_RATIOS.CUSTOM,
legend: false
});
}
}
render() {
- const {exportImage, onUpdateSetting, intl} = this.props;
+ const {exportImage, onUpdateImageSetting, intl} = this.props;
const {legend, ratio, resolution} = exportImage;
return (
@@ -104,7 +99,7 @@ const ExportImageModalFactory = () => {
<SelectionButton
key={op.id}
selected={ratio === op.id}
- onClick={() => onUpdateSetting({ratio: op.id})}
+ onClick={() => onUpdateImageSetting({ratio: op.id})}
>
<FormattedMessage id={op.label} />
</SelectionButton>
@@ -121,7 +116,7 @@ const ExportImageModalFactory = () => {
<SelectionButton
key={op.id}
selected={resolution === op.id}
- onClick={() => op.available && onUpdateSetting({resolution: op.id})}
+ onClick={() => op.available && onUpdateImageSetting({resolution: op.id})}
>
{op.label}
</SelectionButton>
@@ -137,7 +132,7 @@ const ExportImageModalFactory = () => {
id="add-map-legend"
checked={legend}
label={intl.formatMessage({id: 'modal.exportImage.mapLegendAdd'})}
- onChange={() => onUpdateSetting({legend: !legend})}
+ onChange={() => onUpdateImageSetting({legend: !legend})}
/>
</div>
</ImageOptionList>
diff --git a/src/components/modals/image-modal-container.js b/src/components/modals/image-modal-container.js
index 7909501c0..bd0d450b8 100644
--- a/src/components/modals/image-modal-container.js
+++ b/src/components/modals/image-modal-container.js
@@ -52,6 +52,10 @@ export default class ImageModalContainer extends Component {
}
}
+ componentWillUnmount() {
+ this.props.onUpdateImageSetting({exporting: false});
+ }
+
_updateThumbSize(initialMount) {
if (this.props.currentProvider && this.props.cloudProviders.length) {
const provider = this.props.cloudProviders.find(p => p.name === this.props.currentProvider);
diff --git a/src/components/plot-container.js b/src/components/plot-container.js
index bc88e4721..6fcd739c3 100644
--- a/src/components/plot-container.js
+++ b/src/components/plot-container.js
@@ -30,13 +30,22 @@ import MapContainerFactory from './map-container';
import {convertToPng} from 'utils/export-utils';
import {scaleMapStyleByResolution} from 'utils/map-style-utils/mapbox-gl-style-editor';
import {getScaleFromImageSize} from 'utils/export-utils';
+import {findMapBounds} from 'utils/data-utils';
+import geoViewport from '@mapbox/geo-viewport';
+
+const DOM_FILTER_FUNC = node => node.className !== 'mapboxgl-control-container';
+const OUT_OF_SCREEN_POSITION = -9999;
const propTypes = {
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
exportImageSetting: PropTypes.object.isRequired,
addNotification: PropTypes.func.isRequired,
- mapFields: PropTypes.object.isRequired
+ mapFields: PropTypes.object.isRequired,
+ setExportImageSetting: PropTypes.object.isRequired,
+ setExportImageDataUri: PropTypes.func.isRequired,
+ setExportImageError: PropTypes.func.isRequired,
+ splitMaps: PropTypes.arrayOf(PropTypes.object)
};
PlotContainerFactory.deps = [MapContainerFactory];
@@ -49,6 +58,14 @@ const StyledPlotContainer = styled.div`
}
position: absolute;
+ top: ${OUT_OF_SCREEN_POSITION}px;
+ left: ${OUT_OF_SCREEN_POSITION}px;
+`;
+
+const StyledMapContainer = styled.div`
+ width: ${props => props.width}px;
+ height: ${props => props.height}px;
+ display: flex;
`;
const deckGlProps = {
@@ -63,10 +80,11 @@ export default function PlotContainerFactory(MapContainer) {
constructor(props) {
super(props);
this._onMapRender = debounce(this._onMapRender, 500);
+ this._retrieveNewScreenshot = debounce(this._retrieveNewScreenshot, 500);
}
componentDidMount() {
- this.props.startExportingImage();
+ this.props.setExportImageSetting({processing: true});
}
componentDidUpdate(prevProps) {
@@ -76,6 +94,7 @@ export default function PlotContainerFactory(MapContainer) {
item => this.props.exportImageSetting[item] !== prevProps.exportImageSetting[item]
);
if (shouldRetrieveScreenshot) {
+ this.props.setExportImageSetting({processing: true});
this._retrieveNewScreenshot();
}
}
@@ -118,10 +137,7 @@ export default function PlotContainerFactory(MapContainer) {
_retrieveNewScreenshot = () => {
if (this.plottingAreaRef.current) {
- this.props.startExportingImage();
- const filter = node => node.className !== 'mapboxgl-control-container';
-
- convertToPng(this.plottingAreaRef.current, {filter})
+ convertToPng(this.plottingAreaRef.current, {filter: DOM_FILTER_FUNC})
.then(this.props.setExportImageDataUri)
.catch(err => {
this.props.setExportImageError(err);
@@ -133,24 +149,41 @@ export default function PlotContainerFactory(MapContainer) {
render() {
const {exportImageSetting, mapFields, splitMaps} = this.props;
const {imageSize = {}, legend} = exportImageSetting;
+ const {mapState} = mapFields;
const isSplit = splitMaps && splitMaps.length > 1;
const size = {
width: imageSize.imageW || 1,
height: imageSize.imageH || 1
};
+
+ const bounds = findMapBounds(mapFields.layers);
+ const width = size.width / (isSplit ? 2 : 1);
+ const height = size.height;
const scale = this.mapScaleSelector(this.props);
+ const newMapState = {
+ ...mapState,
+ width,
+ height,
+ zoom: mapState.zoom + (Math.log2(scale) || 0)
+ };
+
+ if (exportImageSetting.center) {
+ const {center, zoom} = exportImageSetting.center
+ ? geoViewport.viewport(bounds, [width, height])
+ : {center: [mapState.longitude, mapState.latitude], zoom: mapState.zoom};
+
+ newMapState.longitude = center[0];
+ newMapState.latitude = center[1];
+ newMapState.zoom = zoom + Number(Math.log2(scale) || 0);
+ }
+
const mapProps = {
...mapFields,
mapStyle: this.scaledMapStyleSelector(this.props),
// override viewport based on export settings
- mapState: {
- ...mapFields.mapState,
- width: size.width / (isSplit ? 2 : 1),
- height: size.height,
- zoom: mapFields.mapState.zoom + (Math.log2(scale) || 0)
- },
+ mapState: newMapState,
mapControls: {
// override map legend visibility
mapLegend: {
@@ -178,20 +211,10 @@ export default function PlotContainerFactory(MapContainer) {
);
return (
- <StyledPlotContainer
- style={{position: 'absolute', top: -9999, left: -9999}}
- className="export-map-instance"
- >
- <div
- ref={this.plottingAreaRef}
- style={{
- width: `${size.width}px`,
- height: `${size.height}px`,
- display: 'flex'
- }}
- >
+ <StyledPlotContainer className="export-map-instance">
+ <StyledMapContainer ref={this.plottingAreaRef} width={size.width} height={size.height}>
{mapContainers}
- </div>
+ </StyledMapContainer>
</StyledPlotContainer>
);
}
diff --git a/src/components/side-panel.js b/src/components/side-panel.js
index 5f220ce29..8631f6841 100644
--- a/src/components/side-panel.js
+++ b/src/components/side-panel.js
@@ -37,13 +37,10 @@ import {
ADD_DATA_ID,
ADD_MAP_STYLE_ID,
DATA_TABLE_ID,
- EXPORT_IMAGE_ID,
EXPORT_DATA_ID,
EXPORT_MAP_ID,
- SAVE_MAP_ID,
SHARE_MAP_ID,
- SIDEBAR_PANELS,
- OVERWRITE_MAP_ID
+ SIDEBAR_PANELS
} from 'constants/default-settings';
const SidePanelContent = styled.div`
@@ -150,22 +147,20 @@ export default function SidePanelFactory(
this.props.uiStateActions.openDeleteModal(key);
};
- _onClickExportImage = () => this.props.uiStateActions.toggleModal(EXPORT_IMAGE_ID);
+ _onClickExportImage = () => this.props.uiStateActions.startExportingImage();
_onClickExportData = () => this.props.uiStateActions.toggleModal(EXPORT_DATA_ID);
_onClickExportMap = () => this.props.uiStateActions.toggleModal(EXPORT_MAP_ID);
- _onClickSaveToStorage = () => {
- this.props.uiStateActions.toggleModal(this.props.mapSaved ? OVERWRITE_MAP_ID : SAVE_MAP_ID);
- };
+ _onClickSaveToStorage = () => this.props.uiStateActions.startSaveStorage(this.props.mapSaved);
_onClickSaveAsToStorage = () => {
// add (copy) to file name
this.props.visStateActions.setMapInfo({
title: `${this.props.mapInfo.title || 'Kepler.gl'} (Copy)`
});
- this.props.uiStateActions.toggleModal(SAVE_MAP_ID);
+ this.props.uiStateActions.startSaveStorage(false);
};
_onClickShareMap = () => this.props.uiStateActions.toggleModal(SHARE_MAP_ID);
diff --git a/src/constants/action-types.d.ts b/src/constants/action-types.d.ts
index c044eaa90..5f74f5d17 100644
--- a/src/constants/action-types.d.ts
+++ b/src/constants/action-types.d.ts
@@ -52,7 +52,7 @@ export type ActionType = {
COPY_TABLE_COLUMN: string;
NEXT_FILE_BATCH: string;
PROCESS_FILE_CONTENT: string;
-
+
// mapState
UPDATE_MAP: string;
FIT_BOUNDS: string;
@@ -116,8 +116,11 @@ export type ActionType = {
SET_POLYGON_FILTER_LAYER: string;
DELETE_FEATURE: string;
TOGGLE_EDITOR_VISIBILITY: string;
+
+ // storage
+ START_SAVE_STORAGE: string;
};
export const ActionTypes: ActionType;
export const ACTION_PREFIX: string;
-export default ActionTypes;
\ No newline at end of file
+export default ActionTypes;
diff --git a/src/constants/action-types.js b/src/constants/action-types.js
index 7a8134135..0e8ca762a 100644
--- a/src/constants/action-types.js
+++ b/src/constants/action-types.js
@@ -166,7 +166,10 @@ const ActionTypes = {
SET_FEATURES: `${ACTION_PREFIX}SET_FEATURES`,
SET_POLYGON_FILTER_LAYER: `${ACTION_PREFIX}SET_POLYGON_FILTER_LAYER`,
DELETE_FEATURE: `${ACTION_PREFIX}DELETE_FEATURE`,
- TOGGLE_EDITOR_VISIBILITY: `${ACTION_PREFIX}TOGGLE_EDITOR_VISIBILITY`
+ TOGGLE_EDITOR_VISIBILITY: `${ACTION_PREFIX}TOGGLE_EDITOR_VISIBILITY`,
+
+ // storage
+ START_SAVE_STORAGE: `${ACTION_PREFIX}START_SAVE_STORAGE`
};
export default ActionTypes;
diff --git a/src/reducers/ui-state-updaters.d.ts b/src/reducers/ui-state-updaters.d.ts
index 49d9823b3..2d6de56cd 100644
--- a/src/reducers/ui-state-updaters.d.ts
+++ b/src/reducers/ui-state-updaters.d.ts
@@ -17,6 +17,7 @@ export type ExportImage = {
// exporting state
imageDataUri: string;
exporting: boolean;
+ processing: boolean;
error: Error;
};
@@ -129,10 +130,6 @@ export function setExportImageSettingUpdater(
state: UiState,
action: UiStateActions.SetExportImageSettingUpdaterAction
): UiState;
-export function startExportingImageUpdater(
- state: UiState,
- action: UiStateActions.StartExportingImageUpdaterAction
-): UiState;
export function setExportImageDataUriUpdater(
state: UiState,
action: UiStateActions.SetExportImageDataUriUpdaterAction
@@ -145,6 +142,10 @@ export function cleanupExportImageUpdater(
state: UiState,
action: UiStateActions.CleanupExportImageUpdaterAction
): UiState;
+export function startExportingImageUpdater(
+ state: UiState,
+ action: UiStateActions.startExportingImage
+): UiState;
export function setExportSelectedDatasetUpdater(
state: UiState,
action: UiStateActions.SetExportSelectedDatasetUpdaterAction
@@ -177,6 +178,10 @@ export function setLocaleUpdater(
state: UiState,
action: UiStateActions.SetLocaleUpdaterAction
): UiState;
+export function startSaveStorage(
+ state: UiState,
+ action: UiStateActions.StartSaveStorage
+): UiState
export function loadFilesUpdater(state: UiState, action: LoadFilesUpdaterAction): UiState;
export function loadFilesErrUpdater(state: UiState, action: LoadFilesErrUpdaterAction): UiState;
diff --git a/src/reducers/ui-state-updaters.js b/src/reducers/ui-state-updaters.js
index 94e406596..f8a9190c1 100644
--- a/src/reducers/ui-state-updaters.js
+++ b/src/reducers/ui-state-updaters.js
@@ -32,6 +32,9 @@ import {
import {LOCALE_CODES} from 'localization/locales';
import {createNotification, errorNotification} from 'utils/notifications-utils';
import {calculateExportImageSize} from 'utils/export-utils';
+import {payload_, apply_, compose_} from './composer-helpers';
+import {EXPORT_IMAGE_ID} from '../constants';
+import {OVERWRITE_MAP_ID, SAVE_MAP_ID} from '../constants/default-settings';
export const DEFAULT_ACTIVE_SIDE_PANEL = 'layer';
export const DEFAULT_MODAL = ADD_DATA_ID;
@@ -140,9 +143,14 @@ export const DEFAULT_EXPORT_IMAGE = {
imageW: 0,
imageH: 0
},
+ // when this is set to true, the mock map viewport will move to the center of data
+ center: false,
// exporting state
imageDataUri: '',
+ // exporting: used to attach plot-container to dom
exporting: false,
+ // processing: used as loading indicator when export image is being produced
+ processing: false,
error: false
};
@@ -379,23 +387,6 @@ export const setExportImageSettingUpdater = (state, {payload: newSetting}) => {
};
};
-/**
- * Set `exportImage.exporting` to `true`
- * @memberof uiStateUpdaters
- * @param state `uiState`
- * @returns nextState
- * @type {typeof import('./ui-state-updaters').startExportingImageUpdater}
- * @public
- */
-export const startExportingImageUpdater = state => ({
- ...state,
- exportImage: {
- ...state.exportImage,
- exporting: true,
- imageDataUri: ''
- }
-});
-
/**
* Set `exportImage.setExportImageDataUri` to a image dataUri
* @memberof uiStateUpdaters
@@ -410,7 +401,7 @@ export const setExportImageDataUriUpdater = (state, {payload: dataUri}) => ({
...state,
exportImage: {
...state.exportImage,
- exporting: false,
+ processing: false,
imageDataUri: dataUri
}
});
@@ -441,10 +432,33 @@ export const cleanupExportImageUpdater = state => ({
...state.exportImage,
exporting: false,
imageDataUri: '',
- error: false
+ error: false,
+ center: false
}
});
+/**
+ * Start image exporting flow
+ * @memberof uiStateUpdaters
+ * @param state
+ * @param options
+ * @returns {UiState}
+ * @type {typeof import('./ui-state-updaters').startExportingImage}
+ * @public
+ */
+export const startExportingImageUpdater = (state, {payload: options = {}}) => {
+ const imageSettings = {
+ ...options,
+ exporting: true
+ };
+
+ return compose_([
+ cleanupExportImageUpdater,
+ apply_(setExportImageSettingUpdater, payload_(imageSettings)),
+ apply_(toggleModalUpdater, payload_(EXPORT_IMAGE_ID))
+ ])(state);
+};
+
/**
* Set selected dataset for export
* @memberof uiStateUpdaters
@@ -698,3 +712,19 @@ export const setLocaleUpdater = (state, {payload: {locale}}) => ({
...state,
locale
});
+
+/**
+ * Start saving storage flow
+ * @memberof uiStateUpdaters
+ * @param state
+ * @param mapSaved
+ * @returns {UiState}
+ * @type {typeof import('./ui-state-updaters').startSaveStorage}
+ */
+export const startSaveStorage = (state, {payload: mapSaved}) => {
+ return compose_([
+ cleanupExportImageUpdater,
+ apply_(setExportImageSettingUpdater, payload_({exporting: true})),
+ apply_(toggleModalUpdater, payload_(mapSaved ? OVERWRITE_MAP_ID : SAVE_MAP_ID))
+ ])(state);
+};
diff --git a/src/reducers/ui-state.js b/src/reducers/ui-state.js
index 883ba8c4c..fe9b2e3f8 100644
--- a/src/reducers/ui-state.js
+++ b/src/reducers/ui-state.js
@@ -37,10 +37,10 @@ const actionHandler = {
[ActionTypes.REMOVE_NOTIFICATION]: uiStateUpdaters.removeNotificationUpdater,
[ActionTypes.SET_EXPORT_IMAGE_SETTING]: uiStateUpdaters.setExportImageSettingUpdater,
- [ActionTypes.START_EXPORTING_IMAGE]: uiStateUpdaters.startExportingImageUpdater,
[ActionTypes.SET_EXPORT_IMAGE_DATA_URI]: uiStateUpdaters.setExportImageDataUriUpdater,
[ActionTypes.SET_EXPORT_IMAGE_ERROR]: uiStateUpdaters.setExportImageErrorUpdater,
[ActionTypes.CLEANUP_EXPORT_IMAGE]: uiStateUpdaters.cleanupExportImageUpdater,
+ [ActionTypes.START_EXPORTING_IMAGE]: uiStateUpdaters.startExportingImageUpdater,
[ActionTypes.SET_EXPORT_SELECTED_DATASET]: uiStateUpdaters.setExportSelectedDatasetUpdater,
[ActionTypes.SET_EXPORT_DATA_TYPE]: uiStateUpdaters.setExportDataTypeUpdater,
@@ -55,7 +55,9 @@ const actionHandler = {
[ActionTypes.LOAD_FILES_ERR]: uiStateUpdaters.loadFilesErrUpdater,
[ActionTypes.TOGGLE_SPLIT_MAP]: uiStateUpdaters.toggleSplitMapUpdater,
- [ActionTypes.SET_LOCALE]: uiStateUpdaters.setLocaleUpdater
+ [ActionTypes.SET_LOCALE]: uiStateUpdaters.setLocaleUpdater,
+
+ [ActionTypes.START_SAVE_STORAGE]: uiStateUpdaters.startSaveStorage
};
/* Reducer */
diff --git a/src/reducers/vis-state-selectors.js b/src/reducers/vis-state-selectors.js
index 7a3b5c322..43c0594d1 100644
--- a/src/reducers/vis-state-selectors.js
+++ b/src/reducers/vis-state-selectors.js
@@ -1,3 +1,23 @@
+// Copyright (c) 2020 Uber Technologies, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
import {createSelector} from 'reselect';
// NOTE: default formats must match file-handler.js
diff --git a/test/browser/components/kepler-gl-test.js b/test/browser/components/kepler-gl-test.js
index 1176d7549..a09bf3772 100644
--- a/test/browser/components/kepler-gl-test.js
+++ b/test/browser/components/kepler-gl-test.js
@@ -143,7 +143,11 @@ test('Components -> KeplerGl -> Mount -> Plot', t => {
...initialCoreState,
uiState: {
...initialCoreState.uiState,
- currentModal: EXPORT_IMAGE_ID
+ currentModal: EXPORT_IMAGE_ID,
+ exportImage: {
+ ...initialCoreState.uiState.exportImage,
+ exporting: true
+ }
}
}
}
diff --git a/test/browser/components/side-panel/side-panel-test.js b/test/browser/components/side-panel/side-panel-test.js
index f248cd54e..3a5f725be 100644
--- a/test/browser/components/side-panel/side-panel-test.js
+++ b/test/browser/components/side-panel/side-panel-test.js
@@ -55,7 +55,7 @@ const SaveExportDropdown = appInjector.get(SaveExportDropdownFactory);
import {InitialState} from 'test/helpers/mock-state';
// Constants
-import {EXPORT_IMAGE_ID, EXPORT_DATA_ID, EXPORT_MAP_ID} from 'constants/default-settings';
+import {EXPORT_DATA_ID, EXPORT_MAP_ID} from 'constants/default-settings';
// default props from initial state
const defaultProps = {
@@ -316,9 +316,11 @@ test('Components -> SidePanel -> PanelHeader', t => {
test('Components -> SidePanel -> PanelHeader -> ExportDropDown', t => {
const toggleModal = sinon.spy();
+ const startExportingImage = sinon.spy();
const uiStateActions = {
...UIStateActions,
- toggleModal
+ toggleModal,
+ startExportingImage
};
// mound with exportDropdown
@@ -350,12 +352,13 @@ test('Components -> SidePanel -> PanelHeader -> ExportDropDown', t => {
'Export Image',
'Should render Export Image'
);
+
wrapper
.find(ToolbarItem)
.at(0)
.find('.toolbar-item')
.simulate('click');
- t.ok(toggleModal.calledWith(EXPORT_IMAGE_ID), 'Should call toggleModal with EXPORT_IMAGE_ID');
+ t.ok(startExportingImage.calledOnce, 'Should call startExportingImage with no params');
// export data
t.equal(
diff --git a/test/node/reducers/ui-state-test.js b/test/node/reducers/ui-state-test.js
index 904dd8997..5a4a44225 100644
--- a/test/node/reducers/ui-state-test.js
+++ b/test/node/reducers/ui-state-test.js
@@ -29,7 +29,9 @@ import {
setExportSelectedDataset,
setExportDataType,
setExportFiltered,
- addNotification
+ addNotification,
+ startExportingImage,
+ startSaveStorage
} from 'actions/ui-state-actions';
import {loadFiles, loadFilesErr} from 'actions/vis-state-actions';
import reducer, {uiStateReducerFactory} from 'reducers/ui-state';
@@ -38,7 +40,9 @@ import {
EXPORT_DATA_TYPE,
RESOLUTIONS,
DEFAULT_NOTIFICATION_TOPICS,
- DEFAULT_NOTIFICATION_TYPES
+ DEFAULT_NOTIFICATION_TYPES,
+ EXPORT_IMAGE_ID,
+ SAVE_MAP_ID
} from 'constants/default-settings';
import {removeNotification} from 'actions/ui-state-actions';
@@ -126,6 +130,23 @@ test('#uiStateReducer -> SET_EXPORT_IMAGE_SETTING', t => {
t.end();
});
+test('#uiStateReducer -> START_EXPORTING_IMAGE', t => {
+ const newReducer = reducer(INITIAL_UI_STATE, startExportingImage());
+
+ const expectedState = {
+ ...INITIAL_UI_STATE,
+ currentModal: EXPORT_IMAGE_ID,
+ exportImage: {
+ ...INITIAL_UI_STATE.exportImage,
+ exporting: true
+ }
+ };
+
+ t.deepEqual(newReducer, expectedState, 'should set exporting to true and modal to export image');
+
+ t.end();
+});
+
test('#uiStateReducer -> TOGGLE_MAP_CONTROL', t => {
const newReducer = reducer(INITIAL_UI_STATE, toggleMapControl('mapLegend'));
@@ -276,3 +297,20 @@ test('#uiStateReducer -> LOAD_FILES_ERR', t => {
t.end();
});
+
+test('#uiStateReducer -> START_SAVE_STORAGE', t => {
+ const newReducer = reducer(INITIAL_UI_STATE, startSaveStorage(''));
+
+ const expectedState = {
+ ...INITIAL_UI_STATE,
+ currentModal: SAVE_MAP_ID,
+ exportImage: {
+ ...INITIAL_UI_STATE.exportImage,
+ exporting: true
+ }
+ };
+
+ t.deepEqual(newReducer, expectedState, 'should set exporting to true and modal to export image');
+
+ t.end();
+});
diff --git a/yarn.lock b/yarn.lock
index 0fcb1e199..751d5a363 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2293,6 +2293,14 @@
"@babel/runtime" "^7.3.1"
"@probe.gl/stats" "^3.3.0"
+"@loaders.gl/loader-utils@^2.2.5":
+ version "2.2.8"
+ resolved "https://registry.yarnpkg.com/@loaders.gl/loader-utils/-/loader-utils-2.2.8.tgz#9f12f3460260b15e961fa46c3d3c867d7bf48bee"
+ integrity sha512-3F2VgxJPxjuZwAr8fDBkZzx3Wg275XdVaWnyYQ3uyZQ22yGEkrzKc+TlgcqSrxbO5pHrtS5PdS7dmyoJo2+Bdg==
+ dependencies:
+ "@babel/runtime" "^7.3.1"
+ "@probe.gl/stats" "^3.3.0"
+
"@loaders.gl/[email protected]":
version "2.2.5"
resolved "https://registry.yarnpkg.com/@loaders.gl/math/-/math-2.2.5.tgz#d3c52a75821b5934e54dd82211a372a69ec6474e"