Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
[Enhancement] Export import map config (#48)
Giuseppe Macrì298cb23d9634
diff --git a/README.md b/README.mdindex 082fe0592..83bdbe9a1 100644--- a/README.md+++ b/README.md@@ -29,7 +29,7 @@ yarn --ignore-engines```then```-npm start+MapboxAccessToken=MapboxAPIKey npm start```An Example app will be served athttp://localhost:8080/diff --git a/examples/demo-app/src/components/load-data-modal/load-data-modal.js b/examples/demo-app/src/components/load-data-modal/load-data-modal.jsindex e897ea2be..970d5b8b5 100644--- a/examples/demo-app/src/components/load-data-modal/load-data-modal.js+++ b/examples/demo-app/src/components/load-data-modal/load-data-modal.js@@ -23,7 +23,7 @@ import classnames from 'classnames';import styled, {ThemeProvider} from 'styled-components';import PropTypes from 'prop-types';import {FileUpload} from 'kepler.gl/components';-import LoadingSpinner from 'kepler.gl/components/common/loading-spinner';+import {LoadingSpinner} from 'kepler.gl/components';import {themeLT} from 'kepler.gl/styles';import {Icons} from 'kepler.gl/components/';diff --git a/package.json b/package.jsonindex c623e9c91..88f721c2a 100644--- a/package.json+++ b/package.json@@ -27,10 +27,10 @@"install:example": "cd examples/demo-app && npm i","test": "npm run test-node && npm run test-browser","fast-test": "NODE_ENV=test babel-tape-runner ./test/node.js && NODE_ENV=test babel-tape-runner -r ./test/setup-browser-env.js ./test/browser.js",- "test-browser": "NODE_ENV=test babel-tape-runner -r ./test/setup-browser-env.js ./test/browser.js | tap-spec",+ "test-browser": "NODE_ENV=test babel-tape-runner -r ./test/setup-browser-env.js ./test/browser.js","test-node": "NODE_ENV=test babel-tape-runner ./test/node.js | tap-spec","cover": "nyc --reporter html --reporter cobertura --reporter json-summary npm test && nyc report",- "start": "(cd examples/demo-app && (path-exists node_modules || npm i) && npm run start-local)",+ "start": "cd examples/demo-app && (path-exists node_modules || npm i) && npm run start-local","start:custom-layer": "(cd examples/custom-layer && (path-exists node_modules || npm i) && npm run start-local)","start:open-modal": "(cd examples/open-modal && (path-exists node_modules || npm i) && npm run start-local)","build": "rm -fr dist && uber-licence && babel src --out-dir dist --plugins=transform-es2015-modules-commonjs --source-maps inline",@@ -39,7 +39,8 @@"add-licence": "uber-licence","prepublish": "uber-licence && npm run build","web": "(npm run install:example && cd website && yarn --ignore-engines && yarn start)",- "deploy": "(cd website && yarn build && git checkout gh-pages && cp dist/* .. && git add .. && git commit -m 'Update website' && git push origin gh-pages && git checkout master)"+ "deploy": "(cd website && yarn build && git checkout gh-pages && cp dist/* .. && git add .. && git commit -m 'Update website' && git push origin gh-pages && git checkout master)",+ "clean": "rm -rf node_modules examples/demo-app/node_modules website/node_modules"},"files": ["dist",@@ -85,6 +86,7 @@"luma.gl": "4.0.6","moment": "^2.10.6","prop-types": "^15.6.0",+ "react-ace": "^6.1.1","react-anything-sortable": "^1.7.2","react-data-grid": "2.0.80-am-fix-defaultprops-warnings3337","react-file-drop": "^0.1.8",diff --git a/src/actions/ui-state-actions.js b/src/actions/ui-state-actions.jsindex 01ef690f2..84487ceb9 100644--- a/src/actions/ui-state-actions.js+++ b/src/actions/ui-state-actions.js@@ -28,6 +28,7 @@ const {SET_EXPORT_FILTERED,SET_EXPORT_IMAGE_DATA_URI,SET_EXPORT_CONFIG,+ SET_EXPORT_DATA,SET_EXPORT_SELECTED_DATASET,SET_RATIO,SET_RESOLUTION,@@ -55,7 +56,8 @@ const [setExportSelectedDataset,setExportDataType,setExportFiltered,- setExportConfig+ setExportConfig,+ setExportData] = [TOGGLE_SIDE_PANEL,TOGGLE_MODAL,@@ -70,11 +72,12 @@ const [SET_EXPORT_SELECTED_DATASET,SET_EXPORT_DATA_TYPE,SET_EXPORT_FILTERED,- SET_EXPORT_CONFIG+ SET_EXPORT_CONFIG,+ SET_EXPORT_DATA].map(a => createAction(a));export {- toggleSidePanel, toggleModal, toggleMapControl, openDeleteModal, setExportConfig,+ toggleSidePanel, toggleModal, toggleMapControl, openDeleteModal, setExportConfig, setExportData,setRatio, setResolution, toggleLegend, startExportingImage, setExportImageDataUri, cleanupExportImage,setExportSelectedDataset, setExportDataType, setExportFiltered};diff --git a/src/components/common/file-uploader/file-upload.js b/src/components/common/file-uploader/file-upload.jsindex 9db288c89..453d3d71e 100644--- a/src/components/common/file-uploader/file-upload.js+++ b/src/components/common/file-uploader/file-upload.js@@ -41,7 +41,7 @@ const defaultValidFileExt = [// 'zip',// 'gpx',// 'kml',- // 'json',+ 'json','geojson'];@@ -50,6 +50,7 @@ const CHROME_MSG ='*Chrome user: Limit file size to 250mb, if need to upload larger file, try Safari';const DISCLAIMER = '*Kepler.gl is a client-side application with no server backend. Data lives only on your machine/browser. ' +'No information or map data is sent to any server.';+const CONFIG_UPLOAD_MESSAGE = 'Upload data files or upload saved maps from Json containing config and data';const fileIconColor = '#D3D8E0';@@ -97,11 +98,19 @@ const StyledDragNDropIcon = styled.div`const StyledFileUpload = styled.div`.filter-upload__input {visibility: hidden;+ height: 0;+ position: absolute;}.file-drop {position: relative;}++ .file-upload__message {+ color: ${props => props.theme.textColorLT};+ font-size: 14px;+ margin-bottom: 12px;+ }`;const StyledMessage = styled.div`@@ -214,6 +223,7 @@ export default class FileUpload extends Component {onDragLeave={() => this._toggleDragState(false)}onDrop={this._handleFileDrop}>+ <div className="file-upload__message">{CONFIG_UPLOAD_MESSAGE}</div><StyledFileDrop dragOver={dragOver}><div style={{opacity: dragOver ? 0.5 : 1}}><StyledDragNDropIcon>diff --git a/src/components/common/icons/code-alt.js b/src/components/common/icons/code-alt.jsnew file mode 100644index 000000000..c363aab7d--- /dev/null+++ b/src/components/common/icons/code-alt.js@@ -0,0 +1,43 @@+// Copyright (c) 2018 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 React, {Component} from 'react';+import PropTypes from 'prop-types';+import Base from './base';++export default class CodeAlt extends Component {+ static propTypes = {+ /** Set the height of the icon, ex. '16px' */+ height: PropTypes.string+ };++ static defaultProps = {+ height: '16px',+ predefinedClassName: 'data-ex-icons-crosshairs'+ };++ render() {+ return (+ <Base viewBox="0 0 64 64" {...this.props}>+ <path d="M27.768 13.97v4.803a1.2 1.2 0 0 1-1.201 1.2H22.964v8.407a3.603 3.603 0 0 1-3.602 3.603 3.603 3.603 0 0 1 3.602 3.603v8.406H26.567a1.2 1.2 0 0 1 1.2 1.201v4.804a1.2 1.2 0 0 1-1.2 1.2h-6.005a4.804 4.804 0 0 1-4.803-4.803v-7.206a3.603 3.603 0 0 0-3.603-3.602H9.754a1.196 1.196 0 0 1-1.19-1.176h-.01v-4.829c0-.663.537-1.2 1.2-1.2h2.402a3.603 3.603 0 0 0 3.603-3.604v-7.205a4.804 4.804 0 0 1 4.803-4.804h6.005a1.2 1.2 0 0 1 1.2 1.201v.002zm27.584 21.616h-2.401a3.603 3.603 0 0 0-3.603 3.602v7.206a4.804 4.804 0 0 1-4.804 4.804H38.54a1.2 1.2 0 0 1-1.201-1.201V45.193c0-.663.537-1.2 1.2-1.2H42.143v-8.407a3.603 3.603 0 0 1 3.603-3.603 3.603 3.603 0 0 1-3.603-3.603v-8.406H38.54a1.2 1.2 0 0 1-1.201-1.201v-4.804c0-.663.537-1.2 1.2-1.2h6.005a4.804 4.804 0 0 1 4.804 4.803v7.205a3.603 3.603 0 0 0 3.603 3.603h2.401c.654 0 1.175.526 1.19 1.176h.011v4.829a1.2 1.2 0 0 1-1.2 1.2z"/>+ </Base>+ );+ }+};diff --git a/src/components/common/icons/index.js b/src/components/common/icons/index.jsindex dff5f6c80..b459ae6b5 100644--- a/src/components/common/icons/index.js+++ b/src/components/common/icons/index.js@@ -62,3 +62,4 @@ export {default as Trash} from './trash';export {default as Upload} from './upload';export {default as VertDots} from './vert-dots';export {default as IconWrapper} from './base';+export {default as CodeAlt} from './code-alt';diff --git a/src/components/index.js b/src/components/index.jsindex 8e8cf0c62..ff9560986 100644--- a/src/components/index.js+++ b/src/components/index.js@@ -58,6 +58,7 @@ export {default as TimeRangeSlider} from './common/time-range-slider';export {default as Modal, ModalFooter, ModalTitle} from './common/modal';export {default as AppLogo} from './common/logo';export {default as Switch} from './common/switch';+export {default as LoadingSpinner} from './common/loading-spinner';export * from './common/styled-components';export * as Icons from './common/icons';diff --git a/src/components/modal-container.js b/src/components/modal-container.jsindex 97c853810..0281d7e6c 100644--- a/src/components/modal-container.js+++ b/src/components/modal-container.js@@ -35,6 +35,7 @@ import DataTableModalFactory from './modals/data-table-modal';import LoadDataModalFactory from './modals/load-data-modal';import ExportImageModalFactory from './modals/export-image-modal';import ExportDataModalFactory from './modals/export-data-modal';+import ExportConfigModalFactory from './modals/export-config-modal';import AddMapStyleModalFactory from './modals/add-map-style-modal';import {@@ -45,6 +46,7 @@ import {EXPORT_DATA_ID,EXPORT_DATA_TYPE,EXPORT_IMAGE_ID,+ EXPORT_CONFIG_ID,ADD_MAP_STYLE_ID} from 'constants/default-settings';@@ -72,6 +74,7 @@ ModalContainerFactory.deps = [LoadDataModalFactory,ExportImageModalFactory,ExportDataModalFactory,+ ExportConfigModalFactory,AddMapStyleModalFactory];@@ -82,6 +85,7 @@ export default function ModalContainerFactory(LoadDataModal,ExportImageModal,ExportDataModal,+ ExportConfigModal,AddMapStyleModal) {class ModalWrapper extends Component {@@ -133,9 +137,9 @@ export default function ModalContainerFactory(}_onExportData = () => {- const {mapStyle, visState, mapState, uiState} = this.props;+ const {visState, uiState} = this.props;const {datasets} = visState;- const {selectedDataset, dataType, filtered, config} = uiState.exportData;+ const {selectedDataset, dataType, filtered} = uiState.exportData;// get the selected dataconst filename = 'kepler-gl';const selectedDatasets = datasets[selectedDataset] ? [datasets[selectedDataset]] : Object.values(datasets);@@ -162,17 +166,21 @@ export default function ModalContainerFactory(});- if (config) {- const keplerGlConfig = KeplerGlSchema.getConfigToSave(- {mapStyle, visState, mapState, uiState}- );+ this._closeModal();+ };- this._downloadFile(- JSON.stringify(keplerGlConfig, null, 2),- 'application/json',- 'kepler-gl_config.json'- );- }+ _onExportConfig = () => {+ const {data} = this.props.uiState.exportData;++ // we pass all props because we avoid to create new variables+ const dump = data ? KeplerGlSchema.save(this.props)+ : KeplerGlSchema.getConfigToSave(this.props);++ this._downloadFile(+ JSON.stringify(dump, null, 2),+ 'application/json',+ 'keplergl.json'+ );this._closeModal();};@@ -182,6 +190,7 @@ export default function ModalContainerFactory(containerW,containerH,mapStyle,+ mapState,uiState,visState,rootNode,@@ -281,6 +290,7 @@ export default function ModalContainerFactory(break;case EXPORT_DATA_ID:+template = (<ExportDataModal{...uiState.exportData}@@ -289,7 +299,6 @@ export default function ModalContainerFactory(onChangeExportDataType={this.props.uiStateActions.setExportDataType}onChangeExportSelectedDataset={this.props.uiStateActions.setExportSelectedDataset}onChangeExportFiltered={this.props.uiStateActions.setExportFiltered}- onChangeExportConfig={this.props.uiStateActions.setExportConfig}/>);modalProps = {@@ -305,6 +314,31 @@ export default function ModalContainerFactory(};break;+ case EXPORT_CONFIG_ID:+ const keplerGlConfig = KeplerGlSchema.getConfigToSave(+ {mapStyle, visState, mapState, uiState}+ );+ template = (+ <ExportConfigModal+ config={keplerGlConfig}+ data={uiState.exportData.data}+ onClose={this._closeModal}+ onChangeExportData={this.props.uiStateActions.setExportData}+ />+ );+ modalProps = {+ close: false,+ title: 'Export Config',+ footer: true,+ onCancel: this._closeModal,+ onConfirm: this._onExportConfig,+ confirmButton: {+ large: true,+ children: 'Export'+ }+ };+ break;+case ADD_MAP_STYLE_ID:template = (<AddMapStyleModaldiff --git a/src/components/modals/export-config-modal.js b/src/components/modals/export-config-modal.jsnew file mode 100644index 000000000..972e2361b--- /dev/null+++ b/src/components/modals/export-config-modal.js@@ -0,0 +1,184 @@+// Copyright (c) 2018 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 React from 'react';+import PropTypes from 'prop-types';+import styled from 'styled-components';+import AceEditor from 'react-ace';+import Switch from 'components/common/switch';++import {StyledModalContent} from 'components/common/styled-components';++const propTypes = {+ config: PropTypes.object.required+};++const StyledExportConfigSection = styled.div`+ display: flex;+ flex-direction: row;+ margin: 35px 0;+ width: 100%;++ .description {+ width: 185px;++ .title {+ font-weight: 500;+ color: ${props => props.theme.textColorLT};+ font-size: 12px;+ }+ .subtitle {+ color: ${props => props.theme.textColor};+ font-size: 11px;+ }++ .note {+ color: ${props => props.theme.errorColor};+ font-size: 11px;+ }+ }++ .selection {+ display: flex;+ flex-wrap: wrap;+ flex: 1;+ padding-left: 50px;++ select {+ background-color: white;+ border-radius: 1px;+ display: inline-block;+ font: inherit;+ line-height: 1.5em;+ padding: 0.5em 3.5em 0.5em 1em;+ margin: 0;+ box-sizing: border-box;+ appearance: none;+ width: 250px;+ height: 36px;++ background-image:+ linear-gradient(45deg, transparent 50%, gray 50%),+ linear-gradient(135deg, gray 50%, transparent 50%),+ linear-gradient(to right, #ccc, #ccc);+ background-position:+ calc(100% - 20px) calc(1em + 2px),+ calc(100% - 15px) calc(1em + 2px),+ calc(100% - 2.5em) 4.5em;+ background-size:+ 5px 5px,+ 5px 5px,+ 1px 1.5em;+ background-repeat: no-repeat;+ }++ select:focus {+ background-image:+ linear-gradient(45deg, green 50%, transparent 50%),+ linear-gradient(135deg, transparent 50%, green 50%),+ linear-gradient(to right, #ccc, #ccc);+ background-position:+ calc(100% - 15px) 1em,+ calc(100% - 20px) 1em,+ calc(100% - 2.5em) 4.5em;+ background-size:+ 5px 5px,+ 5px 5px,+ 1px 1.5em;+ background-repeat: no-repeat;+ border-color: green;+ outline: 0;+ }+ }+`;++const ExportConfigModal = ({+ data,+ config,+ // actions+ onChangeExportData+}) => (+ <div className="export-config-modal">+ <StyledModalContent>+ <div>+ <StyledExportConfigSection>+ <div className="description">+ <div className="title">+ Current Config+ </div>+ <div className="subtitle">+ You can copy or export the current Kepler.gl configuration.+ </div>+ <div className="note">+ * kepler.gl map config is coupled with loaded datasets.+ dataId key is used to bind layers and filters to a specific dataset.+ If you try to upload a configuration with a specific dataId you also need to make sure+ you existing dataset id match the dataId/s in the config.+ </div>+ </div>+ <div className="selection">+ <AceEditor+ mode="json"+ theme="monokai"+ name="kepler.gl-config"+ onLoad={this.onLoad}+ onChange={this.onChange}+ fontSize={9}+ readOnly={true}+ wrapEnabled={true}+ height="280px"+ showPrintMargin={true}+ showGutter={true}+ highlightActiveLine={false}+ value={JSON.stringify(config, null, 2)}+ setOptions={{+ enableBasicAutocompletion: false,+ enableLiveAutocompletion: true,+ enableSnippets: false,+ showLineNumbers: true,+ tabSize: 2+ }}/>+ </div>+ </StyledExportConfigSection>+ <StyledExportConfigSection>+ <div className="description">+ <div className="title">+ Export Current Map+ </div>+ <div className="subtitle">+ Export current map, including data and config. You can later load the same map by loading this file to kepler.gl.+ </div>+ </div>+ <div className="selection">+ <Switch type="checkbox"+ id="export-map-config"+ checked={data}+ onChange={onChangeExportData}/>+ </div>+ </StyledExportConfigSection>+ </div>+ </StyledModalContent>+ </div>+);++ExportConfigModal.propTypes = propTypes;++const ExportConfigModalFactory = () => ExportConfigModal;+export default ExportConfigModalFactory;diff --git a/src/components/modals/export-data-modal.js b/src/components/modals/export-data-modal.jsindex 18cc77f3e..1ab46d831 100644--- a/src/components/modals/export-data-modal.js+++ b/src/components/modals/export-data-modal.js@@ -25,7 +25,6 @@ import styled from 'styled-components';import {EXPORT_DATA_TYPE_OPTIONS} from 'constants/default-settings';import {FileType} from 'components/common/icons';import {StyledModalContent} from 'components/common/styled-components';-import Switch from 'components/common/switch';const StyledExportDataSection = styled.div`display: flex;@@ -155,7 +154,8 @@ const propTypes = {onClose: PropTypes.func.isRequired,onChangeExportSelectedDataset: PropTypes.func.isRequired,onChangeExportDataType: PropTypes.func.isRequired,- onChangeExportFiltered: PropTypes.func.isRequired+ onChangeExportFiltered: PropTypes.func.isRequired,+ onChangeExportConfig: PropTypes.func.isRequired};const getDataRowCount = (datasets, selectedDataset, filtered) => {@@ -177,9 +177,7 @@ const ExportDataModal = ({// callbacks:onChangeExportDataType,onChangeExportSelectedDataset,- onChangeExportFiltered,- onChangeExportConfig,- onClose+ onChangeExportFiltered}) => (<div className="export-data-modal"><StyledModalContent>@@ -246,23 +244,6 @@ const ExportDataModal = ({</div></StyledExportDataSection>- <StyledExportDataSection>- <div className="description">- <div className="title">- Include Map Config- </div>- <div className="subtitle">- Export current map config as a Json file- </div>- </div>- <div className="selection">- <Switch type="checkbox"- id="export-map-config"- checked={config}- onChange={onChangeExportConfig}/>- </div>- </StyledExportDataSection>-</div></StyledModalContent></div>diff --git a/src/components/side-panel.js b/src/components/side-panel.jsindex d38beed13..91bc8f551 100644--- a/src/components/side-panel.js+++ b/src/components/side-panel.js@@ -36,6 +36,7 @@ import {DATA_TABLE_ID,EXPORT_IMAGE_ID,EXPORT_DATA_ID,+ EXPORT_CONFIG_ID,PANELS} from 'constants/default-settings';@@ -107,6 +108,8 @@ export default function SidePanelFactory(PanelHeader) {_onExportData = () => this.props.uiStateActions.toggleModal(EXPORT_DATA_ID);+ _onExportConfig = () => this.props.uiStateActions.toggleModal(EXPORT_CONFIG_ID);+render() {const {appName,@@ -176,6 +179,7 @@ export default function SidePanelFactory(PanelHeader) {version={version}onExportImage={this._onExportImage}onExportData={this._onExportData}+ onExportConfig={this._onExportConfig}onSaveMap={this.props.onSaveMap}/><PanelTogglediff --git a/src/components/side-panel/panel-header.js b/src/components/side-panel/panel-header.jsindex b0833fa54..fcc2112a4 100644--- a/src/components/side-panel/panel-header.js+++ b/src/components/side-panel/panel-header.js@@ -23,7 +23,7 @@ import styled from 'styled-components';import PropTypes from 'prop-types';import {Tooltip} from 'components/common/styled-components';import KeplerGlLogo from 'components/common/logo';-import {Save, Files, Share, Picture} from 'components/common/icons';+import {CodeAlt, Save, Files, Share, Picture} from 'components/common/icons';import PanelDropdown from 'components/side-panel/panel-dropdown';const StyledPanelHeader = styled.div.attrs({@@ -137,9 +137,21 @@ export const PanelAction = ({item, onClick}) => (</StyledPanelAction>);+const PanelItem = ({onClose, onClickHandler, label, icon}) => (+ <div className="save-export-dropdown__item" onClick={(e) => {+ e.stopPropagation();+ onClose();+ onClickHandler();+ }}>+ {icon}+ <div className="save-export-dropdown__title">{label}</div>+ </div>+);+export const SaveExportDropdown = ({onExportImage,onExportData,+ onExportConfig,onSaveMap,show,onClose@@ -147,34 +159,34 @@ export const SaveExportDropdown = ({return (<StyledPanelDropdown show={show} className="save-export-dropdown"><PanelDropdown onClose={onClose} className="save-export-dropdown__inner">+ <PanelItem+ label="Export Image"+ onClickHandler={onExportImage}+ onClose={onClose}+ icon={(<Picture height="16px" />)}+ />- <div className="save-export-dropdown__item" onClick={(e) => {- e.stopPropagation();- onClose();- onExportImage();- }}>- <Picture height="16px" />- <div className="save-export-dropdown__title">Export Image</div>- </div>+ <PanelItem+ label="Export Data"+ onClickHandler={onExportData}+ onClose={onClose}+ icon={(<Files height="16px" />)}+ />- <div className="save-export-dropdown__item" onClick={(e) => {- e.stopPropagation();- onClose();- onExportData();- }}>- <Files height="16px" />- <div className="save-export-dropdown__title">Export Data</div>- </div>+ <PanelItem+ label="Export Config"+ onClickHandler={onExportConfig}+ onClose={onClose}+ icon={(<CodeAlt height="16px" />)}+ />{onSaveMap ? (- <div className="save-export-dropdown__item" onClick={(e) => {- e.stopPropagation();- onClose();- onSaveMap();- }}>- <Share height="16px" />- <div className="save-export-dropdown__title">Save Map Url</div>- </div>+ <PanelItem+ label="Save Map Url"+ onClickHandler={onSaveMap}+ onClose={onClose}+ icon={(<Share height="16px" />)}+ />) : null}</PanelDropdown></StyledPanelDropdown>diff --git a/src/constants/action-types.js b/src/constants/action-types.jsindex 4fd8b8cf3..efb825f5a 100644--- a/src/constants/action-types.js+++ b/src/constants/action-types.js@@ -88,6 +88,7 @@ const ActionTypes = keyMirror({SET_EXPORT_DATA_TYPE: null,SET_EXPORT_FILTERED: null,SET_EXPORT_CONFIG: null,+ SET_EXPORT_DATA: null,// allINIT: null,diff --git a/src/constants/default-settings.js b/src/constants/default-settings.jsindex 7de6d68bf..32b081c7b 100644--- a/src/constants/default-settings.js+++ b/src/constants/default-settings.js@@ -32,6 +32,7 @@ export const DELETE_DATA_ID = 'deleteData';export const ADD_DATA_ID = 'addData';export const EXPORT_IMAGE_ID = 'exportImage';export const EXPORT_DATA_ID = 'exportData';+export const EXPORT_CONFIG_ID = 'exportConfig';export const ADD_MAP_STYLE_ID = 'addMapStyle';import {diff --git a/src/processors/file-handler.js b/src/processors/file-handler.jsindex f043c7d9a..bae103d94 100644--- a/src/processors/file-handler.js+++ b/src/processors/file-handler.js@@ -20,19 +20,26 @@import {FileReader} from 'global/window';import {processCsvData, processGeojson} from './data-processor';+import KeplerGlSchema from 'schemas';++const FILE_HANDLERS = {+ csv: loadCsv,+ json: loadJSON+};export function getFileHandler(fileBlob) {const type = getFileType(fileBlob.name);-- return type === 'csv' ? loadCsv : type === 'geojson' ? loadGeoJSON : null;+ return FILE_HANDLERS[type];}export function getFileType(filename) {if (filename.endsWith('csv')) {return 'csv';- } else if (filename.endsWith('json') || filename.endsWith('geojson')) {+ }++ else if (filename.endsWith('json') || filename.endsWith('geojson')) {// Read GeoJson from browser- return 'geojson';+ return 'json';}// Wait to add other file type handler@@ -56,13 +63,13 @@ export function loadCsv(fileBlob, processor = processCsvData) {);}-function readGeoJSONFile(fileBlob) {+function readJSONFile(fileBlob) {return new Promise((resolve, reject) => {const fileReader = new FileReader();fileReader.onload = ({target: {result}}) => {try {- const geo = JSON.parse(result);- resolve(geo);+ const json = JSON.parse(result);+ resolve(json);} catch (err) {resolve(null);}@@ -72,8 +79,37 @@ function readGeoJSONFile(fileBlob) {});}-export function loadGeoJSON(fileBlob, processor = processGeojson) {- return readGeoJSONFile(fileBlob).then(- rawData => (rawData ? processor(rawData) : null)+export function isKeplerGlMap(json) {+ return (+ typeof json === 'object' &&+ json.datasets &&+ json.config &&+ json.info &&+ json.info.app === 'kepler.gl'+ );+}++export function determineJsonProcess(jsonData, defaultProcessor) {+ if (isKeplerGlMap(jsonData)) {+ return processKeplerglJSON;+ }++ return defaultProcessor;+}++export function loadJSON(fileBlob, processor = processGeojson) {+ return readJSONFile(fileBlob).then(+ rawData =>+ rawData ? determineJsonProcess(rawData, processor)(rawData) : null);}++export function processKeplerglJSON(rawData) {+ const data = rawData+ ? KeplerGlSchema.load(rawData.datasets, rawData.config)+ : null;+ return {+ ...data,+ reset: true // this will reset the state+ };+}diff --git a/src/reducers/ui-state-updaters.js b/src/reducers/ui-state-updaters.jsindex e86489937..f69395da5 100644--- a/src/reducers/ui-state-updaters.js+++ b/src/reducers/ui-state-updaters.js@@ -146,3 +146,11 @@ export const setExportConfigUpdater = (state, action) => ({config: !state.exportData.config}});++export const setExportDataUpdater = (state, action) => ({+ ...state,+ exportData: {+ ...state.exportData,+ data: !state.exportData.data+ }+});diff --git a/src/reducers/ui-state.js b/src/reducers/ui-state.jsindex 12b24052e..1316e0098 100644--- a/src/reducers/ui-state.js+++ b/src/reducers/ui-state.js@@ -43,7 +43,8 @@ import {setExportSelectedDatasetUpdater,setExportDataTypeUpdater,setExportFilteredUpdater,- setExportConfigUpdater+ setExportConfigUpdater,+ setExportDataUpdater} from './ui-state-updaters';export const DEFAULT_ACTIVE_SIDE_PANEL = 'layer';@@ -80,7 +81,8 @@ export const DEFAULT_EXPORT_DATA = {selectedDataset: '',dataType: EXPORT_DATA_TYPE.CSV,filtered: true,- config: true+ config: false, // no longer used, since we removed the option to export config from modal data export+ data: false // this is used in modal config export};export const INITIAL_UI_STATE = {@@ -113,7 +115,8 @@ const actionHandler = {[ActionTypes.SET_EXPORT_SELECTED_DATASET]: setExportSelectedDatasetUpdater,[ActionTypes.SET_EXPORT_DATA_TYPE]: setExportDataTypeUpdater,[ActionTypes.SET_EXPORT_FILTERED]: setExportFilteredUpdater,- [ActionTypes.SET_EXPORT_CONFIG]: setExportConfigUpdater+ [ActionTypes.SET_EXPORT_CONFIG]: setExportConfigUpdater,+ [ActionTypes.SET_EXPORT_DATA]: setExportDataUpdater};/* Reducer */diff --git a/src/reducers/vis-state-updaters.js b/src/reducers/vis-state-updaters.jsindex e23b173ce..271387e20 100644--- a/src/reducers/vis-state-updaters.js+++ b/src/reducers/vis-state-updaters.js@@ -26,7 +26,8 @@ import {disableStackCapturing} from 'react-palm/tasks';import {LOAD_FILE_TASK} from 'tasks/tasks';// Actions-import {updateVisData, loadFilesErr} from 'actions/vis-state-actions';+import {loadFilesErr} from 'actions/vis-state-actions';+import {addDataToMap} from 'actions';// Utilsimport {getDefaultInteraction} from 'utils/interaction-utils';@@ -933,7 +934,19 @@ export const loadFilesUpdater = (state, action) => {// reader -> parser -> augment -> receiveVisDataconst loadFileTasks = [Task.all(filesToLoad.map(LOAD_FILE_TASK)).bimap(- results => updateVisData(results, {centerMap: true}),+ results => {+ const data = results.reduce((f, c) => ({+ // using concat here because the current datasets could be an array or a single item+ datasets: f.datasets.concat(c.datasets),+ // we need to deep merge this thing unless we find a better solution+ // this case will only happen if we allow to load multiple keplergl json files+ config: {+ ...f.config,+ ...(c.config || {})+ }+ }), {datasets: [], config: {}, options: {centerMap: true}});+ return addDataToMap(data);+ },error => loadFilesErr(error))];diff --git a/src/schemas/schema-manager.js b/src/schemas/schema-manager.jsindex 5e7eb8d6d..8a8b71efc 100644--- a/src/schemas/schema-manager.js+++ b/src/schemas/schema-manager.js@@ -59,6 +59,10 @@ class KeplerGLSchema {* config: {* version: 'v0',* config: {}+ * },+ * info: {+ * app: 'kepler.gl',+ * create_at: 'Mon May 28 2018 21:04:46 GMT-0700 (PDT)'* }* }*@@ -69,7 +73,11 @@ class KeplerGLSchema {save(state) {return {datasets: this.getDatasetToSave(state),- config: this.getConfigToSave(state)+ config: this.getConfigToSave(state),+ info: {+ app: 'kepler.gl',+ created_at: new Date().toString()+ }};}@@ -79,6 +87,7 @@ class KeplerGLSchema {config: savedConfig ? this.parseSavedConfig(savedConfig) : undefined};}+/*** Get data to save* @param {Object} state - app statediff --git a/src/tasks/tasks.js b/src/tasks/tasks.jsindex 0a92c9149..b8d2c6aa8 100644--- a/src/tasks/tasks.js+++ b/src/tasks/tasks.js@@ -29,7 +29,15 @@ export const LOAD_FILE_TASK = taskCreator(// TODO: capture in the UI and show messagethrow new Error('fail to load data');} else {- success({data: result, info});+ // we are trying to standardize the shape of our return+ // since we start using the kepler.json format+ // result has both datasets and info+ // TODO: I think we should pass info to the handler and return+ // the same format back from the file handler+ if (result.datasets) { // this is coming from parsing keplergl.json file+ success(result); // info is already part of datasets+ }+ success({datasets: {data: result, info}});}}).catch(err => error(err)),diff --git a/src/utils/map-style-utils/mapbox-utils.js b/src/utils/map-style-utils/mapbox-utils.jsindex 0310ed8bb..69da48e9c 100644--- a/src/utils/map-style-utils/mapbox-utils.js+++ b/src/utils/map-style-utils/mapbox-utils.js@@ -1,3 +1,23 @@+// Copyright (c) 2018 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.+export const transformRequest = (url, resourceType) => {const isMapboxRequest = url.slice(8, 22) === 'api.mapbox.com' ||url.slice(10, 26) === 'tiles.mapbox.com';diff --git a/test/node/reducers/map-style-test.js b/test/node/reducers/map-style-test.jsindex 9642808b2..e0778dd1d 100644--- a/test/node/reducers/map-style-test.js+++ b/test/node/reducers/map-style-test.js@@ -1,3 +1,23 @@+// Copyright (c) 2018 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 test from 'tape';import reducer, {INITIAL_MAP_STYLE} from 'reducers/map-style';diff --git a/test/node/utils/mapbox-gl-style-editor-test.js b/test/node/utils/mapbox-gl-style-editor-test.jsindex 1089772e3..69f3f1dd2 100644--- a/test/node/utils/mapbox-gl-style-editor-test.js+++ b/test/node/utils/mapbox-gl-style-editor-test.js@@ -1,3 +1,23 @@+// Copyright (c) 2018 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 test from 'tape';import {mergeLayerGroupVisibility} from 'utils/map-style-utils/mapbox-gl-style-editor';diff --git a/test/setup-browser-env.js b/test/setup-browser-env.jsindex f84cda847..12d679d50 100644--- a/test/setup-browser-env.js+++ b/test/setup-browser-env.js@@ -37,5 +37,7 @@ Object.keys(global.window).forEach(property => {});global.navigator = {- userAgent: 'node.js'+ userAgent: 'node.js',+ platform: 'mac',+ appName: 'kepler.glsrc/components/modals/export-data-modal.js'};diff --git a/yarn.lock b/yarn.lockindex f41189e5f..779e7f582 100644--- a/yarn.lock+++ b/yarn.lock@@ -1320,6 +1320,10 @@ brace-expansion@^1.0.0, brace-expansion@^1.1.7:balanced-match "^1.0.0"concat-map "0.0.1"+brace@^0.11.0:+ version "0.11.1"+ resolved "https://registry.yarnpkg.com/brace/-/brace-0.11.1.tgz#4896fcc9d544eef45f4bb7660db320d3b379fe58"+braces@^1.8.2:version "1.8.5"resolved "https://registry.yarnpkg.com/braces/-/braces-1.8.5.tgz#ba77962e12dff969d6b76711e914b737857bf6a7"@@ -2408,6 +2412,10 @@ detective@^5.0.2:defined "^1.0.0"minimist "^1.1.1"+diff-match-patch@^1.0.0:+ version "1.0.1"+ resolved "https://registry.yarnpkg.com/diff-match-patch/-/diff-match-patch-1.0.1.tgz#d5f880213d82fbc124d2b95111fb3c033dbad7fa"+diff@^3.1.0:version "3.5.0"resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"@@ -4521,6 +4529,14 @@ lodash.flattendeep@^4.2.0, lodash.flattendeep@^4.4.0:version "4.4.0"resolved "https://registry.yarnpkg.com/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz#fb030917f86a3134e5bc9bec0d69e0013ddfedb2"+lodash.get@^4.4.2:+ version "4.4.2"+ resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"++lodash.isequal@^4.1.1:+ version "4.5.0"+ resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"+lodash.isplainobject@^4.0.6:version "4.0.6"resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb"@@ -5828,6 +5844,16 @@ re-emitter@^1.0.0:version "1.1.3"resolved "https://registry.yarnpkg.com/re-emitter/-/re-emitter-1.1.3.tgz#fa9e319ffdeeeb35b27296ef0f3d374dac2f52a7"+react-ace@^6.1.1:+ version "6.1.1"+ resolved "https://registry.yarnpkg.com/react-ace/-/react-ace-6.1.1.tgz#c8339b4f0a27401bff53f477f125d3d7eac2a090"+ dependencies:+ brace "^0.11.0"+ diff-match-patch "^1.0.0"+ lodash.get "^4.4.2"+ lodash.isequal "^4.1.1"+ prop-types "^15.5.8"+react-addons-test-utils@^15.6.2:version "15.6.2"resolved "https://registry.yarnpkg.com/react-addons-test-utils/-/react-addons-test-utils-15.6.2.tgz#c12b6efdc2247c10da7b8770d185080a7b047156"